private void SetValueInTable(object key, object value, HashSlot[] table) { int size = table.Length; int hash = base.GetHash(key); int index = GetIndexFromHash(hash, size); bool success = false; for (int i = 0; i < size; i++) { index = GetNextQuadraticIndex(index, i, size); if (table[index] == null) { table[index] = new HashSlot(key, value); success = true; break; } else if (table[index].Key == key) { table[index] = new HashSlot(key, value); success = true; break; } } if (!success) { throw new Exception("_INTERNAL_EXCEPTION > QPHashTable > 'SetValueInTable()' :: loop ends, value not inserted"); } }
private void SetValueInTable(object key, object value, HashSlot[] targetTable) { int capacity = targetTable.Length; int hash = base.GetHash(key); int index = GetIndexFromHash(hash, targetTable.Length); bool success = false; for (int i = 0; i < capacity; i++) { if (targetTable[index] == null) { targetTable[index] = new HashSlot(key, value); success = true; break; } else if (targetTable[index].Key == key) { targetTable[index] = new HashSlot(key, value); success = true; break; } else { index = (index + 1) % capacity; } } if (!success) { throw new Exception("INTERNAL_ERROR: SetValueInTable() :: Cannot find valid index, loop ends."); } }
private void ResizeTableIfNeed() { if (GetLoadFactor().Factor > MAX_LOAD_FACTOR) { int newSize = this.table.Length * 2; HashSlot[] newTable = new HashSlot[newSize]; Rehash(this.table, newTable); this.table = newTable; } }
private bool SetValueInTable(object key, object value, ListNode[] table) { int hash = base.GetHash(key); int index = GetIndexFromHash(hash, table.Length); bool sameKeyFound = false; HashSlot newSlot = new HashSlot(key, value); ListNode lastNode = table[index]; if (lastNode != null) { bool search = true; while (search) { if (lastNode.Slot.Key == key) { sameKeyFound = true; search = false; } else { if (lastNode.NextNode != null) { lastNode = lastNode.NextNode; } else { search = false; } } } } if (sameKeyFound) { lastNode.SetHashSlot(newSlot); } else { if (lastNode == null) { table[index] = new ListNode(newSlot); } else { lastNode.SetNextNode(new ListNode(newSlot)); } } return(!sameKeyFound); }
private void ExtendTableIfNeed() { double factor = GetLoadFactor().Factor; if (factor > MAX_LOAD_FACTOR) { int newSize = this.table.Length * 2; HashSlot[] newTable = new HashSlot[newSize]; RehashTable(this.table, newTable); this.table = newTable; } }
private bool SetValueInTable(object key, object value, HashSlot[] table) { int hash = base.GetHash(key); int size = table.Length; int index; bool success = false; bool insertedNew = false; for (int i = 0; i < size; i++) { index = GetNextDoubleHashIndex(hash, i, size); if (table[index] == null) { table[index] = new HashSlot(key, value); success = true; insertedNew = true; break; } else if (table[index].Key == key) { table[index] = new HashSlot(key, value); insertedNew = false; success = true; break; } } if (!success) { throw new Exception("__INTERNAL_ERROR > DHHashTable > SetValueInTable :: value not inserted, loops end"); } return(insertedNew); }