Exemplo n.º 1
0
        public UInt32Dictionary()
        {
            list     = null;
            iterator = new Iterator(null);

            Prefill(25);
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
 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);
         }
     }
 }
Exemplo n.º 4
0
            public KeyValuePair Next()
            {
                KeyValuePair result = *list;

                list = list->Prev;
                return(result);
            }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
        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;
            }
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        public bool Contains(UInt64 key)
        {
            KeyValuePair *cPair = list;

            while (cPair != null)
            {
                if (cPair->Key == key)
                {
                    return(true);
                }
                cPair = cPair->Prev;
            }
            return(false);
        }
Exemplo n.º 9
0
 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;
         }
     }
 }
Exemplo n.º 10
0
        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;
        }
Exemplo n.º 11
0
 public void StoreState()
 {
     storedList = list;
 }
Exemplo n.º 12
0
 internal void Reset(KeyValuePair *aList)
 {
     list = aList;
 }
Exemplo n.º 13
0
 public Iterator(KeyValuePair *aList)
 {
     list = aList;
 }
Exemplo n.º 14
0
 public UInt64Dictionary()
 {
     list = null;
     iterator = new Iterator(list);
 }
Exemplo n.º 15
0
 public void RestoreState()
 {
     list = storedList;
 }
Exemplo n.º 16
0
        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;
            }
        }
Exemplo n.º 17
0
 public Iterator(KeyValuePair* aList)
 {
     list = aList;
 }
Exemplo n.º 18
0
 internal void Reset(KeyValuePair* aList)
 {
     list = aList;
 }
Exemplo n.º 19
0
 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;
         }
     }
 }
Exemplo n.º 20
0
        public UInt32Dictionary()
        {
            list = null;
            iterator = new Iterator(null);

            Prefill(25);
        }
Exemplo n.º 21
0
 public KeyValuePair Next()
 {
     KeyValuePair result = *list;
     list = list->Prev;
     return result;
 }
Exemplo n.º 22
0
 public void RestoreState()
 {
     list = storedList;
 }
Exemplo n.º 23
0
        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;
        }
Exemplo n.º 24
0
 public void StoreState()
 {
     storedList = list;
 }
Exemplo n.º 25
0
 public UInt64Dictionary()
 {
     list     = null;
     iterator = new Iterator(list);
 }
Exemplo n.º 26
0
        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;
        }