A vector (array) of bits that is accessed in units ("registers") of width bits which are stored as 64bit "words" ( long s). In this context a register is at most 64bits.
| 23 | * are stored as 64bit "words" (<code>long</code>s). In this context a register is at most 64bits. |
| 24 | */ |
| 25 | class BitVector implements Cloneable { |
| 26 | // NOTE: in this context, a word is 64bits |
| 27 | |
| 28 | // rather than doing division to determine how a bit index fits into 64bit |
| 29 | // words (i.e. longs), bit shifting is used |
| 30 | private static final int LOG2_BITS_PER_WORD = 6 /*=>64bits*/; |
| 31 | private static final int BITS_PER_WORD = 1 << LOG2_BITS_PER_WORD; |
| 32 | private static final int BITS_PER_WORD_MASK = BITS_PER_WORD - 1; |
| 33 | |
| 34 | // ditto from above but for bytes (for output) |
| 35 | private static final int LOG2_BITS_PER_BYTE = 3 /*=>8bits*/; |
| 36 | public static final int BITS_PER_BYTE = 1 << LOG2_BITS_PER_BYTE; |
| 37 | |
| 38 | // ======================================================================== |
| 39 | public static final int BYTES_PER_WORD = 8 /*8 bytes in a long*/; |
| 40 | |
| 41 | // ************************************************************************ |
| 42 | // 64bit words |
| 43 | private final long[] words; |
| 44 | |
| 45 | public final long[] words() { |
| 46 | return words; |
| 47 | } |
| 48 | |
| 49 | public final int wordCount() { |
| 50 | return words.length; |
| 51 | } |
| 52 | |
| 53 | public final int byteCount() { |
| 54 | return wordCount() * BYTES_PER_WORD; |
| 55 | } |
| 56 | |
| 57 | // the width of a register in bits (this cannot be more than 64 (the word size)) |
| 58 | private final int registerWidth; |
| 59 | |
| 60 | public final int registerWidth() { |
| 61 | return registerWidth; |
| 62 | } |
| 63 | |
| 64 | private final long count; |
| 65 | |
| 66 | // ------------------------------------------------------------------------ |
| 67 | private final long registerMask; |
| 68 | |
| 69 | // ======================================================================== |
| 70 | /** |
| 71 | * @param width the width of each register. This cannot be negative or zero or greater than 63 |
| 72 | * (the signed word size). |
| 73 | * @param count the number of registers. This cannot be negative or zero |
| 74 | */ |
| 75 | public BitVector(final int width, final long count) { |
| 76 | // ceil((width * count)/BITS_PER_WORD) |
| 77 | this.words = new long[(int) (((width * count) + BITS_PER_WORD_MASK) >>> LOG2_BITS_PER_WORD)]; |
| 78 | this.registerWidth = width; |
| 79 | this.count = count; |
| 80 | |
| 81 | this.registerMask = (1L << width) - 1; |
| 82 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…