Пример #1
0
        public object Put(object key, object value_ren)
        {
            int hashCode = 0;
            int index    = 0;

            if (key != null)
            {
                hashCode = key.GetHashCode();
                index    = (hashCode & 0x7FFFFFFF) % keyTables.Length;
                for (ArrayMap.Entry e = keyTables[index]; e != null; e = e.next)
                {
                    if ((e.hashCode == hashCode) && key.Equals(e.key))
                    {
                        return(SwapValue(e, value_ren));
                    }
                }
            }
            else
            {
                for (ArrayMap.Entry e_0 = keyTables[0]; e_0 != null; e_0 = e_0.next)
                {
                    if (e_0.key == null)
                    {
                        return(SwapValue(e_0, value_ren));
                    }
                }
            }
            EnsureCapacity();
            index = (hashCode & 0x7FFFFFFF) % keyTables.Length;
            ArrayMap.Entry e_1 = new ArrayMap.Entry(hashCode, key, value_ren, keyTables[index]);
            keyTables[index]    = e_1;
            valueTables[size++] = e_1;
            return(null);
        }
Пример #2
0
        private object SwapValue(ArrayMap.Entry entry, object value_ren)
        {
            object old = entry.value_ren;

            entry.value_ren = value_ren;
            return(old);
        }
Пример #3
0
 public bool ContainsKey(object key)
 {
     ArrayMap.Entry[] table = keyTables;
     if (key != null)
     {
         int hashCode = key.GetHashCode();
         int index    = (hashCode & 0x7FFFFFFF) % table.Length;
         for (ArrayMap.Entry e = table[index]; e != null; e = e.next)
         {
             if (e.hashCode == hashCode && key.Equals(e.key))
             {
                 return(true);
             }
         }
     }
     else
     {
         for (ArrayMap.Entry e_0 = table[0]; e_0 != null; e_0 = e_0.next)
         {
             if (e_0.key == null)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #4
0
 public Entry(int hashCode_0, object key_1, object value_ren,
              ArrayMap.Entry next_2)
 {
     this.hashCode  = hashCode_0;
     this.key       = key_1;
     this.value_ren = value_ren;
     this.next      = next_2;
 }
Пример #5
0
        public object Remove(int index)
        {
            ArrayMap.Entry e         = RemoveList(index);
            object         value_ren = e.value_ren;

            RemoveMap(e.key);
            e.value_ren = null;
            return(value_ren);
        }
Пример #6
0
 public override bool Equals(object o)
 {
     if ((object)this == o)
     {
         return(true);
     }
     ArrayMap.Entry e = (ArrayMap.Entry)o;
     return(((key != null) ? key.Equals(e.key) : e.key == null) &&
            ((value_ren != null) ? value_ren.Equals(e.value_ren) : e.value_ren == null));
 }
Пример #7
0
 private int IndexOf(ArrayMap.Entry entry)
 {
     for (int i = 0; i < size; i++)
     {
         if (valueTables[i] == entry)
         {
             return(i);
         }
     }
     return(-1);
 }
Пример #8
0
        private ArrayMap.Entry RemoveList(int index)
        {
            ArrayMap.Entry e        = valueTables[index];
            int            numMoved = size - index - 1;

            if (numMoved > 0)
            {
                System.Array.Copy((Array)(valueTables), index + 1, (Array)(valueTables), index, numMoved);
            }
            valueTables[--size] = null;
            return(e);
        }
Пример #9
0
 public object Remove(object key)
 {
     ArrayMap.Entry e = RemoveMap(key);
     if (e != null)
     {
         object value_ren = e.value_ren;
         RemoveList(IndexOf(e));
         e.Clear();
         return(value_ren);
     }
     return(null);
 }
Пример #10
0
 public void Reverse()
 {
     for (int i = 0, lastIndex = size - 1, n = size / 2; i < n; i++)
     {
         int            ii      = lastIndex - i;
         ArrayMap.Entry tempKey = keyTables[i];
         keyTables[i]  = keyTables[ii];
         keyTables[ii] = tempKey;
         ArrayMap.Entry tempValue = valueTables[i];
         valueTables[i]  = valueTables[ii];
         valueTables[ii] = tempValue;
     }
 }
Пример #11
0
 public void Shuffle()
 {
     for (int i = size - 1; i >= 0; i--)
     {
         int            ii      = MathUtils.Random(i);
         ArrayMap.Entry tempKey = keyTables[i];
         keyTables[i]  = keyTables[ii];
         keyTables[ii] = tempKey;
         ArrayMap.Entry tempValue = valueTables[i];
         valueTables[i]  = valueTables[ii];
         valueTables[ii] = tempValue;
     }
 }
Пример #12
0
 public object GetKey(int index)
 {
     if (index < 0 || index >= size)
     {
         return(null);
     }
     ArrayMap.Entry entry = GetEntry(index);
     if (entry != null)
     {
         return(entry.key);
     }
     return(null);
 }
Пример #13
0
        private ArrayMap.Entry RemoveMap(object key)
        {
            int hashCode = 0;
            int index    = 0;

            if (key != null)
            {
                hashCode = key.GetHashCode();
                index    = (hashCode & 0x7FFFFFFF) % keyTables.Length;
                for (ArrayMap.Entry e = keyTables[index], prev = null; e != null; prev = e, e = e.next)
                {
                    if ((e.hashCode == hashCode) && key.Equals(e.key))
                    {
                        if (prev != null)
                        {
                            prev.next = e.next;
                        }
                        else
                        {
                            keyTables[index] = e.next;
                        }
                        return(e);
                    }
                }
            }
            else
            {
                for (ArrayMap.Entry e_0 = keyTables[index], prev_1 = null; e_0 != null; prev_1 = e_0, e_0 = e_0.next)
                {
                    if ((e_0.hashCode == hashCode) && e_0.key == null)
                    {
                        if (prev_1 != null)
                        {
                            prev_1.next = e_0.next;
                        }
                        else
                        {
                            keyTables[index] = e_0.next;
                        }
                        return(e_0);
                    }
                }
            }
            return(null);
        }
Пример #14
0
 private void EnsureCapacity()
 {
     if (size >= threshold)
     {
         ArrayMap.Entry[] oldTable     = valueTables;
         int newCapacity               = oldTable.Length * 2 + 1;
         ArrayMap.Entry[] newMapTable  = new ArrayMap.Entry[newCapacity];
         ArrayMap.Entry[] newListTable = new ArrayMap.Entry[newCapacity];
         threshold = (int)(newCapacity * LOAD_FACTOR);
         System.Array.Copy((Array)(oldTable), 0, (Array)(newListTable), 0, size);
         for (int i = 0; i < size; i++)
         {
             ArrayMap.Entry old   = oldTable[i];
             int            index = (old.hashCode & 0x7FFFFFFF) % newCapacity;
             ArrayMap.Entry e     = old;
             old                = old.next;
             e.next             = newMapTable[index];
             newMapTable[index] = e;
         }
         keyTables   = newMapTable;
         valueTables = newListTable;
     }
 }
Пример #15
0
 public object Put(object key, object value_ren)
 {
     int hashCode = 0;
     int index = 0;
     if (key != null)
     {
         hashCode = key.GetHashCode();
         index = (hashCode & 0x7FFFFFFF) % keyTables.Length;
         for (ArrayMap.Entry e = keyTables[index]; e != null; e = e.next)
         {
             if ((e.hashCode == hashCode) && key.Equals(e.key))
             {
                 return SwapValue(e, value_ren);
             }
         }
     }
     else
     {
         for (ArrayMap.Entry e_0 = keyTables[0]; e_0 != null; e_0 = e_0.next)
         {
             if (e_0.key == null)
             {
                 return SwapValue(e_0, value_ren);
             }
         }
     }
     EnsureCapacity();
     index = (hashCode & 0x7FFFFFFF) % keyTables.Length;
     ArrayMap.Entry e_1 = new ArrayMap.Entry(hashCode, key, value_ren, keyTables[index]);
     keyTables[index] = e_1;
     valueTables[size++] = e_1;
     return null;
 }
Пример #16
0
 public Entry(int hashCode_0, object key_1, object value_ren,
         ArrayMap.Entry next_2)
 {
     this.hashCode = hashCode_0;
     this.key = key_1;
     this.value_ren = value_ren;
     this.next = next_2;
 }
Пример #17
0
 public void Clear()
 {
     key       = null;
     value_ren = null;
     next      = null;
 }
Пример #18
0
 public void Clear()
 {
     key = null;
     value_ren = null;
     next = null;
 }
Пример #19
0
 private void EnsureCapacity()
 {
     if (size >= threshold)
     {
         ArrayMap.Entry[] oldTable = valueTables;
         int newCapacity = oldTable.Length * 2 + 1;
         ArrayMap.Entry[] newMapTable = new ArrayMap.Entry[newCapacity];
         ArrayMap.Entry[] newListTable = new ArrayMap.Entry[newCapacity];
         threshold = (int)(newCapacity * LOAD_FACTOR);
         System.Array.Copy((Array)(oldTable), 0, (Array)(newListTable), 0, size);
         for (int i = 0; i < size; i++)
         {
             ArrayMap.Entry old = oldTable[i];
             int index = (old.hashCode & 0x7FFFFFFF) % newCapacity;
             ArrayMap.Entry e = old;
             old = old.next;
             e.next = newMapTable[index];
             newMapTable[index] = e;
         }
         keyTables = newMapTable;
         valueTables = newListTable;
     }
 }