New IO structure, unexpexted error in C code

This commit is contained in:
Nitload
2023-06-22 03:33:24 +08:00
parent 50b4965e54
commit ee8132c149
172 changed files with 1344 additions and 4023 deletions
+88 -34
View File
@@ -1,34 +1,41 @@
using StgSharp.Graphics;
using StgSharp.Logic;
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace StgSharp
{
public class LinkedList<T>:INode<LinkedList<T>>,IEnumerable where T: INode<T>
public class LinkedList<T> : IEnumerable
{
internal readonly ContainerNode<T> _heading;
private ContainerNode<T> _cache;
internal readonly LinkedListNode<T> _heading;
private LinkedListNode<T> _cache;
private bool isEmpty;
public Counter<uint> count = new Counter<uint>(0, 1, 1);
public LinkedList()
{
_heading = new ContainerNode<T>(null);
_heading = new LinkedListNode<T>();
isEmpty = true;
}
public T First
{
get { return _heading._next._value; }
private set { _heading._next = value.ID; }
/*
* This setter is ued to reset the First node,
* be careful when use this setter to avoid
* unexpected risk of this List lose all nodes.
*/
private set { _heading._next = default; }
}
public T Tail
{
get { return _heading._previous._value; }
private set { _heading._previous = value.ID; }
/*
* This setter is ued to reset the Last node,
* be careful when use this setter to avoid
* unexpected risk of this List lose all nodes.
*/
private set { _heading._previous = default; }
}
/// <summary>
@@ -40,54 +47,101 @@ namespace StgSharp
//checkout if the linkedlist is null
if (isEmpty)
{
_heading._next = t.ID;
_heading._previous = t.ID;
t.Next = _heading;
t.Previous = _heading;
LinkedListNode<T> node = new LinkedListNode<T>(t);
_heading._next = node;
_heading._previous = node;
node.Next = _heading;
node.Previous = _heading;
isEmpty = false;
}
else
{
t.Next = _heading;
t.Previous = _heading.Previous;
_heading._previous._next = t.ID;
_heading._previous = t.ID;
LinkedListNode<T> node = new LinkedListNode<T>(t);
node.Next = _heading;
node.Previous = _heading.Previous;
_heading._previous._next = node;
_heading._previous = node;
}
count++;
}
public void Remove(T node)
public void Remove(T value)
{
foreach (INode<T> item in this)
{
if (item == node)
{
node.SelfDestrcut();
break;
}
}
LinkedListNode<T> node = Find(value);
node._next._previous = node._previous;
node._previous._next = node._next;
node._previous = null;
node._next = null;
count--;
}
public void RemoveTail()
{
//check out if the list has only one member
if (Tail == First)
if (count._value == 1)
{
First = default;
isEmpty = true;
}
else
{
Tail.Previous.Next = _heading;
Tail.Next = null;
_heading.Previous.Next = _heading;
}
count--;
}
internal LinkedListNode<T> Find(T value)
{
foreach (LinkedListNode<T> node in this)
{
if (node._value.Equals(value))
{
return node;
}
}
throw new Exception("Value not found in this LinkedList");
}
public void Clear()
{
_heading._previous = null;
_heading._next = null;
count.Reset();
}
IEnumerator IEnumerable.GetEnumerator()
{
return new LinkedListEnumrator<T>(this);
}
internal struct LinkedListEnumrator<T> : IEnumerator
{
private LinkedList<T> _target;
LinkedListNode<T> enumrator;
public LinkedListEnumrator(LinkedList<T> target)
{
_target = target;
enumrator = target._heading;
}
object IEnumerator.Current
{
get { return enumrator._value; }
}
bool IEnumerator.MoveNext()
{
enumrator = enumrator._next;
return enumrator == default(LinkedListNode<T>);
}
void IEnumerator.Reset()
{
enumrator = _target._heading;
}
}
}
}