Daily update on 20231211 by nitload youmu

This commit is contained in:
Nitload
2023-12-12 03:17:16 +08:00
parent ab85c1a9fe
commit f97fb137ba
100 changed files with 2699 additions and 3191 deletions
+76 -27
View File
@@ -1,21 +1,32 @@
using System;
using StgSharp.Graphics;
using System;
using System.Collections;
namespace StgSharp
{
public class LinkedList<T> : IEnumerable
{
public Counter<uint> count = new Counter<uint>(0, 1, 1);
internal readonly LinkedListNode<T> _hook;
private LinkedListNode<T> _cache;
private bool isEmpty;
public Counter<uint> count = new Counter<uint>(0, 1, 1);
public LinkedList()
{
_hook = new LinkedListNode<T>();
isEmpty = true;
}
/// <summary>
/// Whether this linked list has no members or not.
/// </summary>
public bool IsEmpty
{
get { return count == 0; }
}
/// <summary>
/// The first memeber of this linkec list.
/// Set value to this property will reset the first node.
/// </summary>
public T First
{
get { return _hook._next._value; }
@@ -27,6 +38,10 @@ namespace StgSharp
private set { _hook._next = default; }
}
/// <summary>
/// The last memeber of this linkec list.
/// Set value to this property will reset the first node.
/// </summary>
public T Tail
{
get { return _hook._previous._value; }
@@ -45,14 +60,13 @@ namespace StgSharp
public void Add(T t)
{
//checkout if the linkedlist is null
if (isEmpty)
if (IsEmpty)
{
LinkedListNode<T> node = new LinkedListNode<T>(t);
_hook._next = node;
_hook._previous = node;
node.Next = _hook;
node.Previous = _hook;
isEmpty = false;
}
else
{
@@ -66,6 +80,53 @@ namespace StgSharp
count++;
}
/// <summary>
/// Remove all members from this list
/// </summary>
public void Clear()
{
_hook._previous = null;
_hook._next = null;
count.Reset();
GC.Collect();
}
IEnumerator IEnumerable.GetEnumerator()
{
return new LinkedListEnumrator<T>(this);
}
/// <summary>
/// Insert a member to current linkedlist,
/// the new member will be after a certain existed member.
/// </summary>
/// <param name="target">New member will be inserted after this member</param>
/// <param name="newMember">The new member to be inserted</param>
public void InsertAfter(T target, T newMember)
{
try
{
LinkedListNode<T> targetNode = Find(target);
LinkedListNode<T> targetNext = targetNode._next;
LinkedListNode<T> newNode = new LinkedListNode<T>(newMember);
targetNode._next = newNode;
newNode._next = targetNext;
targetNode._previous = newNode;
newNode._previous = targetNode;
count++;
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// Remove a member from this linkedlist.
/// </summary>
/// <param name="value">Member to be removed from this list</param>
public void Remove(T value)
{
LinkedListNode<T> node = Find(value);
@@ -76,13 +137,14 @@ namespace StgSharp
count--;
}
/// <summary>
/// remove the first member of the list
/// </summary>
public void RemoveFirst()
{
if (count._value == 1)
{
First = default;
isEmpty = true;
}
else
{
@@ -91,13 +153,15 @@ namespace StgSharp
count--;
}
/// <summary>
/// remove the last member of the list
/// </summary>
public void RemoveTail()
{
//check out if the list has only one member
if (count._value == 1)
{
First = default;
isEmpty = true;
}
else
{
@@ -124,28 +188,13 @@ namespace StgSharp
return enumerator;
}
public void Clear()
{
_hook._previous = null;
_hook._next = null;
count.Reset();
}
IEnumerator IEnumerable.GetEnumerator()
{
return new LinkedListEnumrator<T>(this);
}
/**/
internal struct LinkedListEnumrator<T> : IEnumerator
{
private LinkedList<T> _target;
LinkedListNode<T> enumerator;
private uint index=0;
private T _value;
LinkedListNode<T> enumerator;
private uint index = 0;
public LinkedListEnumrator(LinkedList<T> target)
{
_target = target;
@@ -154,7 +203,7 @@ namespace StgSharp
object IEnumerator.Current
{
get
get
{
if (index == 0 || enumerator == _target._hook)
{
+2 -3
View File
@@ -16,7 +16,6 @@ namespace StgSharp
{
}
public LinkedListNode(T t)
{
_value = t;
@@ -43,8 +42,8 @@ namespace StgSharp
{
_previous.Next = _next;
_next.Previous = _previous;
_next = default(LinkedListNode<T>);
_previous = default(LinkedListNode<T>);
_next = null;
_previous = null;
}
}