@Test public void testMerge() { Entry[] entries = new Entry[] { makeEntry(COL_START, "valStart"), makeEntry("01col1", "val1"), makeEntry("02col2", "val2"), makeEntry("03col3", "val3"), makeEntry("04emptycol", ""), makeEntry(COL_END, "valEnd"), }; Entry[] adds = new Entry[] { makeEntry("03col3", "val3-2"), makeEntry("06col6", "val6"), makeEntry("19col19", "val19"), }; Entry[] dels = new Entry[] { makeEntry("01col1", "val1"), makeEntry("11col11", "val11"), }; List<BufferPage> mergedPages; int maxPageSize = 100; BufferPage bp = buildFromEntryArray(entries, entries.length); mergedPages = bp.merge(adds,0,adds.length, new Entry[]{}, 0, 0, maxPageSize); assertEquals(1, mergedPages.size()); assertEquals(entries.length + 2, mergedPages.get(0).numEntries()); mergedPages = bp.merge(new Entry[]{}, 0, 0, dels, 0, dels.length, maxPageSize); assertEquals(1, mergedPages.size()); assertEquals(entries.length - 1, mergedPages.get(0).numEntries()); mergedPages = bp.merge(adds,0,adds.length, dels, 0, dels.length, maxPageSize); assertEquals(1, mergedPages.size()); assertEquals(entries.length + 2 - 1, mergedPages.get(0).numEntries()); maxPageSize = 3; bp = buildFromEntryArray(entries, entries.length); mergedPages = bp.merge(adds,0,adds.length, new Entry[]{}, 0, 0, maxPageSize); assertEquals(3, mergedPages.size()); assertEquals(3, mergedPages.get(0).numEntries()); assertEquals(3, mergedPages.get(1).numEntries()); assertEquals(2, mergedPages.get(2).numEntries()); maxPageSize = 2; bp = buildFromEntryArray(entries, entries.length); mergedPages = bp.merge(adds,0,adds.length, new Entry[]{}, 0, 0, maxPageSize); assertEquals(4, mergedPages.size()); assertEquals(2, mergedPages.get(0).numEntries()); assertEquals(2, mergedPages.get(1).numEntries()); assertEquals(2, mergedPages.get(2).numEntries()); assertEquals(2, mergedPages.get(3).numEntries()); mergedPages = mergedPages.get(0).merge(new Entry[]{},0,0,new Entry[]{mergedPages.get(0).getNoCopy(0), mergedPages.get(0).getNoCopy(1)},0,2, maxPageSize); assertEquals(0, mergedPages.size()); maxPageSize = 2; bp = buildFromEntryArray(entries, entries.length); mergedPages = bp.merge(adds,0,adds.length-1, new Entry[]{}, 0, 0, maxPageSize); assertEquals(4, mergedPages.size()); assertEquals(2, mergedPages.get(0).numEntries()); assertEquals(2, mergedPages.get(1).numEntries()); assertEquals(2, mergedPages.get(2).numEntries()); assertEquals(1, mergedPages.get(3).numEntries()); }
public static List<BufferPage> merge(List<BufferPage> pagesToMerge, int maxPageSize) { if (pagesToMerge == null || pagesToMerge.size() < 1) { return pagesToMerge; } int totalCount = 0; for (BufferPage p : pagesToMerge) { totalCount += p.numEntries(); } Entry[] newdata = new Entry[totalCount]; totalCount = 0; for (BufferPage p : pagesToMerge) { for (int i = 0; i < p.numEntries(); i++) { newdata[totalCount++] = p.getNoCopy(i); } } int numNewPages = newdata.length / maxPageSize; if (newdata.length % maxPageSize > 0) { numNewPages++; } List<BufferPage> newPages = new ArrayList<>(numNewPages); for (int i = 0; i < numNewPages; i++) { newPages.add(BufferPageUtils.buildFromEntryArray(newdata, i * maxPageSize, Math.min(newdata.length, (i + 1) * maxPageSize))); } return newPages; }
BufferPage { public static List<BufferPage> merge(List<BufferPage> pagesToMerge, int maxPageSize) { if (pagesToMerge == null || pagesToMerge.size() < 1) { return pagesToMerge; } int totalCount = 0; for (BufferPage p : pagesToMerge) { totalCount += p.numEntries(); } Entry[] newdata = new Entry[totalCount]; totalCount = 0; for (BufferPage p : pagesToMerge) { for (int i = 0; i < p.numEntries(); i++) { newdata[totalCount++] = p.getNoCopy(i); } } int numNewPages = newdata.length / maxPageSize; if (newdata.length % maxPageSize > 0) { numNewPages++; } List<BufferPage> newPages = new ArrayList<>(numNewPages); for (int i = 0; i < numNewPages; i++) { newPages.add(BufferPageUtils.buildFromEntryArray(newdata, i * maxPageSize, Math.min(newdata.length, (i + 1) * maxPageSize))); } return newPages; } }
BufferPage { public static List<BufferPage> merge(List<BufferPage> pagesToMerge, int maxPageSize) { if (pagesToMerge == null || pagesToMerge.size() < 1) { return pagesToMerge; } int totalCount = 0; for (BufferPage p : pagesToMerge) { totalCount += p.numEntries(); } Entry[] newdata = new Entry[totalCount]; totalCount = 0; for (BufferPage p : pagesToMerge) { for (int i = 0; i < p.numEntries(); i++) { newdata[totalCount++] = p.getNoCopy(i); } } int numNewPages = newdata.length / maxPageSize; if (newdata.length % maxPageSize > 0) { numNewPages++; } List<BufferPage> newPages = new ArrayList<>(numNewPages); for (int i = 0; i < numNewPages; i++) { newPages.add(BufferPageUtils.buildFromEntryArray(newdata, i * maxPageSize, Math.min(newdata.length, (i + 1) * maxPageSize))); } return newPages; } BufferPage(final int[] indices, final byte[] data); }
BufferPage { public static List<BufferPage> merge(List<BufferPage> pagesToMerge, int maxPageSize) { if (pagesToMerge == null || pagesToMerge.size() < 1) { return pagesToMerge; } int totalCount = 0; for (BufferPage p : pagesToMerge) { totalCount += p.numEntries(); } Entry[] newdata = new Entry[totalCount]; totalCount = 0; for (BufferPage p : pagesToMerge) { for (int i = 0; i < p.numEntries(); i++) { newdata[totalCount++] = p.getNoCopy(i); } } int numNewPages = newdata.length / maxPageSize; if (newdata.length % maxPageSize > 0) { numNewPages++; } List<BufferPage> newPages = new ArrayList<>(numNewPages); for (int i = 0; i < numNewPages; i++) { newPages.add(BufferPageUtils.buildFromEntryArray(newdata, i * maxPageSize, Math.min(newdata.length, (i + 1) * maxPageSize))); } return newPages; } BufferPage(final int[] indices, final byte[] data); boolean isEmpty(); int getIndex(final StaticBuffer column); Entry get(final int index); Entry getNoCopy(final int index); int numEntries(); int byteSize(); static List<BufferPage> merge(List<BufferPage> pagesToMerge, int maxPageSize); List<BufferPage> merge(Entry[] add, int iaddp, int addLimit, Entry[] del, int idelp, int delLimit, int maxPageSize); }
BufferPage { public static List<BufferPage> merge(List<BufferPage> pagesToMerge, int maxPageSize) { if (pagesToMerge == null || pagesToMerge.size() < 1) { return pagesToMerge; } int totalCount = 0; for (BufferPage p : pagesToMerge) { totalCount += p.numEntries(); } Entry[] newdata = new Entry[totalCount]; totalCount = 0; for (BufferPage p : pagesToMerge) { for (int i = 0; i < p.numEntries(); i++) { newdata[totalCount++] = p.getNoCopy(i); } } int numNewPages = newdata.length / maxPageSize; if (newdata.length % maxPageSize > 0) { numNewPages++; } List<BufferPage> newPages = new ArrayList<>(numNewPages); for (int i = 0; i < numNewPages; i++) { newPages.add(BufferPageUtils.buildFromEntryArray(newdata, i * maxPageSize, Math.min(newdata.length, (i + 1) * maxPageSize))); } return newPages; } BufferPage(final int[] indices, final byte[] data); boolean isEmpty(); int getIndex(final StaticBuffer column); Entry get(final int index); Entry getNoCopy(final int index); int numEntries(); int byteSize(); static List<BufferPage> merge(List<BufferPage> pagesToMerge, int maxPageSize); List<BufferPage> merge(Entry[] add, int iaddp, int addLimit, Entry[] del, int idelp, int delLimit, int maxPageSize); static final int[] EMPTY_INDEX; static final byte[] EMPTY_DATA; }