@@ -115,14 +115,14 @@ private static int bitmapToIdx(int bitmap, int position) {
115
115
}
116
116
}
117
117
118
- private static BitmapNode bitmapNodesForPair (TreePart one , int hashOne , TreePart two , int hashTwo , int hashShift ) {
118
+ private static BitmapPart bitmapNodesForPair (TreePart one , int hashOne , TreePart two , int hashTwo , int hashShift ) {
119
119
assert hashOne != hashTwo : "bitmapNodesForPair cannot work with colliding nodes" ;
120
120
int oneIdx = hashIdx (hashOne , hashShift );
121
121
int twoIdx = hashIdx (hashTwo , hashShift );
122
122
if (oneIdx == twoIdx ) {
123
- return new BitmapNode (new TreePart []{bitmapNodesForPair (one , hashOne , two , hashTwo , hashShift + 5 )}, idxToBit (twoIdx ));
123
+ return new BitmapPart (new TreePart []{bitmapNodesForPair (one , hashOne , two , hashTwo , hashShift + 5 )}, idxToBit (twoIdx ));
124
124
}
125
- return new BitmapNode (oneIdx > twoIdx ? new TreePart []{one , two } : new TreePart []{two , one }, idxToBit (twoIdx ) | idxToBit (oneIdx ));
125
+ return new BitmapPart (oneIdx > twoIdx ? new TreePart []{one , two } : new TreePart []{two , one }, idxToBit (twoIdx ) | idxToBit (oneIdx ));
126
126
}
127
127
128
128
private static TreePart nodeWithEntry (TreePart original , Entry newEntry , int hashShift ) {
@@ -136,13 +136,13 @@ private static TreePart nodeWithEntry(TreePart original, Entry newEntry, int has
136
136
if (PyObjectRichCompareBool .EqNode .getUncached ().execute (null , newEntry .key , existing .key )) {
137
137
return newEntry ;
138
138
} else {
139
- return new CollisionNode (existing .hash , existing , newEntry );
139
+ return new CollisionPart (existing .hash , existing , newEntry );
140
140
}
141
141
}
142
142
return bitmapNodesForPair (newEntry , newEntry .hash , existing , existing .hash , hashShift );
143
143
}
144
- if (original instanceof BitmapNode ) {
145
- BitmapNode existing = (BitmapNode ) original ;
144
+ if (original instanceof BitmapPart ) {
145
+ BitmapPart existing = (BitmapPart ) original ;
146
146
int position = hashIdx (newEntry .hash , hashShift );
147
147
int sparseIdx = bitmapToIdx (existing .bitmap , position );
148
148
if (sparseIdx < 0 ) {
@@ -156,7 +156,7 @@ private static TreePart nodeWithEntry(TreePart original, Entry newEntry, int has
156
156
newElems [i ] = existing .elems [elemsI --];
157
157
}
158
158
}
159
- return new ArrayNode (newElems );
159
+ return new ArrayPart (newElems );
160
160
} else {
161
161
int newBitmap = existing .bitmap | idxToBit (position );
162
162
TreePart [] newElems = new TreePart [existing .elems .length + 1 ];
@@ -170,33 +170,33 @@ private static TreePart nodeWithEntry(TreePart original, Entry newEntry, int has
170
170
newElems [i ] = existing .elems [oldI ++];
171
171
}
172
172
}
173
- return new BitmapNode (newElems , newBitmap );
173
+ return new BitmapPart (newElems , newBitmap );
174
174
}
175
175
} else {
176
176
TreePart [] toReplaceIn = existing .elems .clone ();
177
177
TreePart toReplace = toReplaceIn [sparseIdx ];
178
178
TreePart newPart = nodeWithEntry (toReplace , newEntry , hashShift + 5 );
179
179
toReplaceIn [sparseIdx ] = newPart ;
180
- return new BitmapNode (toReplaceIn , existing .bitmap );
180
+ return new BitmapPart (toReplaceIn , existing .bitmap );
181
181
}
182
182
}
183
- if (original instanceof ArrayNode ) {
184
- ArrayNode existing = (ArrayNode ) original ;
183
+ if (original instanceof ArrayPart ) {
184
+ ArrayPart existing = (ArrayPart ) original ;
185
185
int position = hashIdx (newEntry .hash , hashShift );
186
186
TreePart [] toReplaceIn = existing .elems .clone ();
187
187
TreePart toReplace = toReplaceIn [position ];
188
188
TreePart newPart = nodeWithEntry (toReplace , newEntry , hashShift + 5 );
189
189
toReplaceIn [position ] = newPart ;
190
- return new ArrayNode (toReplaceIn );
190
+ return new ArrayPart (toReplaceIn );
191
191
}
192
- if (original instanceof CollisionNode ) {
193
- CollisionNode existing = (CollisionNode ) original ;
192
+ if (original instanceof CollisionPart ) {
193
+ CollisionPart existing = (CollisionPart ) original ;
194
194
if (existing .hash == newEntry .hash ) {
195
195
int originalLength = existing .elems .length ;
196
196
Entry [] newElems = new Entry [originalLength + 1 ];
197
197
newElems [originalLength ] = newEntry ;
198
198
System .arraycopy (existing .elems , 0 , newElems , 0 , originalLength );
199
- return new CollisionNode (existing .hash , newElems );
199
+ return new CollisionPart (existing .hash , newElems );
200
200
} else {
201
201
return bitmapNodesForPair (existing , existing .hash , newEntry , newEntry .hash , hashShift );
202
202
}
@@ -221,8 +221,8 @@ private static Object lookupKeyInPart(TreePart part, Object key, int hash, int h
221
221
}
222
222
return null ;
223
223
}
224
- if (part instanceof BitmapNode ) {
225
- BitmapNode existing = (BitmapNode ) part ;
224
+ if (part instanceof BitmapPart ) {
225
+ BitmapPart existing = (BitmapPart ) part ;
226
226
int position = hashIdx (hash , hashShift );
227
227
int sparseIdx = bitmapToIdx (existing .bitmap , position );
228
228
if (sparseIdx < 0 ) {
@@ -231,13 +231,13 @@ private static Object lookupKeyInPart(TreePart part, Object key, int hash, int h
231
231
TreePart deeper = existing .elems [sparseIdx ];
232
232
return lookupKeyInPart (deeper , key , hash , hashShift + 5 );
233
233
}
234
- if (part instanceof ArrayNode ) {
235
- ArrayNode existing = (ArrayNode ) part ;
234
+ if (part instanceof ArrayPart ) {
235
+ ArrayPart existing = (ArrayPart ) part ;
236
236
int position = hashIdx (hash , hashShift );
237
237
return lookupKeyInPart (existing .elems [position ], key , hash , hashShift + 5 );
238
238
}
239
- if (part instanceof CollisionNode ) {
240
- CollisionNode existing = (CollisionNode ) part ;
239
+ if (part instanceof CollisionPart ) {
240
+ CollisionPart existing = (CollisionPart ) part ;
241
241
if (existing .hash != hash ) {
242
242
return null ;
243
243
}
@@ -256,7 +256,7 @@ public Object lookup(Object key, int hash) {
256
256
}
257
257
258
258
@ SuppressWarnings ("fallthrough" )
259
- private static TreePart bitmapWithoutKey (BitmapNode existing , Object key , int hash , int hashShift ) {
259
+ private static TreePart bitmapWithoutKey (BitmapPart existing , Object key , int hash , int hashShift ) {
260
260
int position = hashIdx (hash , hashShift );
261
261
int sparseIdx = bitmapToIdx (existing .bitmap , position );
262
262
if (sparseIdx < 0 ) {
@@ -268,7 +268,7 @@ private static TreePart bitmapWithoutKey(BitmapNode existing, Object key, int ha
268
268
if (replacement == null ) {
269
269
// if we have no elements, we can simply delete the BitmapPart entirely
270
270
return null ;
271
- } else if (replacement instanceof Entry || replacement instanceof CollisionNode ) {
271
+ } else if (replacement instanceof Entry || replacement instanceof CollisionPart ) {
272
272
// if the only element is an entry, we can simply skip the BitmapPart
273
273
// we cannot do the same for the other TreeParts, since those rely on
274
274
// depth to find which part of the hash is relevant to them.
@@ -283,7 +283,7 @@ private static TreePart bitmapWithoutKey(BitmapNode existing, Object key, int ha
283
283
// return that element, otherwise, run the normal removal logic
284
284
int otherIdx = sparseIdx == 0 ? 1 : 0 ;
285
285
TreePart otherElem = existing .elems [otherIdx ];
286
- if (otherElem instanceof Entry || otherElem instanceof CollisionNode ) {
286
+ if (otherElem instanceof Entry || otherElem instanceof CollisionPart ) {
287
287
return otherElem ;
288
288
}
289
289
}
@@ -300,11 +300,11 @@ private static TreePart bitmapWithoutKey(BitmapNode existing, Object key, int ha
300
300
}
301
301
}
302
302
assert newI == newElems .length ;
303
- return new BitmapNode (newElems , newBitmap );
303
+ return new BitmapPart (newElems , newBitmap );
304
304
}
305
305
TreePart [] newElems = existing .elems .clone ();
306
306
newElems [sparseIdx ] = replacement ;
307
- return new BitmapNode (newElems , existing .bitmap );
307
+ return new BitmapPart (newElems , existing .bitmap );
308
308
}
309
309
}
310
310
@@ -321,12 +321,12 @@ private static TreePart partWithoutKey(TreePart root, Object key, int hash, int
321
321
}
322
322
return root ;
323
323
}
324
- if (root instanceof BitmapNode ) {
325
- BitmapNode existing = (BitmapNode ) root ;
324
+ if (root instanceof BitmapPart ) {
325
+ BitmapPart existing = (BitmapPart ) root ;
326
326
return bitmapWithoutKey (existing , key , hash , hashShift );
327
327
}
328
- if (root instanceof ArrayNode ) {
329
- ArrayNode existing = (ArrayNode ) root ;
328
+ if (root instanceof ArrayPart ) {
329
+ ArrayPart existing = (ArrayPart ) root ;
330
330
int position = hashIdx (hash , hashShift );
331
331
TreePart replacement = partWithoutKey (existing .elems [position ], key , hash , hashShift + 5 );
332
332
if (replacement == null ) {
@@ -348,16 +348,16 @@ private static TreePart partWithoutKey(TreePart root, Object key, int hash, int
348
348
}
349
349
}
350
350
assert newElemsI == 0 ;
351
- return new BitmapNode (newElems , bitmap );
351
+ return new BitmapPart (newElems , bitmap );
352
352
}
353
353
// fall through to normal logic
354
354
}
355
355
TreePart [] newElems = existing .elems .clone ();
356
356
newElems [position ] = replacement ;
357
- return new ArrayNode (newElems );
357
+ return new ArrayPart (newElems );
358
358
}
359
- if (root instanceof CollisionNode ) {
360
- CollisionNode existing = (CollisionNode ) root ;
359
+ if (root instanceof CollisionPart ) {
360
+ CollisionPart existing = (CollisionPart ) root ;
361
361
if (existing .hash == hash ) {
362
362
for (int i = 0 ; i < existing .elems .length ; ++i ) {
363
363
if (PyObjectRichCompareBool .EqNode .getUncached ().execute (null , existing .elems [i ].key , key )) {
@@ -374,7 +374,7 @@ private static TreePart partWithoutKey(TreePart root, Object key, int hash, int
374
374
if (newElems .length == 1 ) {
375
375
return newElems [0 ];
376
376
}
377
- return new CollisionNode (hash , newElems );
377
+ return new CollisionPart (hash , newElems );
378
378
}
379
379
}
380
380
}
@@ -387,11 +387,11 @@ public Hamt without(Object key, int hash) {
387
387
return new Hamt (partWithoutKey (root , key , hash , 0 ));
388
388
}
389
389
390
- private final static class BitmapNode implements TreePart {
390
+ private final static class BitmapPart implements TreePart {
391
391
final int bitmap ;
392
392
final TreePart [] elems ;
393
393
394
- public BitmapNode (TreePart [] elems , int bitmap ) {
394
+ public BitmapPart (TreePart [] elems , int bitmap ) {
395
395
for (TreePart e : elems ) {
396
396
assert e != null ;
397
397
}
@@ -413,10 +413,10 @@ public String dump(int indent) {
413
413
}
414
414
}
415
415
416
- private final static class ArrayNode implements TreePart {
416
+ private final static class ArrayPart implements TreePart {
417
417
final TreePart [] elems ;
418
418
419
- public ArrayNode (TreePart [] elems ) {
419
+ public ArrayPart (TreePart [] elems ) {
420
420
assert elems .length == 32 ;
421
421
this .elems = elems ;
422
422
}
@@ -433,11 +433,11 @@ public String dump(int indent) {
433
433
}
434
434
}
435
435
436
- private final static class CollisionNode implements TreePart {
436
+ private final static class CollisionPart implements TreePart {
437
437
final int hash ;
438
438
final Entry [] elems ;
439
439
440
- public CollisionNode (int hash , Entry ... elems ) {
440
+ public CollisionPart (int hash , Entry ... elems ) {
441
441
this .hash = hash ;
442
442
this .elems = elems ;
443
443
}
0 commit comments