Added class collections.LinkedList
parent
1374b8aca4
commit
bb870e415c
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
namespace ln.types.cache
|
||||
{
|
||||
public class LinkedListItem<T>
|
||||
{
|
||||
public bool IsLinked => (Previous != this);
|
||||
|
||||
public LinkedListItem<T> Previous;
|
||||
public LinkedListItem<T> Next;
|
||||
|
||||
public T Value;
|
||||
|
||||
public LinkedListItem()
|
||||
{
|
||||
Previous = this;
|
||||
Next = this;
|
||||
}
|
||||
public LinkedListItem(T value)
|
||||
:this()
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using ln.types.cache;
|
||||
using System.Runtime.Remoting;
|
||||
namespace ln.types.collections
|
||||
{
|
||||
/**
|
||||
* A backend Implementation of Double-Linked-List
|
||||
**/
|
||||
public class LinkedList<T>
|
||||
{
|
||||
public LinkedListItem<T> FirstItem => (head.Next != head) ? head.Next : null;
|
||||
public LinkedListItem<T> LastItem => (head.Previous != head) ? head.Previous : null;
|
||||
|
||||
public LinkedListItem<T> Head => head;
|
||||
|
||||
LinkedListItem<T> head = new LinkedListItem<T>();
|
||||
|
||||
public LinkedList()
|
||||
{
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
head = new LinkedListItem<T>();
|
||||
}
|
||||
|
||||
public void Add(LinkedListItem<T> item)
|
||||
{
|
||||
if (item.Previous != item)
|
||||
Remove(item);
|
||||
|
||||
item.Next = head;
|
||||
item.Previous = head.Previous;
|
||||
item.Previous.Next = item;
|
||||
item.Next.Previous = item;
|
||||
}
|
||||
|
||||
public void Remove(LinkedListItem<T> item)
|
||||
{
|
||||
item.Previous.Next = item.Next;
|
||||
item.Next.Previous = item.Previous;
|
||||
item.Next = item;
|
||||
item.Previous = item;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -105,6 +105,8 @@
|
|||
<Compile Include="odb\ng\Events.cs" />
|
||||
<Compile Include="odb\ng\storage\bases\StorageBase.cs" />
|
||||
<Compile Include="odb\ng\storage\bases\CachingStorageBase.cs" />
|
||||
<Compile Include="cache\LinkedListItem.cs" />
|
||||
<Compile Include="collections\LinkedList.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="odb\" />
|
||||
|
|
Loading…
Reference in New Issue