internal HashtableEntry(KeyType key, ValueType value, uint hashCode, HashtableEntry <KeyType, ValueType> next) { this.Key = key; this.Value = value; this.hashCode = hashCode; this.next = next; }
public ValueType this[KeyType key] { get { var e = this.GetHashtableEntry(key, (uint)key.GetHashCode()); if (e == null) { return(default(ValueType)); } return(e.Value); } set { uint hashCode = (uint)key.GetHashCode(); var e = this.GetHashtableEntry(key, hashCode); if (e != null) { e.Key = key; e.Value = value; return; } if (++this.Count >= threshold) { this.Rehash(); } uint index = hashCode % (uint)table.Length; table[index] = new HashtableEntry <KeyType, ValueType>(key, value, hashCode, table[index]); } }
internal HashtableEntry(HashtableEntry <KeyType, ValueType> template) { this.Key = template.Key; this.Value = template.Value; this.hashCode = template.hashCode; if (template.next != null) { this.next = new HashtableEntry <KeyType, ValueType>(template.next); } }
public bool TryGetValue(KeyType key, out ValueType result) { HashtableEntry <KeyType, ValueType> e = this.GetHashtableEntry(key, (uint)key.GetHashCode()); if (e == null) { result = default(ValueType); return(false); } else { result = e.Value; return(true); } }
public bool MoveNext() { if (this.currentEntry != null) { this.currentEntry = this.currentEntry.next; } while (this.currentEntry == null) { if (this.tableIndex >= this.table.Length) { return(false); } this.currentEntry = this.table[this.tableIndex++]; } return(true); }
public SimpleHashtable(SimpleHashtable <KeyType, ValueType> template) { this.Count = template.Count; threshold = template.threshold; int n = template.table.Length; table = new HashtableEntry <KeyType, ValueType> [n]; for (int i = 0; i < n; i++) { var templateEntry = template.table[i]; if (templateEntry != null) { table[i] = new HashtableEntry <KeyType, ValueType>(templateEntry); } } }
public bool MoveNext() { if (currentEntry != null) { currentEntry = currentEntry.next; } while (currentEntry == null) { if (tableIndex >= table.Length) { return(false); } currentEntry = table[tableIndex++]; } return(true); }
public void Add(KeyType key, ValueType value) { uint hashCode = (uint)key.GetHashCode(); var e = this.GetHashtableEntry(key, hashCode); if (e != null) { throw new InvalidOperationException(); } if (++this.Count >= threshold) { this.Rehash(); } uint index = hashCode % (uint)table.Length; table[index] = new HashtableEntry <KeyType, ValueType>(key, value, hashCode, table[index]); }
internal HashtableEntryEnumerator(HashtableEntry <KeyType, ValueType>[] table) { this.table = table; this.tableIndex = 0; this.currentEntry = null; }