Skip to content

Commit 917cbb5

Browse files
committed
Fix bug with nonexplicit singleton hash table store in ChainedHashTable
Two or greater ChainedHashTable objects have the same LinkedList array for storing values. Fix this by creating a new array for every ChainedHashTable objects.
1 parent fd847ea commit 917cbb5

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

DataStructures/Dictionaries/ChainedHashTable.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public enum CapacityManagementMode
3434
private decimal _slotsLoadFactor;
3535
private const int _defaultCapacity = 8;
3636
private DLinkedList<TKey, TValue>[] _hashTableStore;
37-
private static readonly DLinkedList<TKey, TValue>[] _emptyArray = new DLinkedList<TKey, TValue>[_defaultCapacity];
3837
private List<TKey> _keysCollection { get; set; }
3938
private List<TValue> _valuesCollection { get; set; }
4039

@@ -56,7 +55,7 @@ public enum CapacityManagementMode
5655
public ChainedHashTable()
5756
{
5857
this._size = 0;
59-
this._hashTableStore = _emptyArray;
58+
this._hashTableStore = new DLinkedList<TKey, TValue>[_defaultCapacity];
6059
this._freeSlotsCount = this._hashTableStore.Length;
6160
this._keysComparer = EqualityComparer<TKey>.Default;
6261
this._valuesComparer = EqualityComparer<TValue>.Default;
@@ -620,7 +619,7 @@ public void Clear()
620619
Array.Clear(_hashTableStore, 0, _hashTableStore.Length);
621620

622621
// Re-initialize to empty collection.
623-
_hashTableStore = _emptyArray;
622+
_hashTableStore = new DLinkedList<TKey, TValue>[_defaultCapacity];
624623

625624
_size = 0;
626625
_slotsLoadFactor = 0;

0 commit comments

Comments
 (0)