56
56
57
57
public final class Hamt {
58
58
59
- @ CompilerDirectives .TruffleBoundary
60
59
public String dump () {
61
60
return dumpPart (this .root , 0 );
62
61
}
@@ -65,28 +64,6 @@ private static String dumpPart(TreePart i, int indent) {
65
64
return i == null ? " " .repeat (indent ) + "null\n " : i .dump (indent );
66
65
}
67
66
68
- private interface TreePart {
69
- String dump (int indent );
70
- }
71
-
72
- @ CompilerDirectives .ValueType
73
- public static final class Entry implements TreePart {
74
- final Object key ;
75
- final int hash ;
76
- final Object value ;
77
-
78
- public Entry (Object key , int hash , Object value ) {
79
- this .key = key ;
80
- this .hash = hash & 0x3FFFFFFF ; // 30 bits
81
- this .value = value ;
82
- }
83
-
84
- @ Override
85
- public String dump (int indent ) {
86
- return " " .repeat (indent ) + String .format ("%s : %s (%d)\n " , key , value , hash );
87
- }
88
- }
89
-
90
67
// TODO: track size on the Hamt.
91
68
private final TreePart root ;
92
69
@@ -135,6 +112,7 @@ private static BitmapPart bitmapPartsForPair(TreePart one, int hashOne, TreePart
135
112
return new BitmapPart (oneIdx > twoIdx ? new TreePart []{one , two } : new TreePart []{two , one }, idxToBit (twoIdx ) | idxToBit (oneIdx ));
136
113
}
137
114
115
+ @ CompilerDirectives .TruffleBoundary
138
116
private static TreePart partWithEntry (TreePart original , Entry newEntry , int hashShift ) {
139
117
assert hashShift <= 25 ;
140
118
if (original == null ) {
@@ -219,6 +197,7 @@ public Hamt withEntry(Entry newEntry) {
219
197
return new Hamt (root );
220
198
}
221
199
200
+ @ CompilerDirectives .TruffleBoundary
222
201
private static Object lookupKeyInPart (TreePart part , Object key , int hash , int hashShift ) {
223
202
assert hashShift <= 25 ;
224
203
if (part == null ) {
@@ -314,6 +293,7 @@ private static TreePart bitmapWithoutKey(BitmapPart existing, Object key, int ha
314
293
return new BitmapPart (newElems , existing .bitmap );
315
294
}
316
295
296
+ @ CompilerDirectives .TruffleBoundary
317
297
private static TreePart partWithoutKey (TreePart root , Object key , int hash , int hashShift ) {
318
298
if (root == null ) {
319
299
return null ;
@@ -391,6 +371,10 @@ public Hamt without(Object key, int hash) {
391
371
return new Hamt (partWithoutKey (root , key , hash , 0 ));
392
372
}
393
373
374
+ private interface TreePart {
375
+ String dump (int indent );
376
+ }
377
+
394
378
private static final class BitmapPart implements TreePart {
395
379
final int bitmap ;
396
380
final TreePart [] elems ;
@@ -459,4 +443,22 @@ public String dump(int indent) {
459
443
return result .toString ();
460
444
}
461
445
}
446
+
447
+ @ CompilerDirectives .ValueType
448
+ public static final class Entry implements TreePart {
449
+ final Object key ;
450
+ final int hash ;
451
+ final Object value ;
452
+
453
+ public Entry (Object key , int hash , Object value ) {
454
+ this .key = key ;
455
+ this .hash = hash & 0x3FFFFFFF ; // 30 bits
456
+ this .value = value ;
457
+ }
458
+
459
+ @ Override
460
+ public String dump (int indent ) {
461
+ return " " .repeat (indent ) + String .format ("%s : %s (%d)\n " , key , value , hash );
462
+ }
463
+ }
462
464
}
0 commit comments