Skip to content

Commit bd035f5

Browse files
committed
Hashing in reasonable shape
After *lots* of work. Still a bunch of things that could be improved plus code needs a clean up.
1 parent 549d80a commit bd035f5

File tree

10 files changed

+315
-277
lines changed

10 files changed

+315
-277
lines changed

src/algorithms/controllers/AVLTreeInsertion.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,10 @@ export default {
802802
vis.graph.setFunctionName('Tree is Empty');
803803
vis.graph.setFunctionInsertText(``);
804804
vis.array.patch(0);
805+
// make a bit more room for tree
806+
vis.graph.setSize(2.5);
807+
vis.graph.setZoom(0.8);
808+
vis.array.setZoom(0.9);
805809
},
806810
[nodes],
807811
1

src/algorithms/controllers/HashingCommon.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,26 @@ export const POINTER_CUT_OFF = 1;
6868
* @param {*} toggleAnimate whether animation is carried out or not
6969
* @returns the hashed value
7070
*/
71-
export function hash1(chunker, bookmark, key, tableSize, toggleAnimate) {
71+
export function hash1(chunker, bookmark, key, tableSize, toggleAnimate, type) {
7272
let hashed = (key * PRIME) % tableSize; // Hash the key
7373

7474
if (toggleAnimate) {
7575
// Update the graph
7676
chunker.add(
7777
bookmark,
78-
(vis, val) => {
78+
(vis, val, key) => {
7979
vis.graph.updateNode(HASH_GRAPH.Value, val);
8080
vis.graph.select(HASH_GRAPH.Value);
81+
vis.graph.updateNode(HASH_GRAPH.Key, key);
82+
let kth = vis.array.getKth();
83+
vis.array.showKth({
84+
key: key,
85+
type,
86+
insertions: kth.insertions,
87+
increment: ' '
88+
});
8189
},
82-
[hashed]
90+
[hashed, key, type]
8391
)
8492
}
8593

@@ -104,6 +112,7 @@ export function hash2(chunker, bookmark, key, tableSize, toggleAnimate) {
104112
chunker.add(
105113
bookmark,
106114
(vis, val) => {
115+
vis.graph.updateNode(HASH_GRAPH.Key2, key);
107116
vis.graph.updateNode(HASH_GRAPH.Value2, val);
108117
vis.graph.select(HASH_GRAPH.Value2);
109118
},

src/algorithms/controllers/HashingDelete.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default function HashingDelete(
5656
);
5757

5858
// Hashing the key
59-
let i = hash1(chunker, IBookmarks.ApplyHash, key, SIZE, true); // Target value after being hashed
59+
let i = hash1(chunker, IBookmarks.ApplyHash, key, SIZE, true, HASH_TYPE.Delete); // Target value after being hashed
6060

6161
/** This part is for Linear Probing and Double Hashing */
6262
if (ALGORITHM_NAME !== 'HashingCH') {
@@ -85,7 +85,7 @@ export default function HashingDelete(
8585
[i]
8686
);
8787

88-
let explored = 0;
88+
let explored = 0; // XXX shouldn't need this
8989
// Search for the target key, checking each probed position
9090
while (table[i] !== key && table[i] !== undefined && explored < SIZE) {
9191
// Chunker for not matching

0 commit comments

Comments
 (0)