5
5
hash1 ,
6
6
HASH_GRAPH ,
7
7
EMPTY_CHAR ,
8
+ EMPTY_CHAR_CH ,
8
9
Colors ,
9
10
INDEX ,
10
11
POINTER ,
@@ -25,7 +26,7 @@ import { createPopper } from '@popperjs/core';
25
26
// Bookmarks to link chunker with pseudocode
26
27
const IBookmarks = {
27
28
Init : 1 ,
28
- EmptyArray : 2 ,
29
+ EmptyArray : 1 , // XXX delete init code
29
30
InitInsertion : 3 ,
30
31
NewInsertion : 4 ,
31
32
Hash1 : 5 ,
@@ -35,6 +36,10 @@ const IBookmarks = {
35
36
BulkInsert : 1 ,
36
37
}
37
38
39
+ // text to display after key in table to indicate there are more keys
40
+ // XXX MUST be the same in function extractArray in Array2DTracer.js
41
+ const ETC = ".." ;
42
+
38
43
export default {
39
44
explanation : HashingExp ,
40
45
@@ -66,7 +71,7 @@ export default {
66
71
67
72
// Initialize arrays
68
73
let indexArr = Array . from ( { length : SIZE } , ( _ , i ) => i ) ;
69
- let valueArr = Array ( SIZE ) . fill ( EMPTY_CHAR ) ;
74
+ let valueArr = Array ( SIZE ) . fill ( EMPTY_CHAR_CH ) ;
70
75
let nullArr = Array ( SIZE ) . fill ( '' ) ;
71
76
72
77
// For return
@@ -128,7 +133,7 @@ export default {
128
133
)
129
134
130
135
// Internally assign the key to the index
131
- table [ i ] . push ( key ) ;
136
+ table [ i ] . unshift ( key ) ;
132
137
133
138
// Chunker for placing the key
134
139
chunker . add (
@@ -154,11 +159,22 @@ export default {
154
159
popper . innerHTML = table [ idx ] ;
155
160
}
156
161
162
+ let slotCurValue = vis . array . getValueAt ( VALUE , idx ) ;
163
+ if ( slotCurValue === EMPTY_CHAR_CH )
164
+ // Update value of that index when the slot is empty
165
+ vis . array . updateValueAt ( VALUE , idx , '[' + val + ']' ) ;
166
+ else
167
+ // / Update value of that index when the slot is not empty
168
+ vis . array . updateValueAt ( VALUE , idx , '[' + val + '..' ) ;
169
+ vis . array . fill ( INDEX , idx , undefined , undefined , Colors . Insert ) ;
170
+
171
+ /*
157
172
let slotCurValue = vis.array.getValueAt(VALUE, idx);
158
173
if (slotCurValue === EMPTY_CHAR) vis.array.updateValueAt(VALUE, idx, val); // Update value of that index when the slot is empty
159
- else vis . array . updateValueAt ( VALUE , idx , slotCurValue + ( table [ idx ] . length == 2 ? ".." : "" ) ) ; // Update value of that index when the slot is not empty
174
+ else vis.array.updateValueAt(VALUE, idx, slotCurValue + (table[idx].length == 2 ? ETC : "")); // Update value of that index when the slot is not empty
160
175
vis.array.showKth({key: vis.array.getKth().key, type: HASH_TYPE.BulkInsert, insertions: insertions});
161
176
vis.array.fill(INDEX, idx, undefined, undefined, Colors.Insert); // Fill it green, indicating successful insertion
177
+ */
162
178
} ,
163
179
[ key , i , insertions , table ]
164
180
)
@@ -185,7 +201,7 @@ export default {
185
201
// hashed value
186
202
let i = hash1 ( null , null , key , table . length , false ) ;
187
203
188
- table [ i ] . push ( key ) ;
204
+ table [ i ] . unshift ( key ) ;
189
205
inserts [ key ] = i ;
190
206
lastHash = i ;
191
207
}
@@ -217,9 +233,13 @@ export default {
217
233
}
218
234
219
235
let slotCurValue = vis . array . getValueAt ( VALUE , inserts [ key ] ) ;
220
- console . log ( typeof ( slotCurValue ) ) ;
221
- if ( slotCurValue === EMPTY_CHAR ) vis . array . updateValueAt ( VALUE , inserts [ key ] , key ) ; // Update value of that index when the slot is empty
222
- else vis . array . updateValueAt ( VALUE , inserts [ key ] , slotCurValue + ( ( table [ inserts [ key ] ] . length >= 2 && typeof ( slotCurValue ) == 'number' ) ? ".." : "" ) ) ; // Update value of that index when the slot is not empty
236
+ console . log ( typeof ( slotCurValue ) , key , slotCurValue , table [ inserts [ key ] ] ) ;
237
+ if ( slotCurValue === EMPTY_CHAR_CH )
238
+ // Update value of that index when the slot is empty
239
+ vis . array . updateValueAt ( VALUE , inserts [ key ] , '[' + key + ']' ) ;
240
+ else
241
+ // / Update value of that index when the slot is not empty
242
+ vis . array . updateValueAt ( VALUE , inserts [ key ] , '[' + key + '..' ) ;
223
243
vis . array . fill ( INDEX , inserts [ key ] , undefined , undefined , Colors . Insert ) ;
224
244
}
225
245
vis . array . showKth ( { key : vis . array . getKth ( ) . key , type : HASH_TYPE . BulkInsert , insertions : insertions } ) ;
@@ -265,11 +285,12 @@ export default {
265
285
INDEX ,
266
286
{
267
287
rowLength : size > SMALL_SIZE ? SPLIT_SIZE : SMALL_SIZE ,
268
- rowHeader : [ 'Index' , 'Value ' , '' ]
288
+ rowHeader : [ 'Index' , 'Chain ' , '' ]
269
289
}
270
290
) ;
271
291
272
- vis . array . hideArrayAtIndex ( [ VALUE , POINTER ] ) ; // Hide value and pointer row intially
292
+ // vis.array.hideArrayAtIndex([VALUE, POINTER]); // Hide value and pointer row intially
293
+ vis . array . hideArrayAtIndex ( [ POINTER ] ) ; // Hide pointer row intially
273
294
274
295
vis . graph . weighted ( true ) ;
275
296
@@ -296,8 +317,9 @@ export default {
296
317
) ;
297
318
298
319
// Chunker to initialize empty array visually
320
+ /*
299
321
chunker.add(
300
- IBookmarks . EmptyArray ,
322
+ IBookmarks.Init ,
301
323
(vis) => {
302
324
// Show the value row
303
325
vis.array.hideArrayAtIndex(POINTER);
@@ -306,7 +328,7 @@ export default {
306
328
307
329
// Chunker for intializing insertion stat
308
330
chunker.add(
309
- IBookmarks . InitInsertion ,
331
+ IBookmarks.EmptyArray ,
310
332
(vis, insertions) => {
311
333
vis.array.showKth({
312
334
key: "",
@@ -318,6 +340,7 @@ export default {
318
340
},
319
341
[insertions]
320
342
)
343
+ */
321
344
322
345
// Magic numbers for length of splitting a postive integer string by "-", the index of "", and the number to delete when a negative integer is split by "-"
323
346
const POS_INTEGER_SPLIT_LENGTH = 1 ;
0 commit comments