예제 #1
0
        protected V SetValueForEntry(Tuple3KeyEntry <Key1, Key2, Key3, V> entry, V value)
        {
            V oldValue = entry.GetValue();

            entry.SetValue(value);
            return(oldValue);
        }
예제 #2
0
        protected V RemoveEntryForKey(Key1 key1, Key2 key2, Key3 key3)
        {
            int hash = Hash(ExtractHash(key1, key2, key3));

            Tuple3KeyEntry <Key1, Key2, Key3, V>[] table = this.table;
            int i = hash & (table.Length - 1);
            Tuple3KeyEntry <Key1, Key2, Key3, V> entry = table[i];

            if (entry != null)
            {
                if (EqualKeys(key1, key2, key3, entry))
                {
                    table[i] = entry.GetNextEntry();
                    V value = entry.GetValue();
                    EntryRemoved(entry);
                    return(value);
                }
                Tuple3KeyEntry <Key1, Key2, Key3, V> prevEntry = entry;
                entry = entry.GetNextEntry();
                while (entry != null)
                {
                    if (EqualKeys(key1, key2, key3, entry))
                    {
                        prevEntry.SetNextEntry(entry.GetNextEntry());
                        V value = entry.GetValue();
                        EntryRemoved(entry);
                        return(value);
                    }
                    prevEntry = entry;
                    entry     = entry.GetNextEntry();
                }
            }
            return(default(V));
        }
예제 #3
0
        public void ToString(StringBuilder sb)
        {
            sb.Append(Count).Append(" items: [");
            bool first = true;

            Tuple3KeyEntry <Key1, Key2, Key3, V>[] table = this.table;
            for (int a = table.Length; a-- > 0;)
            {
                Tuple3KeyEntry <Key1, Key2, Key3, V> entry = table[a];
                while (entry != null)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(',');
                    }
                    StringBuilderUtil.AppendPrintable(sb, entry);
                    entry = entry.GetNextEntry();
                }
            }
            sb.Append(']');
        }
예제 #4
0
        public V Put(Key1 key1, Key2 key2, Key3 key3, V value)
        {
            int hash = Hash(ExtractHash(key1, key2, key3));

            Tuple3KeyEntry <Key1, Key2, Key3, V>[] table = this.table;
            int i = hash & (table.Length - 1);

            Tuple3KeyEntry <Key1, Key2, Key3, V> entry = table[i];

            while (entry != null)
            {
                if (EqualKeys(key1, key2, key3, entry))
                {
                    if (IsSetValueForEntryAllowed())
                    {
                        return(SetValueForEntry(entry, value));
                    }
                    V oldValue = entry.GetValue();
                    RemoveEntryForKey(key1, key2, key3);
                    AddEntry(hash, key1, key2, key3, value, i);
                    return(oldValue);
                }
                entry = entry.GetNextEntry();
            }
            AddEntry(hash, key1, key2, key3, value, i);
            return(default(V));
        }
예제 #5
0
 public override void Remove()
 {
     if (!removeAllowed)
     {
         throw new NotSupportedException();
     }
     hashMap.Remove(currEntry.GetKey1(), currEntry.GetKey2(), currEntry.GetKey3());
     currEntry = null;
 }
예제 #6
0
 public Tuple3KeyEntry(Key1 key1, Key2 key2, Key3 key3, V value, int hash, Tuple3KeyEntry <Key1, Key2, Key3, V> nextEntry)
 {
     this.key1      = key1;
     this.key2      = key2;
     this.key3      = key3;
     this.value     = value;
     this.hash      = hash;
     this.nextEntry = nextEntry;
 }
예제 #7
0
        protected void AddEntry(int hash, Key1 key1, Key2 key2, Key3 key3, V value, int bucketIndex)
        {
            Tuple3KeyEntry <Key1, Key2, Key3, V>[] table = this.table;
            Tuple3KeyEntry <Key1, Key2, Key3, V>   e     = table[bucketIndex];

            e = CreateEntry(hash, key1, key2, key3, value, e);
            table[bucketIndex] = e;
            EntryAdded(e);
            if (Count >= threshold)
            {
                Resize(2 * table.Length);
            }
        }
예제 #8
0
 protected Tuple3KeyEntry <Key1, Key2, Key3, V> GetNextBucketFromIndex(int index)
 {
     Tuple3KeyEntry <Key1, Key2, Key3, V>[] table = this.table;
     while (index-- > 0)
     {
         Tuple3KeyEntry <Key1, Key2, Key3, V> entry = table[index];
         if (entry != null)
         {
             this.index = index;
             return(entry);
         }
     }
     return(null);
 }
예제 #9
0
        public V[] ToArray(V[] targetArray)
        {
            int index = 0;

            Tuple3KeyEntry <Key1, Key2, Key3, V>[] table = this.table;
            for (int a = table.Length; a-- > 0;)
            {
                Tuple3KeyEntry <Key1, Key2, Key3, V> entry = table[a];
                while (entry != null)
                {
                    targetArray[index++] = entry.GetValue();
                    entry = entry.GetNextEntry();
                }
            }
            return(targetArray);
        }
예제 #10
0
        public IList <V> Values()
        {
            Tuple3KeyEntry <Key1, Key2, Key3, V>[] table = this.table;
            List <V> valueList = new List <V>(Count);

            for (int a = table.Length; a-- > 0;)
            {
                Tuple3KeyEntry <Key1, Key2, Key3, V> entry = table[a];
                while (entry != null)
                {
                    valueList.Add(entry.GetValue());
                    entry = entry.GetNextEntry();
                }
            }
            return(valueList);
        }
예제 #11
0
        public V Get(Key1 key1, Key2 key2, Key3 key3)
        {
            int hash = Hash(ExtractHash(key1, key2, key3));

            Tuple3KeyEntry <Key1, Key2, Key3, V>[] table = this.table;
            int i = hash & (table.Length - 1);
            Tuple3KeyEntry <Key1, Key2, Key3, V> entry = table[i];

            while (entry != null)
            {
                if (EqualKeys(key1, key2, key3, entry))
                {
                    return(entry.GetValue());
                }
                entry = entry.GetNextEntry();
            }
            return(default(V));
        }
예제 #12
0
        public bool ContainsKey(Key1 key1, Key2 key2, Key3 key3)
        {
            int hash = Hash(ExtractHash(key1, key2, key3));

            Tuple3KeyEntry <Key1, Key2, Key3, V>[] table = this.table;
            int i = hash & (table.Length - 1);
            Tuple3KeyEntry <Key1, Key2, Key3, V> entry = table[i];

            while (entry != null)
            {
                if (EqualKeys(key1, key2, key3, entry))
                {
                    return(true);
                }
                entry = entry.GetNextEntry();
            }
            return(false);
        }
예제 #13
0
        protected void Transfer(Tuple3KeyEntry <Key1, Key2, Key3, V>[] newTable)
        {
            int newCapacityMinus1 = newTable.Length - 1;

            Tuple3KeyEntry <Key1, Key2, Key3, V>[] table = this.table;

            for (int a = table.Length; a-- > 0;)
            {
                Tuple3KeyEntry <Key1, Key2, Key3, V> entry = table[a], next;
                while (entry != null)
                {
                    next = entry.GetNextEntry();
                    int i = entry.GetHash() & newCapacityMinus1;
                    entry.SetNextEntry(newTable[i]);
                    newTable[i] = entry;
                    entry       = next;
                }
            }
        }
예제 #14
0
        public bool RemoveIfValue(Key1 key1, Key2 key2, Key3 key3, V value)
        {
            int hash = Hash(ExtractHash(key1, key2, key3));

            Tuple3KeyEntry <Key1, Key2, Key3, V>[] table = this.table;
            int i = hash & (table.Length - 1);
            Tuple3KeyEntry <Key1, Key2, Key3, V> entry = table[i];

            if (entry != null)
            {
                if (EqualKeys(key1, key2, key3, entry))
                {
                    table[i] = entry.GetNextEntry();
                    V existingValue = entry.GetValue();
                    if (!Object.ReferenceEquals(existingValue, value)) // Test if reference identical
                    {
                        return(false);
                    }
                    EntryRemoved(entry);
                    return(true);
                }
                Tuple3KeyEntry <Key1, Key2, Key3, V> prevEntry = entry;
                entry = entry.GetNextEntry();
                while (entry != null)
                {
                    if (EqualKeys(key1, key2, key3, entry))
                    {
                        prevEntry.SetNextEntry(entry.GetNextEntry());
                        V existingValue = entry.GetValue();
                        if (!Object.ReferenceEquals(existingValue, value)) // Test if reference identical
                        {
                            return(false);
                        }
                        EntryRemoved(entry);
                        return(true);
                    }
                    prevEntry = entry;
                    entry     = entry.GetNextEntry();
                }
            }
            return(false);
        }
예제 #15
0
        public bool PutIfNotExists(Key1 key1, Key2 key2, Key3 key3, V value)
        {
            int hash = Hash(ExtractHash(key1, key2, key3));

            Tuple3KeyEntry <Key1, Key2, Key3, V>[] table = this.table;
            int i = hash & (table.Length - 1);

            Tuple3KeyEntry <Key1, Key2, Key3, V> entry = table[i];

            while (entry != null)
            {
                if (EqualKeys(key1, key2, key3, entry))
                {
                    return(false);
                }
                entry = entry.GetNextEntry();
            }
            AddEntry(hash, key1, key2, key3, value, i);
            return(true);
        }
예제 #16
0
 public override bool MoveNext()
 {
     if (first)
     {
         currEntry = GetNextBucketFromIndex(table.Length);
         if (currEntry == null)
         {
             return(false);
         }
         first = false;
         return(true);
     }
     else if (currEntry != null)
     {
         currEntry = currEntry.GetNextEntry();
     }
     if (currEntry == null)
     {
         currEntry = GetNextBucketFromIndex(index);
     }
     return(currEntry != null);
 }
예제 #17
0
        public void Clear()
        {
            if (IsEmpty)
            {
                return;
            }
            Tuple3KeyEntry <Key1, Key2, Key3, V>[] table = this.table;

            for (int a = table.Length; a-- > 0;)
            {
                Tuple3KeyEntry <Key1, Key2, Key3, V> entry = table[a];
                if (entry != null)
                {
                    table[a] = null;
                    while (entry != null)
                    {
                        Tuple3KeyEntry <Key1, Key2, Key3, V> nextEntry = entry.GetNextEntry();
                        EntryRemoved(entry);
                        entry = nextEntry;
                    }
                }
            }
        }
예제 #18
0
 /**
  * @see java.util.Map#containsValue(java.lang.Object)
  */
 public bool ContainsValue(V value)
 {
     Tuple3KeyEntry <Key1, Key2, Key3, V>[] table = this.table;
     if (value == null)
     {
         for (int a = table.Length; a-- > 0;)
         {
             Tuple3KeyEntry <Key1, Key2, Key3, V> entry = table[a];
             while (entry != null)
             {
                 Object entryValue = entry.GetValue();
                 if (entryValue == null)
                 {
                     return(true);
                 }
                 entry = entry.GetNextEntry();
             }
         }
     }
     else
     {
         for (int a = table.Length; a-- > 0;)
         {
             Tuple3KeyEntry <Key1, Key2, Key3, V> entry = table[a];
             while (entry != null)
             {
                 Object entryValue = entry.GetValue();
                 if (value.Equals(entryValue))
                 {
                     return(true);
                 }
                 entry = entry.GetNextEntry();
             }
         }
     }
     return(false);
 }
예제 #19
0
 protected virtual void EntryRemoved(Tuple3KeyEntry <Key1, Key2, Key3, V> entry)
 {
     // Intended blank
 }
예제 #20
0
 protected abstract Tuple3KeyEntry <Key1, Key2, Key3, V> CreateEntry(int hash, Key1 key1, Key2 key2, Key3 key3, V value,
                                                                     Tuple3KeyEntry <Key1, Key2, Key3, V> nextEntry);
예제 #21
0
 public void SetNextEntry(Tuple3KeyEntry <Key1, Key2, Key3, V> nextEntry)
 {
     this.nextEntry = nextEntry;
 }
예제 #22
0
 protected virtual bool EqualKeys(Key1 key1, Key2 key2, Key3 key3, Tuple3KeyEntry <Key1, Key2, Key3, V> entry)
 {
     return(Object.Equals(key1, entry.GetKey1()) && Object.Equals(key2, entry.GetKey2()) && Object.Equals(key3, entry.GetKey3()));
 }