Skip to content

Commit 964ce54

Browse files
author
Adam Hrbac
committed
Rename Hamt nodes to Parts to avoid confusion with truffle nodes
1 parent bb757f6 commit 964ce54

File tree

1 file changed

+41
-41
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars

1 file changed

+41
-41
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/Hamt.java

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ private static int bitmapToIdx(int bitmap, int position) {
115115
}
116116
}
117117

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) {
119119
assert hashOne != hashTwo : "bitmapNodesForPair cannot work with colliding nodes";
120120
int oneIdx = hashIdx(hashOne, hashShift);
121121
int twoIdx = hashIdx(hashTwo, hashShift);
122122
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));
124124
}
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));
126126
}
127127

128128
private static TreePart nodeWithEntry(TreePart original, Entry newEntry, int hashShift) {
@@ -136,13 +136,13 @@ private static TreePart nodeWithEntry(TreePart original, Entry newEntry, int has
136136
if (PyObjectRichCompareBool.EqNode.getUncached().execute(null, newEntry.key, existing.key)) {
137137
return newEntry;
138138
} else {
139-
return new CollisionNode(existing.hash, existing, newEntry);
139+
return new CollisionPart(existing.hash, existing, newEntry);
140140
}
141141
}
142142
return bitmapNodesForPair(newEntry, newEntry.hash, existing, existing.hash, hashShift);
143143
}
144-
if (original instanceof BitmapNode) {
145-
BitmapNode existing = (BitmapNode) original;
144+
if (original instanceof BitmapPart) {
145+
BitmapPart existing = (BitmapPart) original;
146146
int position = hashIdx(newEntry.hash, hashShift);
147147
int sparseIdx = bitmapToIdx(existing.bitmap, position);
148148
if (sparseIdx < 0) {
@@ -156,7 +156,7 @@ private static TreePart nodeWithEntry(TreePart original, Entry newEntry, int has
156156
newElems[i] = existing.elems[elemsI--];
157157
}
158158
}
159-
return new ArrayNode(newElems);
159+
return new ArrayPart(newElems);
160160
} else {
161161
int newBitmap = existing.bitmap | idxToBit(position);
162162
TreePart[] newElems = new TreePart[existing.elems.length + 1];
@@ -170,33 +170,33 @@ private static TreePart nodeWithEntry(TreePart original, Entry newEntry, int has
170170
newElems[i] = existing.elems[oldI++];
171171
}
172172
}
173-
return new BitmapNode(newElems, newBitmap);
173+
return new BitmapPart(newElems, newBitmap);
174174
}
175175
} else {
176176
TreePart[] toReplaceIn = existing.elems.clone();
177177
TreePart toReplace = toReplaceIn[sparseIdx];
178178
TreePart newPart = nodeWithEntry(toReplace, newEntry, hashShift + 5);
179179
toReplaceIn[sparseIdx] = newPart;
180-
return new BitmapNode(toReplaceIn, existing.bitmap);
180+
return new BitmapPart(toReplaceIn, existing.bitmap);
181181
}
182182
}
183-
if (original instanceof ArrayNode) {
184-
ArrayNode existing = (ArrayNode) original;
183+
if (original instanceof ArrayPart) {
184+
ArrayPart existing = (ArrayPart) original;
185185
int position = hashIdx(newEntry.hash, hashShift);
186186
TreePart[] toReplaceIn = existing.elems.clone();
187187
TreePart toReplace = toReplaceIn[position];
188188
TreePart newPart = nodeWithEntry(toReplace, newEntry, hashShift + 5);
189189
toReplaceIn[position] = newPart;
190-
return new ArrayNode(toReplaceIn);
190+
return new ArrayPart(toReplaceIn);
191191
}
192-
if (original instanceof CollisionNode) {
193-
CollisionNode existing = (CollisionNode) original;
192+
if (original instanceof CollisionPart) {
193+
CollisionPart existing = (CollisionPart) original;
194194
if (existing.hash == newEntry.hash) {
195195
int originalLength = existing.elems.length;
196196
Entry[] newElems = new Entry[originalLength + 1];
197197
newElems[originalLength] = newEntry;
198198
System.arraycopy(existing.elems, 0, newElems, 0, originalLength);
199-
return new CollisionNode(existing.hash, newElems);
199+
return new CollisionPart(existing.hash, newElems);
200200
} else {
201201
return bitmapNodesForPair(existing, existing.hash, newEntry, newEntry.hash, hashShift);
202202
}
@@ -221,8 +221,8 @@ private static Object lookupKeyInPart(TreePart part, Object key, int hash, int h
221221
}
222222
return null;
223223
}
224-
if (part instanceof BitmapNode) {
225-
BitmapNode existing = (BitmapNode) part;
224+
if (part instanceof BitmapPart) {
225+
BitmapPart existing = (BitmapPart) part;
226226
int position = hashIdx(hash, hashShift);
227227
int sparseIdx = bitmapToIdx(existing.bitmap, position);
228228
if (sparseIdx < 0) {
@@ -231,13 +231,13 @@ private static Object lookupKeyInPart(TreePart part, Object key, int hash, int h
231231
TreePart deeper = existing.elems[sparseIdx];
232232
return lookupKeyInPart(deeper, key, hash, hashShift + 5);
233233
}
234-
if (part instanceof ArrayNode) {
235-
ArrayNode existing = (ArrayNode) part;
234+
if (part instanceof ArrayPart) {
235+
ArrayPart existing = (ArrayPart) part;
236236
int position = hashIdx(hash, hashShift);
237237
return lookupKeyInPart(existing.elems[position], key, hash, hashShift + 5);
238238
}
239-
if (part instanceof CollisionNode) {
240-
CollisionNode existing = (CollisionNode) part;
239+
if (part instanceof CollisionPart) {
240+
CollisionPart existing = (CollisionPart) part;
241241
if (existing.hash != hash) {
242242
return null;
243243
}
@@ -256,7 +256,7 @@ public Object lookup(Object key, int hash) {
256256
}
257257

258258
@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) {
260260
int position = hashIdx(hash, hashShift);
261261
int sparseIdx = bitmapToIdx(existing.bitmap, position);
262262
if (sparseIdx < 0) {
@@ -268,7 +268,7 @@ private static TreePart bitmapWithoutKey(BitmapNode existing, Object key, int ha
268268
if (replacement == null) {
269269
// if we have no elements, we can simply delete the BitmapPart entirely
270270
return null;
271-
} else if (replacement instanceof Entry || replacement instanceof CollisionNode) {
271+
} else if (replacement instanceof Entry || replacement instanceof CollisionPart) {
272272
// if the only element is an entry, we can simply skip the BitmapPart
273273
// we cannot do the same for the other TreeParts, since those rely on
274274
// 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
283283
// return that element, otherwise, run the normal removal logic
284284
int otherIdx = sparseIdx == 0 ? 1 : 0;
285285
TreePart otherElem = existing.elems[otherIdx];
286-
if (otherElem instanceof Entry || otherElem instanceof CollisionNode) {
286+
if (otherElem instanceof Entry || otherElem instanceof CollisionPart) {
287287
return otherElem;
288288
}
289289
}
@@ -300,11 +300,11 @@ private static TreePart bitmapWithoutKey(BitmapNode existing, Object key, int ha
300300
}
301301
}
302302
assert newI == newElems.length;
303-
return new BitmapNode(newElems, newBitmap);
303+
return new BitmapPart(newElems, newBitmap);
304304
}
305305
TreePart[] newElems = existing.elems.clone();
306306
newElems[sparseIdx] = replacement;
307-
return new BitmapNode(newElems, existing.bitmap);
307+
return new BitmapPart(newElems, existing.bitmap);
308308
}
309309
}
310310

@@ -321,12 +321,12 @@ private static TreePart partWithoutKey(TreePart root, Object key, int hash, int
321321
}
322322
return root;
323323
}
324-
if (root instanceof BitmapNode) {
325-
BitmapNode existing = (BitmapNode) root;
324+
if (root instanceof BitmapPart) {
325+
BitmapPart existing = (BitmapPart) root;
326326
return bitmapWithoutKey(existing, key, hash, hashShift);
327327
}
328-
if (root instanceof ArrayNode) {
329-
ArrayNode existing = (ArrayNode) root;
328+
if (root instanceof ArrayPart) {
329+
ArrayPart existing = (ArrayPart) root;
330330
int position = hashIdx(hash, hashShift);
331331
TreePart replacement = partWithoutKey(existing.elems[position], key, hash, hashShift + 5);
332332
if (replacement == null) {
@@ -348,16 +348,16 @@ private static TreePart partWithoutKey(TreePart root, Object key, int hash, int
348348
}
349349
}
350350
assert newElemsI == 0;
351-
return new BitmapNode(newElems, bitmap);
351+
return new BitmapPart(newElems, bitmap);
352352
}
353353
// fall through to normal logic
354354
}
355355
TreePart[] newElems = existing.elems.clone();
356356
newElems[position] = replacement;
357-
return new ArrayNode(newElems);
357+
return new ArrayPart(newElems);
358358
}
359-
if (root instanceof CollisionNode) {
360-
CollisionNode existing = (CollisionNode) root;
359+
if (root instanceof CollisionPart) {
360+
CollisionPart existing = (CollisionPart) root;
361361
if (existing.hash == hash) {
362362
for (int i = 0; i < existing.elems.length; ++i) {
363363
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
374374
if (newElems.length == 1) {
375375
return newElems[0];
376376
}
377-
return new CollisionNode(hash, newElems);
377+
return new CollisionPart(hash, newElems);
378378
}
379379
}
380380
}
@@ -387,11 +387,11 @@ public Hamt without(Object key, int hash) {
387387
return new Hamt(partWithoutKey(root, key, hash, 0));
388388
}
389389

390-
private final static class BitmapNode implements TreePart {
390+
private final static class BitmapPart implements TreePart {
391391
final int bitmap;
392392
final TreePart[] elems;
393393

394-
public BitmapNode(TreePart[] elems, int bitmap) {
394+
public BitmapPart(TreePart[] elems, int bitmap) {
395395
for (TreePart e : elems) {
396396
assert e != null;
397397
}
@@ -413,10 +413,10 @@ public String dump(int indent) {
413413
}
414414
}
415415

416-
private final static class ArrayNode implements TreePart {
416+
private final static class ArrayPart implements TreePart {
417417
final TreePart[] elems;
418418

419-
public ArrayNode(TreePart[] elems) {
419+
public ArrayPart(TreePart[] elems) {
420420
assert elems.length == 32;
421421
this.elems = elems;
422422
}
@@ -433,11 +433,11 @@ public String dump(int indent) {
433433
}
434434
}
435435

436-
private final static class CollisionNode implements TreePart {
436+
private final static class CollisionPart implements TreePart {
437437
final int hash;
438438
final Entry[] elems;
439439

440-
public CollisionNode(int hash, Entry... elems) {
440+
public CollisionPart(int hash, Entry... elems) {
441441
this.hash = hash;
442442
this.elems = elems;
443443
}

0 commit comments

Comments
 (0)