File tree Expand file tree Collapse file tree
src/main/java/myworld/hummingbird/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ public class BitFieldAllocator {
1111
1212 private final BitField state ;
1313 private int lastFree = 0 ;
14+ private int allocated = 0 ;
1415
1516 public BitFieldAllocator (int initialSize ){
1617 state = new BitField (initialSize );
@@ -21,6 +22,7 @@ public synchronized int allocate(){
2122 state .set (lastFree );
2223 var ptr = lastFree ;
2324 lastFree = -1 ;
25+ allocated ++;
2426 return ptr ;
2527 }
2628
@@ -30,6 +32,7 @@ public synchronized int allocate(){
3032 if (freeBit != 0 ){
3133 var ptr = i * 64 + Long .numberOfLeadingZeros (freeBit );
3234 state .set (ptr );
35+ allocated ++;
3336 return ptr ;
3437 }
3538 }
@@ -41,8 +44,13 @@ public synchronized boolean isAllocated(int ptr){
4144 }
4245
4346 public synchronized void free (int ptr ){
47+ allocated --;
4448 state .clear (ptr );
4549 lastFree = ptr ;
4650 }
4751
52+ public synchronized int freeSpace (){
53+ return state .bitCount () - allocated ;
54+ }
55+
4856}
You can’t perform that action at this time.
0 commit comments