public void Remove(string key) { var slotNum = HashString(key); var list = _items[slotNum]; HashTableItem found = null; if (list == null) { return; } foreach (var item in list) { if (item.Key == key) { found = item; break; } } if (found != null) { list.Remove(found); } }
public void Add(TKey key, TValue value) { if (GetLoadFactory() > LOAD_FACTOR) { this.Resize(); } int index = Hash(key); if (array[index] == null) { array[index] = new LinkedList <HashTableItem <TKey, TValue> >(); } var hashTableItem = new HashTableItem <TKey, TValue>(key, value); var node = new LinkedListNode <HashTableItem <TKey, TValue> >(hashTableItem); foreach (var item in array[index]) { if (item.Key.Equals(key)) { throw new InvalidOperationException("Значение с заданным ключем уже существует"); } } array[index].AddFirst(node); size++; }
public int Add(TKey key, TValue value) { int index = Hash(key); if (array[index] == null) { array[index] = new LinkedList <HashTableItem <TKey, TValue> >(); } HashTableItem <TKey, TValue> hashTable = new HashTableItem <TKey, TValue>(key, value); LinkedListNode <HashTableItem <TKey, TValue> > nodeHashTable = new LinkedListNode <HashTableItem <TKey, TValue> >(hashTable); array[index].AddFirst(nodeHashTable); return(index); }
//Добавление в хэш таблицу public int Add(TKey key, TValue value) { if (!CheckSize()) { this.Resize(); } int index = hash(key); if (array[index] == null) { array[index] = new LinkedList <HashTableItem <TKey, TValue> >(); } HashTableItem <TKey, TValue> hashTable = new HashTableItem <TKey, TValue>(key, value); LinkedListNode <HashTableItem <TKey, TValue> > nodeHashTable = new LinkedListNode <HashTableItem <TKey, TValue> >(hashTable); array[index].AddFirst(nodeHashTable); Count++; return(index); }