From 0e94cdc0c481e9312d1b5033b3597c7c262ff878 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Mon, 12 Oct 2026 16:46:53 -0700 Subject: Check for cyclic class init before we emit code --- .../com/seaofnodes/simple/util/IntHashMap.java | 30 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'chapter25/src/main/java/com/seaofnodes/simple/util') diff --git a/chapter25/src/main/java/com/seaofnodes/simple/util/IntHashMap.java b/chapter25/src/main/java/com/seaofnodes/simple/util/IntHashMap.java index 55aaa9f9..b356ec31 100644 --- a/chapter25/src/main/java/com/seaofnodes/simple/util/IntHashMap.java +++ b/chapter25/src/main/java/com/seaofnodes/simple/util/IntHashMap.java @@ -17,6 +17,7 @@ public class IntHashMap { } public int size() { return _size; } + public boolean isEmpty() { return _size==0; } public void clear() { _size = 0; Arrays.fill(_es,_sentinel); @@ -29,7 +30,7 @@ public class IntHashMap { int old = _es[(slot<<1)+1]; if( old == _sentinel && val != _sentinel ) _size++; if( old != _sentinel && val == _sentinel ) _size--; - // Check cap + // Check cap, resize at 3/4 full if( _size > ((cap()>>1) + (cap()>>2)) ) { grow(); slot = probe(key); @@ -45,7 +46,7 @@ public class IntHashMap { return _es[(slot<<1)+1]; } - int probe( int key ) { + private int probe( int key ) { int mask = cap()-1; int slot = key & mask; while( _es[slot<<1] != _sentinel && _es[slot<<1] != key ) @@ -59,7 +60,28 @@ public class IntHashMap { _es = new int[_es.length<<1]; Arrays.fill(_es,_sentinel); for( int i=0; i