/** * 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; }
/** * Test method: void bitmapSize() * * @throws Exception */ public void testBitmapSize() throws Exception { BitMap instance = new BitMap(1000L); int expectedSize = (1000 / 64) + 1; assertEquals(instance.bitmapSize(), expectedSize); }
/** * Test method: void setValPos(int pos, long val, int bits) * Test method: long getValPos(int pos, int bits) * * @throws Exception */ public void testSetAndGetValPos() throws Exception { int pos = 60; int bits = 10; BitMap instance = new BitMap(1000L); instance.setValPos(pos, 1000, bits); long expResult = 1000L; long result = instance.getValPos(pos, bits); 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); } }
/** * Test method: LongBuffer getLongBuffer() * * @throws Exception */ public void testGetLongBuffer() throws Exception { BitMap instance = new BitMap(1000L); for (int i = 0; i < 1000; i++) { if ((int) (Math.random() * 2) == 1) { instance.setBit(i); } } LongBuffer bBuf = instance.getLongBuffer(); assertNotNull(bBuf); for (int i = 0; i < instance.bitmapSize(); i++) { assertEquals(bBuf.get(i), instance.data[i]); } }
/** * Test method: long getSelect1(int i) * * @throws Exception */ public void testGetSelect1() throws Exception { BitMap instance = new BitMap(2048); ArrayList<Long> test = new ArrayList<Long>(); for (int i = 0; i < 2048; i++) { if ((int) (Math.random() * 2) == 1) { instance.setBit(i); test.add((long) i); } } for (int i = 0; i < test.size(); i++) { assertEquals(instance.getSelect1(i), (long) test.get(i)); } }
/** * Test method: long getRank1(int i) * * @throws Exception */ public void testGetRank1() throws Exception { BitMap instance = new BitMap(2048); ArrayList<Long> test = new ArrayList<Long>(); long count = 0; for (int i = 0; i < 2048; i++) { if ((int) (Math.random() * 2) == 1) { instance.setBit(i); count++; } test.add(count); } for (int i = 0; i < test.size(); i++) { assertEquals(instance.getRank1(i), (long) test.get(i)); } }
/** * Test method: long getSelect0(int i) * * @throws Exception */ public void testGetSelect0() throws Exception { BitMap instance = new BitMap(2048); ArrayList<Long> test = new ArrayList<Long>(); for (int i = 0; i < 2048; i++) { if ((int) (Math.random() * 2) == 1) { instance.setBit(i); } else { test.add((long) i); } } for (int i = 0; i < test.size(); i++) { assertEquals(instance.getSelect0(i), (long) test.get(i)); } }
/** * Test method: long getRank0(int i) * * @throws Exception */ public void testGetRank0() throws Exception { BitMap instance = new BitMap(2048); ArrayList<Long> test = new ArrayList<Long>(); long count = 0; for (int i = 0; i < 2048; i++) { if ((int) (Math.random() * 2) == 1) { instance.setBit(i); } else { count++; } test.add(count); } for (int i = 0; i < test.size(); i++) { assertEquals(instance.getRank0(i), (long) test.get(i)); } }
double angle2 = Math.toRadians(angle); angle = angle2; int w = data.getWidth(); int h = data.getHeight(); int size = (int) (Math.sqrt(w * w + h * h)); BitMap newBitMap = new BitMap(size, size); int xCenter = w / 2; int yCenter = h / 2; continue; screenPixels.setValue(x, y, data.getValue(xData, yData));
/** * Test method: long getValPos(LongBuffer bitmap, int pos, int bits) * * @throws Exception */ public void testGetValPos() throws Exception { int pos = 60; int bits = 10; BitMap instance = new BitMap(1000L); instance.setValPos(pos, 1000, bits); LongBuffer bBuf = instance.getLongBuffer(); long expResult = 1000L; long result = BitMapOps.getValPos(bBuf, pos, bits); assertEquals(expResult, result); }
/** * Test method: void setVal(int i, long val) * Test method: long getVal(int i)* * * @throws Exception */ public void testSetAndGetVal() throws Exception { BMArray instance = new BMArray(1000, 64); for (int i = 0; i < 1000; i++) { instance.setVal(i, i); } for (int i = 0; i < 1000; i++) { long result = instance.getVal(i); assertEquals(i, result); } }
/** * Test method: long getRank1(int i) * * @throws Exception */ public void testGetRank1() throws Exception { BitMap B = new BitMap(2048); for (int i = 0; i < 2048; i++) { if ((int) (Math.random() * 2) == 1) { B.setBit(i); } } Dictionary instance = new Dictionary(B); for (int i = 0; i < 2048; i++) { assertEquals(B.getRank1(i), instance.getRank1(i)); } }
/** * Test method: ByteBuffer getByteBuffer() * * @throws Exception */ public void testGetByteBuffer() throws Exception { BitMap B = new BitMap(2048); for (int i = 0; i < 2048; i++) { if ((int) (Math.random() * 2) == 1) { B.setBit(i); } } ByteBuffer instance = new Dictionary(B).getByteBuffer(); assertNotNull(instance); } }
/** * Test method: long getVal(LongBuffer B, int i, int bits) * * @throws Exception */ public void testGetVal() throws Exception { BMArray bmArray = new BMArray(1000, 64); for (int i = 0; i < 1000; i++) { bmArray.setVal(i, i); } LongBuffer bBuf = bmArray.getLongBuffer(); for (int i = 0; i < 1000; i++) { assertEquals(BMArrayOps.getVal(bBuf, i, 64), i); } } }
/** * Constructor to convert a part of an integer array into a bitmap array. * * @param input Input integer array. * @param offset Beginning offset into input. * @param length Length of sub-array to convert. */ public BMArray(int[] input, int offset, int length) { super(((long) length) * ((long) CommonUtils.intLog2(length))); this.n = length; this.bits = CommonUtils.intLog2(this.n + 1); for (int i = offset; i < offset + length; i++) { this.setVal(i - offset, input[i]); } }
/** * 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); } }
/** * 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; }