daily update on 20230713 by nitload youmu, linkedlistbug fixed

This commit is contained in:
Nitload
2023-07-13 06:35:38 +08:00
parent 2a78a60358
commit 01d1b7e7ef
88 changed files with 1388 additions and 1159 deletions
+20 -4
View File
@@ -4,18 +4,33 @@ namespace StgSharp
{
public class Counter<T> where T : struct, IConvertible, IFormattable, IComparable
{
internal readonly dynamic _defualtValue;
internal readonly dynamic _defualtAddValue;
internal readonly dynamic _defualtSubValue;
internal readonly T _defualtValue;
internal readonly T _defualtAddValue;
internal readonly T _defualtSubValue;
internal dynamic _value;
public dynamic Value
public T Value
{
get { return _value; }
set { _value = value; }
}
public T Span
{
get { return _value - _defualtValue; }
}
public T Increament
{
get { return _defualtAddValue; }
}
public T Decreament
{
get { return _defualtSubValue; }
}
public Counter(T defualtValue, T defualtAddValue, T defualtSubValue)
{
var type = Type.GetTypeCode(defualtValue.GetType());
@@ -45,6 +60,7 @@ namespace StgSharp
throw new ArgumentException("Input is not number value type");
break;
}
_value = defualtValue;
_defualtValue = defualtValue;
_defualtAddValue = defualtAddValue;
_defualtSubValue = defualtSubValue;
+68 -24
View File
@@ -5,37 +5,37 @@ namespace StgSharp
{
public class LinkedList<T> : IEnumerable
{
internal readonly LinkedListNode<T> _heading;
internal readonly LinkedListNode<T> _hook;
private LinkedListNode<T> _cache;
private bool isEmpty;
public Counter<uint> count = new Counter<uint>(0, 1, 1);
public LinkedList()
{
_heading = new LinkedListNode<T>();
_hook = new LinkedListNode<T>();
isEmpty = true;
}
public T First
{
get { return _heading._next._value; }
get { return _hook._next._value; }
/*
* 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; }
private set { _hook._next = default; }
}
public T Tail
{
get { return _heading._previous._value; }
get { return _hook._previous._value; }
/*
* 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; }
private set { _hook._previous = default; }
}
/// <summary>
@@ -48,19 +48,19 @@ namespace StgSharp
if (isEmpty)
{
LinkedListNode<T> node = new LinkedListNode<T>(t);
_heading._next = node;
_heading._previous = node;
node.Next = _heading;
node.Previous = _heading;
_hook._next = node;
_hook._previous = node;
node.Next = _hook;
node.Previous = _hook;
isEmpty = false;
}
else
{
LinkedListNode<T> node = new LinkedListNode<T>(t);
node.Next = _heading;
node.Previous = _heading.Previous;
_heading._previous._next = node;
_heading._previous = node;
node.Next = _hook;
node.Previous = _hook.Previous;
_hook._previous._next = node;
_hook._previous = node;
}
count++;
@@ -76,6 +76,21 @@ namespace StgSharp
count--;
}
public void RemoveFirst()
{
if (count._value == 1)
{
First = default;
isEmpty = true;
}
else
{
_hook._next.Remove();
}
count--;
}
public void RemoveTail()
{
//check out if the list has only one member
@@ -86,7 +101,8 @@ namespace StgSharp
}
else
{
_heading.Previous.Next = _heading;
_hook.Previous = _hook.Previous.Previous;
_hook.Previous.Next = _hook;
}
count--;
}
@@ -105,8 +121,8 @@ namespace StgSharp
public void Clear()
{
_heading._previous = null;
_heading._next = null;
_hook._previous = null;
_hook._next = null;
count.Reset();
}
@@ -115,33 +131,61 @@ namespace StgSharp
return new LinkedListEnumrator<T>(this);
}
/**/
internal struct LinkedListEnumrator<T> : IEnumerator
{
private LinkedList<T> _target;
LinkedListNode<T> enumrator;
LinkedListNode<T> enumerator;
private uint index=0;
private T _value;
public LinkedListEnumrator(LinkedList<T> target)
{
_target = target;
enumrator = target._heading;
enumerator = target._hook;
}
object IEnumerator.Current
{
get { return enumrator._value; }
get
{
if (index == 0 || enumerator == _target._hook)
{
throw new InvalidOperationException("Out of index range");
}
else
{
_value = enumerator._value;
return _value;
}
}
}
public T Current
{
get
{
return _value;
}
}
bool IEnumerator.MoveNext()
{
enumrator = enumrator._next;
return enumrator == default(LinkedListNode<T>);
enumerator = enumerator._next;
if (enumerator == _target._hook)
{
return false;
}
index++;
return true;
}
void IEnumerator.Reset()
{
enumrator = _target._heading;
enumerator = _target._hook;
}
}
/**/
}
}
@@ -20,8 +20,6 @@ namespace StgSharp
public LinkedListNode(T t)
{
_value = t;
_previous = new LinkedListNode<T>();
_next = new LinkedListNode<T>();
}
public virtual LinkedListNode<T> Previous
+3 -1
View File
@@ -21,7 +21,7 @@ namespace StgSharp
public Line TopBoarder => topBoader;
public Line BottomBoarder => bottomBoader;
internal Pool()
public Pool()
{
initContainers();
}
@@ -44,6 +44,8 @@ namespace StgSharp
}
}
}