public UInt32Dictionary() { list = null; iterator = new Iterator(null); Prefill(25); }
public void Remove(UInt64 key) { KeyValuePair *cPair = list; while (cPair != null) { if (cPair->Key == key) { KeyValuePair *prev = cPair->Prev; KeyValuePair *next = cPair->Next; if (prev != null) { prev->Next = next; } if (next != null) { next->Prev = prev; } Heap.Free(cPair); } cPair = cPair->Prev; } }
public UInt64 this[UInt64 key] { get { KeyValuePair *cPair = list; while (cPair != null) { if (cPair->Key == key) { return(cPair->Value); } cPair = cPair->Prev; } ExceptionMethods.Throw(new Exceptions.ArgumentException("Key not found in dictionary!")); return(0); } set { KeyValuePair *cPair = list; while (cPair != null) { if (cPair->Key == key) { cPair->Value = value; break; } cPair = cPair->Prev; } if (cPair == null) { Add(key, value); } } }
public KeyValuePair Next() { KeyValuePair result = *list; list = list->Prev; return(result); }
public void Add(UInt32 key, UInt32 value, bool SkipCheck = false) { if (!SkipCheck) { if (Contains(key)) { ExceptionMethods.Throw(new FOS_System.Exception("Cannot add duplicate key to the dictionary!")); } } KeyValuePair *newItem = null; KeyValuePair *newNext = null; KeyValuePair *newPrev = null; KeyValuePair *newListNext = null; bool Alloc = true; if (list != null) { if (list->Empty) { newItem = list; newNext = newItem->Next; newPrev = null; newListNext = newItem->Next; Alloc = false; } else if (list->Next != null) { newItem = list->Next; newNext = newItem->Next; newPrev = newItem->Prev; newListNext = newItem; Alloc = false; } else { Alloc = true; } } if (Alloc) { newItem = (KeyValuePair *)Heap.Alloc((uint)sizeof(KeyValuePair), "UInt32Dictionary.Add"); newNext = null; newPrev = list; newListNext = newItem; } newItem->Key = key; newItem->Value = value; newItem->Next = newNext; newItem->Prev = newPrev; newItem->Empty = false; if (list != null && newItem != list) { list->Next = newListNext; } list = newItem; }
public void Remove(UInt32 key) { KeyValuePair *cPair = list; while (cPair != null) { if (cPair->Key == key) { KeyValuePair *prev = cPair->Prev; KeyValuePair *next = cPair->Next; if (prev != null) { prev->Next = next; } if (next != null) { next->Prev = prev; } if (cPair == list) { if (prev == null) { list = next; } else { list = prev; } } cPair->Empty = true; cPair->Key = 0; cPair->Value = 0; cPair->Prev = list; if (list != null) { cPair->Next = list->Next; list->Next = cPair; cPair->Next->Prev = cPair; } else { cPair->Next = null; list = cPair; } break; } cPair = cPair->Prev; } }
public bool ContainsItemInRange(UInt64 startKey, UInt64 endKey) { KeyValuePair *cPair = list; while (cPair != null) { if (cPair->Key >= startKey && cPair->Key < endKey) { return(true); } cPair = cPair->Prev; } return(false); }
public bool Contains(UInt64 key) { KeyValuePair *cPair = list; while (cPair != null) { if (cPair->Key == key) { return(true); } cPair = cPair->Prev; } return(false); }
private void Prefill(int capacity) { while (capacity-- > 0) { KeyValuePair *newItem = (KeyValuePair *)Heap.Alloc((uint)sizeof(KeyValuePair), "UInt32Dictionary.Prefill"); newItem->Empty = true; newItem->Key = 0; newItem->Value = 0; newItem->Prev = null; if (list == null) { newItem->Next = null; list = newItem; } else { newItem->Next = list; list->Prev = newItem; list = newItem; } } }
public void Add(UInt64 key, UInt64 value, bool SkipCheck = false) { if (!SkipCheck) { if (Contains(key)) { ExceptionMethods.Throw(new FOS_System.Exception("Cannot add duplicate key to the dictionary!")); } } KeyValuePair *newItem = (KeyValuePair *)Heap.Alloc((uint)sizeof(KeyValuePair), "UInt64Dictionary.Add"); newItem->Key = key; newItem->Value = value; newItem->Next = null; newItem->Prev = list; if (list != null) { list->Next = newItem; } list = newItem; }
public void StoreState() { storedList = list; }
internal void Reset(KeyValuePair *aList) { list = aList; }
public Iterator(KeyValuePair *aList) { list = aList; }
public UInt64Dictionary() { list = null; iterator = new Iterator(list); }
public void RestoreState() { list = storedList; }
public void Remove(UInt32 key) { KeyValuePair* cPair = list; while(cPair != null) { if(cPair->Key == key) { KeyValuePair* prev = cPair->Prev; KeyValuePair* next = cPair->Next; if (prev != null) { prev->Next = next; } if (next != null) { next->Prev = prev; } if (cPair == list) { if (prev == null) { list = next; } else { list = prev; } } cPair->Empty = true; cPair->Key = 0; cPair->Value = 0; cPair->Prev = list; if (list != null) { cPair->Next = list->Next; list->Next = cPair; cPair->Next->Prev = cPair; } else { cPair->Next = null; list = cPair; } break; } cPair = cPair->Prev; } }
public Iterator(KeyValuePair* aList) { list = aList; }
internal void Reset(KeyValuePair* aList) { list = aList; }
private void Prefill(int capacity) { while (capacity-- > 0) { KeyValuePair* newItem = (KeyValuePair*)Heap.Alloc((uint)sizeof(KeyValuePair), "UInt32Dictionary.Prefill"); newItem->Empty = true; newItem->Key = 0; newItem->Value = 0; newItem->Prev = null; if (list == null) { newItem->Next = null; list = newItem; } else { newItem->Next = list; list->Prev = newItem; list = newItem; } } }
public KeyValuePair Next() { KeyValuePair result = *list; list = list->Prev; return result; }
public void Add(UInt64 key, UInt64 value, bool SkipCheck = false) { if (!SkipCheck) { if (Contains(key)) { ExceptionMethods.Throw(new FOS_System.Exception("Cannot add duplicate key to the dictionary!")); } } KeyValuePair* newItem = (KeyValuePair*)Heap.Alloc((uint)sizeof(KeyValuePair), "UInt64Dictionary.Add"); newItem->Key = key; newItem->Value = value; newItem->Next = null; newItem->Prev = list; if (list != null) { list->Next = newItem; } list = newItem; }
public void Add(UInt32 key, UInt32 value, bool SkipCheck = false) { if (!SkipCheck) { if (Contains(key)) { ExceptionMethods.Throw(new FOS_System.Exception("Cannot add duplicate key to the dictionary!")); } } KeyValuePair* newItem = null; KeyValuePair* newNext = null; KeyValuePair* newPrev = null; KeyValuePair* newListNext = null; bool Alloc = true; if (list != null) { if (list->Empty) { newItem = list; newNext = newItem->Next; newPrev = null; newListNext = newItem->Next; Alloc = false; } else if (list->Next != null) { newItem = list->Next; newNext = newItem->Next; newPrev = newItem->Prev; newListNext = newItem; Alloc = false; } else { Alloc = true; } } if(Alloc) { newItem = (KeyValuePair*)Heap.Alloc((uint)sizeof(KeyValuePair), "UInt32Dictionary.Add"); newNext = null; newPrev = list; newListNext = newItem; } newItem->Key = key; newItem->Value = value; newItem->Next = newNext; newItem->Prev = newPrev; newItem->Empty = false; if (list != null && newItem != list) { list->Next = newListNext; } list = newItem; }