/** * Method to perform rank0 using linear scan. * * @param i Position in the bitmap. * @return Value of rank0 at specified position. */ public long getRank0(int i) { long count = 0; for (int k = 0; k <= i; k++) { if (this.getBit(k) == 0) count++; } return count; }
/** * Method to perform rank1 using linear scan. * * @param i Position in the bitmap. * @return Value of rank1 at specified position. */ public long getRank1(int i) { long count = 0; for (int k = 0; k <= i; k++) { if (this.getBit(k) == 1) count++; } return count; }
/** * Method to perform select0 using linear scan. * * @param i Position in the bitmap. * @return Value of select0 at specified position. */ public long getSelect0(int i) { long sel = -1, count = 0; for (int k = 0; k < this.size; ++k) { if (this.getBit(k) == 0) count++; if (count == (i + 1)) { sel = k; break; } } return sel; }
/** * Method to perform select1 using linear scan. * * @param i Position in the bitmap. * @return Value of select1 at specified position. */ public long getSelect1(int i) { long sel = -1, count = 0; for (int k = 0; k < this.size; ++k) { if (this.getBit(k) == 1) count++; if (count == (i + 1)) { sel = k; break; } } return sel; }
if (bitMap.getBit(i) == 1) { count++;
/** * Test method: void setBit(int pos) * Test method: long getBit(int pos) * * @throws Exception */ public void testSetAndGetBit() throws Exception { BitMap instance = new BitMap(1000L); ArrayList<Long> test = new ArrayList<Long>(); for (int i = 0; i < 1000; i++) { if ((int) (Math.random() * 2) == 1) { instance.setBit(i); test.add(1L); } else { test.add(0L); } } for (int i = 0; i < 1000; i++) { long expResult = test.get(i); long result = instance.getBit(i); assertEquals(expResult, result); } }
/** * Test method: void clear() * * @throws Exception */ public void testClear() throws Exception { BitMap instance = new BitMap(1000L); for (int i = 0; i < 1000; i++) { if ((int) (Math.random() * 2) == 1) { instance.setBit(i); } } instance.clear(); for (int i = 0; i < 1000; i++) { assertEquals(instance.getBit(i), 0L); } }
blockClass = (int) bitMap.getValPos((int) pos, 4); pos += 4; blockOffset = (int) ((blockClass == 0) ? bitMap.getBit((int) pos) * 16 : 0); pos += Tables.offsetBits[blockClass]; res += blockClass + blockOffset;