/// <summary> /// Добавление нового элемента. /// </summary> /// <param name="item">Элемент.</param> public void Add(ItemMap <TKey, TValue> item) { if (!Keys.Contains(item.Key)) { Keys.Add(item.Key); Items.Add(item); } }
/// <summary> /// Добавить новый элемент. /// </summary> /// <param name="item">Элемент.</param> public void Add(ItemMap <TKey, TValue> item) { var hash = GetHash(item.Key); if (Keys.Contains(item.Key)) { return; } if (Items[hash] == null) { Keys.Add(item.Key); Items[hash] = item; } else { var placed = false; for (var i = hash; i < size; i++) { if (Items[i] == null) { Keys.Add(item.Key); Items[i] = item; placed = true; break; } if (Items[i].Key.Equals(item.Key)) { return; } } if (!placed) { for (var i = 0; i < hash; i++) { if (Items[i] == null) { Keys.Add(item.Key); Items[i] = item; placed = true; break; } if (Items[i].Key.Equals(item.Key)) { return; } } } if (!placed) { throw new Exception("Dictionary is full."); } } }