Skip to content

Commit 1a6d7b9

Browse files
author
Justin Wetherell
committed
Found a bug in my TrieMap where key and value weren't being NULLed out on remove(). Applied the same fix to all Map Classes
1 parent c029506 commit 1a6d7b9

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

src/com/jwetherell/algorithms/data_structures/HashArrayMappedTrie.java

+2
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ public V remove(K key) {
208208
numOfChildren = parent.getNumberOfChildren();
209209
}
210210
}
211+
kvNode.key = 0;
212+
kvNode.value = null;
211213
size--;
212214
return value;
213215
}

src/com/jwetherell/algorithms/data_structures/HashMap.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ public V remove(K key) {
9494
if (pair.key.equals(key)) {
9595
list.remove(pair);
9696
size--;
97-
return pair.value;
97+
V value = pair.value;
98+
pair.key = null;
99+
pair.value = null;
100+
return value;
98101
}
99102
}
100103
return null;

src/com/jwetherell/algorithms/data_structures/SkipListMap.java

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public V remove(K key) {
6969
if (node instanceof SkipListMapNode) {
7070
SkipListMapNode<K, V> treeMapNode = (SkipListMapNode<K, V>) node;
7171
value = treeMapNode.value;
72+
treeMapNode.data = null;
73+
treeMapNode.value = null;
7274
}
7375
return value;
7476
}

src/com/jwetherell/algorithms/data_structures/TreeMap.java

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public V remove(K key) {
7373
if (node instanceof TreeMapNode) {
7474
TreeMapNode<K, V> treeMapNode = (TreeMapNode<K, V>) node;
7575
value = treeMapNode.value;
76+
treeMapNode.id = null;
77+
treeMapNode.value = null;
7678
}
7779
return value;
7880
}

src/com/jwetherell/algorithms/data_structures/TrieMap.java

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public V remove(K key) {
7171
if (node instanceof TrieMapNode) {
7272
TrieMapNode<V> tmn = (TrieMapNode<V>)node;
7373
value = tmn.value;
74+
tmn.value = null;
7475
}
7576
trie.remove(node);
7677
}

0 commit comments

Comments
 (0)