public override void Add(Key key, Value value) { if (loadFactorThresholdReached) { BucketEntry <Key, Value>[] newArray = new BucketEntry <Key, Value> [(int)(array.Length * increaseSizeFactor)]; for (int i = 0; i < array.Length - 1; i++) { if (array[i].Head.Key != null && array[i].Head.Value != null) { int newIndex = Hash(array[i].Head.Key, newArray.Length); newArray[newIndex] = array[i]; } if (array[i].Items.Count > 0) { foreach (KeyValuePair <Key, Value> item in array[i].Items) { int newIndex = Hash(item.Key, newArray.Length); newArray[newIndex].Add(item); } } } array = newArray; CalculateLoadFactor(); int index = Hash(key, array.Length); array[index].Add(new KeyValuePair <Key, Value>(key, value)); } else { int index = Hash(key, array.Length); array[index].Add(new KeyValuePair <Key, Value>(key, value)); CalculateLoadFactor(); } }
public ListHashTable(int initialSize) : base(initialSize) { array = new BucketEntry <Key, Value> [initialSize]; for (int i = 0; i < array.Length; i++) { array[i] = new(); } }