virtual public long[] GetKeys() { long[] res = new long[count]; int ptr = 0; int index = table.Length; LongHashtableEntry entry = null; while (true) { if (entry == null) { while ((index-- > 0) && ((entry = table[index]) == null)) { ; } } if (entry == null) { break; } LongHashtableEntry e = entry; entry = e.next; res[ptr++] = e.key; } return(res); }
/// 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; LongHashtableEntry[] oldTable = table; int newCapacity = oldCapacity * 2 + 1; LongHashtableEntry[] newTable = new LongHashtableEntry[newCapacity]; threshold = (int)(newCapacity * loadFactor); table = newTable; for (int i = oldCapacity; i-- > 0;) { for (LongHashtableEntry old = oldTable[i]; old != null;) { LongHashtableEntry e = old; old = old.next; int index = (e.hash & 0x7FFFFFFF) % newCapacity; e.next = newTable[index]; newTable[index] = e; } } }
virtual protected internal LongHashtableEntry Clone() { LongHashtableEntry entry = new LongHashtableEntry(); entry.hash = hash; entry.key = key; entry.value = value; entry.next = (next != null) ? next.Clone() : null; return(entry); }
virtual public bool HasNext() { if (entry != null) { return(true); } while (index-- > 0) { if ((entry = table[index]) != null) { return(true); } } return(false); }
/// Returns true if the collection contains an element for the key. // @param key the key that we are looking for // @see LongHashtable#contains virtual public bool ContainsKey(long key) { LongHashtableEntry[] tab = table; int hash = key.GetHashCode(); int index = (hash & 0x7FFFFFFF) % tab.Length; for (LongHashtableEntry 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 LongHashtable#containsKey virtual public bool Contains(long value) { LongHashtableEntry[] tab = table; for (int i = tab.Length; i-- > 0;) { for (LongHashtableEntry e = tab[i]; e != null; e = e.next) { if (e.value == value) { return(true); } } } return(false); }
/// 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 LongHashtable#put public long this[long key] { get { LongHashtableEntry[] tab = table; int hash = key.GetHashCode(); int index = (hash & 0x7FFFFFFF) % tab.Length; for (LongHashtableEntry 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. LongHashtableEntry[] tab = table; int hash = key.GetHashCode(); int index = (hash & 0x7FFFFFFF) % tab.Length; for (LongHashtableEntry 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. LongHashtableEntry en = new LongHashtableEntry(); en.hash = hash; en.key = key; en.value = value; en.next = tab[index]; tab[index] = en; ++count; } }
virtual public LongHashtableEntry Next() { if (entry == null) { while ((index-- > 0) && ((entry = table[index]) == null)) { ; } } if (entry != null) { LongHashtableEntry e = entry; entry = e.next; return(e); } throw new InvalidOperationException(MessageLocalization.GetComposedMessage("inthashtableiterator")); }
/// 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 long Remove(long key) { LongHashtableEntry[] tab = table; int hash = key.GetHashCode(); int index = (hash & 0x7FFFFFFF) % tab.Length; for (LongHashtableEntry 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); }
public LongHashtableEntry Next() { if (entry == null) { while ((index-- > 0) && ((entry = table[index]) == null)); } if (entry != null) { LongHashtableEntry e = entry; entry = e.next; return e; } throw new InvalidOperationException(MessageLocalization.GetComposedMessage("inthashtableiterator")); }
public bool HasNext() { if (entry != null) { return true; } while (index-- > 0) { if ((entry = table[index]) != null) { return true; } } return false; }
internal LongHashtableIterator(LongHashtableEntry[] table) { this.table = table; this.index = table.Length; }
protected internal LongHashtableEntry Clone() { LongHashtableEntry entry = new LongHashtableEntry(); 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. protected void Rehash() { int oldCapacity = table.Length; LongHashtableEntry[] oldTable = table; int newCapacity = oldCapacity * 2 + 1; LongHashtableEntry[] newTable = new LongHashtableEntry[newCapacity]; threshold = (int) ( newCapacity * loadFactor ); table = newTable; for ( int i = oldCapacity ; i-- > 0 ; ) { for ( LongHashtableEntry old = oldTable[i] ; old != null ; ) { LongHashtableEntry 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 LongHashtable#put public long this[long key] { get { LongHashtableEntry[] tab = table; int hash = key.GetHashCode(); int index = ( hash & 0x7FFFFFFF ) % tab.Length; for ( LongHashtableEntry 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. LongHashtableEntry[] tab = table; int hash = key.GetHashCode(); int index = ( hash & 0x7FFFFFFF ) % tab.Length; for ( LongHashtableEntry 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. LongHashtableEntry en = new LongHashtableEntry(); en.hash = hash; en.key = key; en.value = value; en.next = tab[index]; tab[index] = en; ++count; } }