@Override public boolean isEmpty() { // could also use (sizeAsLong() == 0) return root.isLeaf() && root.getKeyCount() == 0; }
public int getMemory() { if (isPersistent()) { if (MVStore.ASSERT) { int mem = memory; recalculateMemory(); if (mem != memory) { throw DataUtils.newIllegalStateException( DataUtils.ERROR_INTERNAL, "Memory calculation error"); } } return memory; } return getKeyCount(); }
/** * Add all node keys (including internal bounds) to the given list. * This is mainly used to visualize the internal splits. * * @param list the list * @param p the root page */ public void addNodeKeys(ArrayList<SpatialKey> list, Page p) { if (p != null && !p.isLeaf()) { for (int i = 0; i < p.getKeyCount(); i++) { list.add((SpatialKey) p.getKey(i)); addNodeKeys(list, p.getChildPage(i)); } } }
private Object getBounds(Page x) { Object bounds = keyType.createBoundingBox(x.getKey(0)); for (int i = 1; i < x.getKeyCount(); i++) { keyType.increaseBounds(bounds, x.getKey(i)); } return bounds; }
/** * Get the object for the given key. An exact match is required. * * @param p the page * @param key the key * @return the value, or null if not found */ protected Object get(Page p, Object key) { if (!p.isLeaf()) { for (int i = 0; i < p.getKeyCount(); i++) { if (contains(p, i, key)) { Object o = get(p.getChildPage(i), key); if (o != null) { return o; } } } } else { for (int i = 0; i < p.getKeyCount(); i++) { if (keyType.equals(p.getKey(i), key)) { return p.getValue(i); } } } return null; }
Page p = pos.page; if (p.isLeaf()) { while (pos.index < p.getKeyCount()) { SpatialKey c = (SpatialKey) p.getKey(pos.index++); if (filter == null || check(true, c, filter)) { while (pos.index < p.getKeyCount()) { int index = pos.index++; SpatialKey c = (SpatialKey) p.getKey(index);
/** * Get the first (lowest) or last (largest) key. * * @param first whether to retrieve the first key * @return the key, or null if the map is empty */ @SuppressWarnings("unchecked") protected K getFirstLast(boolean first) { if (size() == 0) { return null; } Page p = root; while (true) { if (p.isLeaf()) { return (K) p.getKey(first ? 0 : p.getKeyCount() - 1); } p = p.getChildPage(first ? 0 : getChildPageCount(p) - 1); } }
/** * Fetch the next entry if there is one. */ @SuppressWarnings("unchecked") private void fetchNext() { while (pos != null) { if (pos.index < pos.page.getKeyCount()) { int index = pos.index++; current = (K) pos.page.getKey(index); currentValue = (V) pos.page.getValue(index); return; } pos = pos.parent; if (pos == null) { break; } if (pos.index < map.getChildPageCount(pos.page)) { min(pos.page.getChildPage(pos.index++), null); } } current = null; }
float largest = Float.MIN_VALUE; int ia = 0, ib = 0; for (int a = 0; a < p.getKeyCount(); a++) { Object objA = p.getKey(a); for (int b = 0; b < p.getKeyCount(); b++) { if (a == b) { continue; Object boundsA = keyType.createBoundingBox(splitA.getKey(0)); Object boundsB = keyType.createBoundingBox(splitB.getKey(0)); while (p.getKeyCount() > 0) { float diff = 0, bestA = 0, bestB = 0; int best = 0; for (int i = 0; i < p.getKeyCount(); i++) { Object o = p.getKey(i); float incA = keyType.getAreaIncrease(boundsA, o); while (splitB.getKeyCount() > 0) { move(splitB, p, 0);
/** * Split the root page if necessary. * * @param p the page * @param writeVersion the write version * @return the new sibling */ protected Page splitRootIfNeeded(Page p, long writeVersion) { if (p.getMemory() <= store.getPageSplitSize() || p.getKeyCount() <= 1) { return p; } int at = p.getKeyCount() / 2; long totalCount = p.getTotalCount(); Object k = p.getKey(at); Page split = p.split(at); Object[] keys = { k }; Page.PageReference[] children = { new Page.PageReference(p, p.getPos(), p.getTotalCount()), new Page.PageReference(split, split.getPos(), split.getTotalCount()), }; p = Page.create(this, writeVersion, keys, null, children, totalCount, 0); return p; }
for (int i = 0; i < p.getKeyCount(); i++) { if (keyType.equals(p.getKey(i), key)) { p.setKey(i, key); for (int i = 0; i < p.getKeyCount(); i++) { if (contains(p, i, key)) { Page c = p.getChildPage(i);
private void add(Page p, long writeVersion, Object key, Object value) { if (p.isLeaf()) { p.insertLeaf(p.getKeyCount(), key, value); return; for (int i = 0; i < p.getKeyCount(); i++) { if (contains(p, i, key)) { index = i; for (int i = 0; i < p.getKeyCount(); i++) { Object k = p.getKey(i); float areaIncrease = keyType.getAreaIncrease(k, key); if (c.getMemory() > store.getPageSplitSize() && c.getKeyCount() > 4) {
while (true) { if (p.isLeaf()) { if (index >= offset + p.getKeyCount()) { return null;
private Page splitLinear(Page p, long writeVersion) { ArrayList<Object> keys = New.arrayList(); for (int i = 0; i < p.getKeyCount(); i++) { keys.add(p.getKey(i)); Object boundsA = keyType.createBoundingBox(splitA.getKey(0)); Object boundsB = keyType.createBoundingBox(splitB.getKey(0)); while (p.getKeyCount() > 0) { Object o = p.getKey(0); float a = keyType.getAreaIncrease(boundsA, o); while (splitB.getKeyCount() > 0) { move(splitB, p, 0);
x += min ? -1 : 1; if (x < 0 || x >= p.getKeyCount()) { return null;
Object result = null; if (p.isLeaf()) { for (int i = 0; i < p.getKeyCount(); i++) { if (keyType.equals(p.getKey(i), key)) { result = p.getValue(i); for (int i = 0; i < p.getKeyCount(); i++) { if (contains(p, i, key)) { Page cOld = p.getChildPage(i); if (p.getKeyCount() == 0) { c.removePage();
if (c.getMemory() > store.getPageSplitSize() && c.getKeyCount() > 1) { int at = c.getKeyCount() / 2; Object k = c.getKey(at); Page split = c.split(at);
return 0; if (p.getKeyCount() > 0) { @SuppressWarnings("unchecked") K key = (K) p.getKey(0);
} else { if (p.getKeyCount() == 0) { p.setChild(index, c); c.removePage();
if (alwaysAdd || get(key) == null) { if (p.getMemory() > store.getPageSplitSize() && p.getKeyCount() > 3) {