@Test public void testListToMapNeedsPadding(){ int[] list = new int[]{0,0,1,0,0,0,1,1,0,1,1,0,1,0,1}; int[] words = BitmapBuilder.listToMap(list); assertEquals(2,words.length); assertEquals(35,words[0]); assertEquals(106,words[1]); }
public static int[] listToMap(int[] list) { list = pad(list); int[] bitMap = new int[(int)(list.length / WORD_LENGTH)]; Arrays.fill(bitMap, 0); int j = -1; for (int i = 0; i < list.length; i++) { if (i % WORD_LENGTH == 0) { j++; } bitMap[j] |= (list[i] << ((WORD_LENGTH - 1) - (i % WORD_LENGTH))); } return bitMap; }
BitmapBuilder { public static int[] listToMap(int[] list) { list = pad(list); int[] bitMap = new int[(int)(list.length / WORD_LENGTH)]; Arrays.fill(bitMap, 0); int j = -1; for (int i = 0; i < list.length; i++) { if (i % WORD_LENGTH == 0) { j++; } bitMap[j] |= (list[i] << ((WORD_LENGTH - 1) - (i % WORD_LENGTH))); } return bitMap; } }
BitmapBuilder { public static int[] listToMap(int[] list) { list = pad(list); int[] bitMap = new int[(int)(list.length / WORD_LENGTH)]; Arrays.fill(bitMap, 0); int j = -1; for (int i = 0; i < list.length; i++) { if (i % WORD_LENGTH == 0) { j++; } bitMap[j] |= (list[i] << ((WORD_LENGTH - 1) - (i % WORD_LENGTH))); } return bitMap; }  }
BitmapBuilder { public static int[] listToMap(int[] list) { list = pad(list); int[] bitMap = new int[(int)(list.length / WORD_LENGTH)]; Arrays.fill(bitMap, 0); int j = -1; for (int i = 0; i < list.length; i++) { if (i % WORD_LENGTH == 0) { j++; } bitMap[j] |= (list[i] << ((WORD_LENGTH - 1) - (i % WORD_LENGTH))); } return bitMap; }  static int[] listToMap(int[] list); static int[] mapToList(int[] bitMap); }
BitmapBuilder { public static int[] listToMap(int[] list) { list = pad(list); int[] bitMap = new int[(int)(list.length / WORD_LENGTH)]; Arrays.fill(bitMap, 0); int j = -1; for (int i = 0; i < list.length; i++) { if (i % WORD_LENGTH == 0) { j++; } bitMap[j] |= (list[i] << ((WORD_LENGTH - 1) - (i % WORD_LENGTH))); } return bitMap; }  static int[] listToMap(int[] list); static int[] mapToList(int[] bitMap); static final int WORD_LENGTH; }