Esempio n. 1
0
        public void InsertAt(T item, int index)
        {
            //Public API for adding at a specific index.
            //Note: Has linear performance
            if (index < arrayAllocation.Length && arrayAllocation.Get(index))
            {
                //this.innerArray[index] = item; //If something's already there, just replace it
            }
            else
            {
                CheckCapacity(index + 1);
                if (index < PeakCount)
                {
                    int indexIndex = Array.BinarySearch <int>(OpenSlots.innerArray, index);
                    Shortcuts.Shift(OpenSlots.innerArray, indexIndex, OpenSlots.innerArray.Length, -1);
                }
                else if (index >= PeakCount)
                {
                    for (; PeakCount < index; PeakCount++)
                    {
                        OpenSlots.Add(PeakCount);
                    }
                    PeakCount++;
                }

                Count++;
            }
            this.innerArray[index] = item;
            arrayAllocation[index] = true;
        }
Esempio n. 2
0
 private bool ConfirmSlot(int hashCode)
 {
     GenerateIndexes(hashCode);
     if (Shortcuts.GetBit(bucketAllocation[bigIndex], smallIndex))
     {
         if (bucketHashes [leIndex] == hashCode)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 3
0
 private bool _Remove(int hashCode)
 {
     if (ForceStop)
     {
         return(false);
     }
     if (ConfirmSlot(hashCode))
     {
         Shortcuts.SetBitFalse(ref bucketAllocation [bigIndex], smallIndex);
         return(true);
     }
     return(_Remove(hashCode * CollisionResolver));
 }
Esempio n. 4
0
 private bool _Add(int hashCode, TValue item)
 {
     if (ForceStop)
     {
         return(false);
     }
     GenerateIndexes(hashCode);
     if (Shortcuts.GetBit(bucketAllocation[bigIndex], smallIndex))
     {
         if (bucketHashes [leIndex] == hashCode)
         {
             return(false);
         }
         //Resolve collision
         return(_Add(hashCode * CollisionResolver, item));
     }
     Shortcuts.SetBitTrue(ref bucketAllocation [bigIndex], smallIndex);
     bucketValues [leIndex] = item;
     bucketHashes [leIndex] = hashCode;
     return(true);
 }
Esempio n. 5
0
 public void FullClear()
 {
     Shortcuts.ClearArray(innerArray);
     FastClear();
 }