@@ -25,6 +25,7 @@ function hashByReference(o) {
25
25
referenceMap . set ( o , hash ) ;
26
26
return hash ;
27
27
}
28
+
28
29
/**
29
30
* merge two hashes in an order sensitive way
30
31
* @param {number } a
@@ -34,6 +35,7 @@ function hashByReference(o) {
34
35
function hashMerge ( a , b ) {
35
36
return ( a ^ ( b + 0x9e3779b9 + ( a << 6 ) + ( a >> 2 ) ) ) | 0 ;
36
37
}
38
+
37
39
/**
38
40
* standard string hash popularised by java
39
41
* @param {string } s
@@ -47,6 +49,7 @@ function hashString(s) {
47
49
}
48
50
return hash ;
49
51
}
52
+
50
53
/**
51
54
* hash a number by converting to two integers and do some jumbling
52
55
* @param {number } n
@@ -58,6 +61,7 @@ function hashNumber(n) {
58
61
const j = tempDataView . getInt32 ( 4 ) ;
59
62
return Math . imul ( 0x45d9f3b , ( i >> 16 ) ^ i ) ^ j ;
60
63
}
64
+
61
65
/**
62
66
* hash a BigInt by converting it to a string and hashing that
63
67
* @param {BigInt } n
@@ -66,6 +70,7 @@ function hashNumber(n) {
66
70
function hashBigInt ( n ) {
67
71
return hashString ( n . toString ( ) ) ;
68
72
}
73
+
69
74
/**
70
75
* hash any js object
71
76
* @param {any } o
@@ -113,6 +118,7 @@ function hashObject(o) {
113
118
}
114
119
return h ;
115
120
}
121
+
116
122
/**
117
123
* hash any js value
118
124
* @param {any } u
@@ -140,6 +146,7 @@ export function getHash(u) {
140
146
return 0 ; // should be unreachable
141
147
}
142
148
}
149
+
143
150
/**
144
151
* @template K,V
145
152
* @typedef {ArrayNode<K,V> | IndexNode<K,V> | CollisionNode<K,V> } Node
@@ -172,6 +179,7 @@ const ENTRY = 0;
172
179
const ARRAY_NODE = 1 ;
173
180
const INDEX_NODE = 2 ;
174
181
const COLLISION_NODE = 3 ;
182
+
175
183
/** @type {IndexNode<any,any> } */
176
184
const EMPTY = {
177
185
type : INDEX_NODE ,
@@ -187,6 +195,7 @@ const EMPTY = {
187
195
function mask ( hash , shift ) {
188
196
return ( hash >>> shift ) & MASK ;
189
197
}
198
+
190
199
/**
191
200
* Set only the Nth bit where N is the masked hash
192
201
* @param {number } hash
@@ -196,6 +205,7 @@ function mask(hash, shift) {
196
205
function bitpos ( hash , shift ) {
197
206
return 1 << mask ( hash , shift ) ;
198
207
}
208
+
199
209
/**
200
210
* Count the number of 1 bits in a number
201
211
* @param {number } x
@@ -209,6 +219,7 @@ function bitcount(x) {
209
219
x += x >> 16 ;
210
220
return x & 0x7f ;
211
221
}
222
+
212
223
/**
213
224
* Calculate the array index of an item in a bitmap index node
214
225
* @param {number } bitmap
@@ -218,6 +229,7 @@ function bitcount(x) {
218
229
function index ( bitmap , bit ) {
219
230
return bitcount ( bitmap & ( bit - 1 ) ) ;
220
231
}
232
+
221
233
/**
222
234
* Efficiently copy an array and set one value at an index
223
235
* @template T
@@ -235,6 +247,7 @@ function cloneAndSet(arr, at, val) {
235
247
out [ at ] = val ;
236
248
return out ;
237
249
}
250
+
238
251
/**
239
252
* Efficiently copy an array and insert one value at an index
240
253
* @template T
@@ -257,6 +270,7 @@ function spliceIn(arr, at, val) {
257
270
}
258
271
return out ;
259
272
}
273
+
260
274
/**
261
275
* Efficiently copy an array and remove one value at an index
262
276
* @template T
@@ -278,6 +292,7 @@ function spliceOut(arr, at) {
278
292
}
279
293
return out ;
280
294
}
295
+
281
296
/**
282
297
* Create a new node containing two entries
283
298
* @template K,V
@@ -308,9 +323,10 @@ function createNode(shift, key1, val1, key2hash, key2, val2) {
308
323
key2hash ,
309
324
key2 ,
310
325
val2 ,
311
- addedLeaf
326
+ addedLeaf ,
312
327
) ;
313
328
}
329
+
314
330
/**
315
331
* @template T,K,V
316
332
* @callback AssocFunction
@@ -377,7 +393,7 @@ function assocArray(root, shift, hash, key, val, addedLeaf) {
377
393
array : cloneAndSet (
378
394
root . array ,
379
395
idx ,
380
- createNode ( shift + SHIFT , node . k , node . v , hash , key , val )
396
+ createNode ( shift + SHIFT , node . k , node . v , hash , key , val ) ,
381
397
) ,
382
398
} ;
383
399
}
@@ -441,7 +457,7 @@ function assocIndex(root, shift, hash, key, val, addedLeaf) {
441
457
array : cloneAndSet (
442
458
root . array ,
443
459
idx ,
444
- createNode ( shift + SHIFT , nodeKey , node . v , hash , key , val )
460
+ createNode ( shift + SHIFT , nodeKey , node . v , hash , key , val ) ,
445
461
) ,
446
462
} ;
447
463
} else {
@@ -528,7 +544,7 @@ function assocCollision(root, shift, hash, key, val, addedLeaf) {
528
544
hash ,
529
545
key ,
530
546
val ,
531
- addedLeaf
547
+ addedLeaf ,
532
548
) ;
533
549
}
534
550
/**
@@ -813,6 +829,7 @@ function forEach(root, fn) {
813
829
forEach ( item , fn ) ;
814
830
}
815
831
}
832
+
816
833
/**
817
834
* Extra wrapper to keep track of Dict size and clean up the API
818
835
* @template K,V
@@ -833,6 +850,7 @@ export default class Dict {
833
850
}
834
851
return m ;
835
852
}
853
+
836
854
/**
837
855
* @template K,V
838
856
* @param {Map<K,V> } o
@@ -846,9 +864,11 @@ export default class Dict {
846
864
} ) ;
847
865
return m ;
848
866
}
867
+
849
868
static new ( ) {
850
869
return new Dict ( undefined , 0 ) ;
851
870
}
871
+
852
872
/**
853
873
* @param {undefined | Node<K,V> } root
854
874
* @param {number } size
0 commit comments