Sparse bit set. This implementation groups bits into blocks, and it could avoid allocating words to represent continuous zero bits when possible. This design saves memory and improves efficiency of set iterations. This implementation uses core design and some code from https://github.com/brettwo
| 36 | * and improve the readability. |
| 37 | */ |
| 38 | public class SparseBitSet extends AbstractBitSet |
| 39 | implements Serializable { |
| 40 | |
| 41 | // TODO: unify level1/2/3 and table/area/block |
| 42 | // Currently: |
| 43 | // w1/level1 = table |
| 44 | // w2/level2 = area |
| 45 | // w3/level3 = block |
| 46 | |
| 47 | //============================================================================== |
| 48 | // The critical parameters. These are set up so that the compiler may |
| 49 | // pre-compute all the values as compile-time constants. |
| 50 | //============================================================================== |
| 51 | |
| 52 | /** |
| 53 | * The number of bits in a positive integer, and the size of permitted index |
| 54 | * of a bit in the bit set. |
| 55 | */ |
| 56 | private static final int INDEX_SIZE = Integer.SIZE - 1; |
| 57 | |
| 58 | /** |
| 59 | * LEVEL3 is the number of bits of the level3 address. |
| 60 | */ |
| 61 | private static final int LEVEL3 = 5; // Do not change! |
| 62 | |
| 63 | /** |
| 64 | * LEVEL2 is the number of bits of the level2 address. |
| 65 | */ |
| 66 | private static final int LEVEL2 = 5; // Do not change! |
| 67 | |
| 68 | /** |
| 69 | * LEVEL1 is the number of bits of the level1 address. |
| 70 | */ |
| 71 | private static final int LEVEL1 = INDEX_SIZE - LEVEL2 - LEVEL3 - ADDRESS_BITS_PER_WORD; |
| 72 | |
| 73 | /** |
| 74 | * MAX_LENGTH1 is the maximum number of entries in the level1 set array. |
| 75 | */ |
| 76 | private static final int MAX_LENGTH1 = 1 << LEVEL1; |
| 77 | |
| 78 | /** |
| 79 | * LENGTH2 is the number of entries in the any level2 area. |
| 80 | */ |
| 81 | private static final int LENGTH2 = 1 << LEVEL2; |
| 82 | |
| 83 | /** |
| 84 | * LENGTH3 is the number of entries in the any level3 block. |
| 85 | */ |
| 86 | private static final int LENGTH3 = 1 << LEVEL3; |
| 87 | |
| 88 | /** |
| 89 | * The shift to create the word index. (I.e., move it to the right end) |
| 90 | */ |
| 91 | static final int SHIFT3 = ADDRESS_BITS_PER_WORD; |
| 92 | |
| 93 | /** |
| 94 | * MASK3 is the mask to extract the LEVEL3 address from a word index |
| 95 | * (after shifting by SHIFT3). |
nothing calls this directly
no outgoing calls
no test coverage detected