Skip to content

Commit c7f5bd0

Browse files
committed
fix: hashing (chaining) undefined bug
1 parent dbd8397 commit c7f5bd0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/algorithms/controllers/HashingDelete.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
VALUE,
1111
DELETE_CHAR,
1212
HASH_TYPE,
13-
newCycle
13+
newCycle,
14+
EMPTY_CHAR
1415
} from './HashingCommon';
1516

1617
// Bookmarks to link chunker with pseudocode
@@ -46,7 +47,7 @@ export default function HashingDelete(
4647
(vis, target) => {
4748

4849
vis.array.showKth({key: target, insertions: vis.array.getKth().insertions, type: HASH_TYPE.Delete}); // Show stats
49-
50+
5051
newCycle(vis, SIZE, key, ALGORITHM_NAME); // New delete cycle
5152
},
5253
[key]
@@ -176,7 +177,8 @@ export default function HashingDelete(
176177
popper.innerHTML = table[idx];
177178

178179
let firstItemOfChain = table[idx][0];
179-
vis.array.updateValueAt(VALUE, idx, firstItemOfChain + '..');
180+
if (firstItemOfChain != undefined) vis.array.updateValueAt(VALUE, idx, firstItemOfChain + '..');
181+
else vis.array.updateValueAt(VALUE, idx, EMPTY_CHAR);
180182

181183
vis.array.fill(INDEX, idx, undefined, undefined, Colors.Found); // Fill the slot with green, indicating that the key is found
182184
},
@@ -197,4 +199,4 @@ export default function HashingDelete(
197199
return total; // Since the deletion key is not found, nothing is deleted
198200
}
199201
}
200-
}
202+
}

0 commit comments

Comments
 (0)