/// Removes the element corresponding to the key. Does nothing if the /// <summary> /// key is not present. /// </summary> /// <summary> /// @param key the key that needs to be removed /// </summary> /// <summary> /// @return the value of key, or null if the key was not found. /// </summary> public int Remove(int key) { var tab = _table; var hash = key; var index = (hash & 0x7FFFFFFF) % tab.Length; for (IntHashtableEntry e = tab[index], prev = null; e != null; prev = e, e = e.Next) { if (e.Hash == hash && e.key == key) { if (prev != null) { prev.Next = e.Next; } else { tab[index] = e.Next; } --Size; return(e.value); } } return(0); }
/// Rehashes the content of the table into a bigger table. // This method is called automatically when the hashtable's // size exceeds the threshold. virtual protected void Rehash() { int oldCapacity = table.Length; IntHashtableEntry[] oldTable = table; int newCapacity = oldCapacity * 2 + 1; IntHashtableEntry[] newTable = new IntHashtableEntry[newCapacity]; threshold = (int)(newCapacity * loadFactor); table = newTable; for (int i = oldCapacity; i-- > 0;) { for (IntHashtableEntry old = oldTable[i]; old != null;) { IntHashtableEntry e = old; old = old.next; int index = (e.hash & 0x7FFFFFFF) % newCapacity; e.next = newTable[index]; newTable[index] = e; } } }
virtual public int[] GetKeys() { int[] res = new int[count]; int ptr = 0; int index = table.Length; IntHashtableEntry entry = null; while (true) { if (entry == null) { while ((index-- > 0) && ((entry = table[index]) == null)) { ; } } if (entry == null) { break; } IntHashtableEntry e = entry; entry = e.next; res[ptr++] = e.key; } return(res); }
public int[] GetKeys() { var res = new int[Size]; var ptr = 0; var index = _table.Length; IntHashtableEntry entry = null; while (true) { if (entry == null) { while ((index-- > 0) && ((entry = _table[index]) == null)) { ; } } if (entry == null) { break; } var e = entry; entry = e.Next; res[ptr++] = e.key; } return(res); }
virtual protected internal IntHashtableEntry Clone() { IntHashtableEntry entry = new IntHashtableEntry(); entry.hash = hash; entry.key = key; entry.value = value; entry.next = (next != null) ? next.Clone() : null; return(entry); }
protected internal IntHashtableEntry Clone() { IntHashtableEntry entry = new IntHashtableEntry(); entry.Hash = Hash; entry.key = key; entry.value = value; entry.Next = (Next != null) ? Next.Clone() : null; return(entry); }
protected internal IntHashtableEntry Clone() { var entry = new IntHashtableEntry { Hash = Hash, key = key, value = value, Next = (Next != null) ? Next.Clone() : null }; return(entry); }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <returns></returns> public int this[int key] { get { var tab = _table; var hash = key; var index = (hash & 0x7FFFFFFF) % tab.Length; for (var e = tab[index]; e != null; e = e.Next) { if (e.Hash == hash && e.key == key) { return(e.value); } } return(0); } set { var tab = _table; var hash = key; var index = (hash & 0x7FFFFFFF) % tab.Length; for (var e = tab[index]; e != null; e = e.Next) { if (e.Hash == hash && e.key == key) { e.value = value; return; } } if (Size >= _threshold) { Rehash(); this[key] = value; return; } var en = new IntHashtableEntry { Hash = hash, key = key, value = value, Next = tab[index] }; tab[index] = en; ++Size; } }
/// Returns true if the collection contains an element for the key. // @param key the key that we are looking for // @see IntHashtable#contains virtual public bool ContainsKey(int key) { IntHashtableEntry[] tab = table; int hash = key; int index = (hash & 0x7FFFFFFF) % tab.Length; for (IntHashtableEntry e = tab[index]; e != null; e = e.next) { if (e.hash == hash && e.key == key) { return(true); } } return(false); }
/// Returns true if the specified object is an element of the hashtable. // This operation is more expensive than the ContainsKey() method. // @param value the value that we are looking for // @exception NullPointerException If the value being searched // for is equal to null. // @see IntHashtable#containsKey virtual public bool Contains(int value) { IntHashtableEntry[] tab = table; for (int i = tab.Length; i-- > 0;) { for (IntHashtableEntry e = tab[i]; e != null; e = e.next) { if (e.value == value) { return(true); } } } return(false); }
public bool HasNext() { if (_entry != null) { return(true); } while (_index-- > 0) { if ((_entry = _table[_index]) != null) { return(true); } } return(false); }
virtual public bool HasNext() { if (entry != null) { return(true); } while (index-- > 0) { if ((entry = table[index]) != null) { return(true); } } return(false); }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <returns></returns> public int this[int key] { get { IntHashtableEntry[] tab = _table; int hash = key; int index = (hash & 0x7FFFFFFF) % tab.Length; for (IntHashtableEntry e = tab[index]; e != null; e = e.Next) { if (e.Hash == hash && e.key == key) { return(e.value); } } return(0); } set { IntHashtableEntry[] tab = _table; int hash = key; int index = (hash & 0x7FFFFFFF) % tab.Length; for (IntHashtableEntry e = tab[index]; e != null; e = e.Next) { if (e.Hash == hash && e.key == key) { e.value = value; return; } } if (_count >= _threshold) { Rehash(); this[key] = value; return; } IntHashtableEntry en = new IntHashtableEntry(); en.Hash = hash; en.key = key; en.value = value; en.Next = tab[index]; tab[index] = en; ++_count; } }
/// Gets the object associated with the specified key in the // hashtable. // @param key the specified key // @returns the element for the key or null if the key // is not defined in the hash table. // @see IntHashtable#put public int this[int key] { get { IntHashtableEntry[] tab = table; int hash = key; int index = (hash & 0x7FFFFFFF) % tab.Length; for (IntHashtableEntry e = tab[index]; e != null; e = e.next) { if (e.hash == hash && e.key == key) { return(e.value); } } return(0); } set { // Makes sure the key is not already in the hashtable. IntHashtableEntry[] tab = table; int hash = key; int index = (hash & 0x7FFFFFFF) % tab.Length; for (IntHashtableEntry e = tab[index]; e != null; e = e.next) { if (e.hash == hash && e.key == key) { e.value = value; return; } } if (count >= threshold) { // Rehash the table if the threshold is exceeded. Rehash(); this[key] = value; return; } // Creates the new entry. IntHashtableEntry en = new IntHashtableEntry(); en.hash = hash; en.key = key; en.value = value; en.next = tab[index]; tab[index] = en; ++count; } }
virtual public IntHashtableEntry Next() { if (entry == null) { while ((index-- > 0) && ((entry = table[index]) == null)) { ; } } if (entry != null) { IntHashtableEntry e = entry; entry = e.next; return(e); } throw new InvalidOperationException(MessageLocalization.GetComposedMessage("inthashtableiterator")); }
public IntHashtableEntry Next() { if (_entry == null) { while ((_index-- > 0) && ((_entry = _table[_index]) == null)) { ; } } if (_entry != null) { var e = _entry; _entry = e.Next; return(e); } throw new InvalidOperationException("IntHashtableIterator"); }
public IntHashtableEntry Next() { if (entry == null) { while ((index-- > 0) && ((entry = table[index]) == null)) { ; } } if (entry != null) { IntHashtableEntry e = entry; entry = e.next; return(e); } throw new InvalidOperationException("IntHashtableIterator"); }
/// Rehashes the content of the table into a bigger table. /// <summary> /// This method is called automatically when the hashtable's /// </summary> /// <summary> /// size exceeds the threshold. /// </summary> protected void Rehash() { var oldCapacity = _table.Length; var oldTable = _table; var newCapacity = oldCapacity * 2 + 1; var newTable = new IntHashtableEntry[newCapacity]; _threshold = (int)(newCapacity * _loadFactor); _table = newTable; for (var i = oldCapacity; i-- > 0;) { for (var old = oldTable[i]; old != null;) { var e = old; old = old.Next; var index = (e.Hash & 0x7FFFFFFF) % newCapacity; e.Next = newTable[index]; newTable[index] = e; } } }
/// Removes the element corresponding to the key. Does nothing if the // key is not present. // @param key the key that needs to be removed // @return the value of key, or null if the key was not found. virtual public int Remove(int key) { IntHashtableEntry[] tab = table; int hash = key; int index = (hash & 0x7FFFFFFF) % tab.Length; for (IntHashtableEntry e = tab[index], prev = null; e != null; prev = e, e = e.next) { if (e.hash == hash && e.key == key) { if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } --count; return(e.value); } } return(0); }
virtual public IntHashtableEntry Next() { if (entry == null) { while ((index-- > 0) && ((entry = table[index]) == null)); } if (entry != null) { IntHashtableEntry e = entry; entry = e.next; return e; } throw new InvalidOperationException(MessageLocalization.GetComposedMessage("inthashtableiterator")); }
virtual public bool HasNext() { if (entry != null) { return true; } while (index-- > 0) { if ((entry = table[index]) != null) { return true; } } return false; }
internal IntHashtableIterator(IntHashtableEntry[] table) { this.table = table; this.index = table.Length; }
virtual protected internal IntHashtableEntry Clone() { IntHashtableEntry entry = new IntHashtableEntry(); entry.hash = hash; entry.key = key; entry.value = value; entry.next = (next != null) ? next.Clone() : null; return entry; }
/// Rehashes the content of the table into a bigger table. // This method is called automatically when the hashtable's // size exceeds the threshold. virtual protected void Rehash() { int oldCapacity = table.Length; IntHashtableEntry[] oldTable = table; int newCapacity = oldCapacity * 2 + 1; IntHashtableEntry[] newTable = new IntHashtableEntry[newCapacity]; threshold = (int) ( newCapacity * loadFactor ); table = newTable; for ( int i = oldCapacity ; i-- > 0 ; ) { for ( IntHashtableEntry old = oldTable[i] ; old != null ; ) { IntHashtableEntry e = old; old = old.next; int index = ( e.hash & 0x7FFFFFFF ) % newCapacity; e.next = newTable[index]; newTable[index] = e; } } }
/// Gets the object associated with the specified key in the // hashtable. // @param key the specified key // @returns the element for the key or null if the key // is not defined in the hash table. // @see IntHashtable#put public int this[int key] { get { IntHashtableEntry[] tab = table; int hash = key; int index = ( hash & 0x7FFFFFFF ) % tab.Length; for ( IntHashtableEntry e = tab[index] ; e != null ; e = e.next ) { if ( e.hash == hash && e.key == key ) return e.value; } return 0; } set { // Makes sure the key is not already in the hashtable. IntHashtableEntry[] tab = table; int hash = key; int index = ( hash & 0x7FFFFFFF ) % tab.Length; for ( IntHashtableEntry e = tab[index] ; e != null ; e = e.next ) { if ( e.hash == hash && e.key == key ) { e.value = value; return; } } if ( count >= threshold ) { // Rehash the table if the threshold is exceeded. Rehash(); this[key] = value; return; } // Creates the new entry. IntHashtableEntry en = new IntHashtableEntry(); en.hash = hash; en.key = key; en.value = value; en.next = tab[index]; tab[index] = en; ++count; } }
public IntHashtableEntry Next() { if (entry == null) { while ((index-- > 0) && ((entry = table[index]) == null)); } if (entry != null) { IntHashtableEntry e = entry; entry = e.next; return e; } throw new InvalidOperationException("IntHashtableIterator"); }