/** * Remove the page. */ public void removePage() { if(isPersistent()) { long p = pos; if (p == 0) { removedInMemory = true; } map.removePage(p, memory); } }
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(); }
/** * Split the page. This modifies the current page. * * @param at the split index * @return the page with the entries after the split index */ Page split(int at) { Page page = isLeaf() ? splitLeaf(at) : splitNode(at); if(isPersistent()) { recalculateMemory(); } return page; }
int keyLength = keys.length; int keyIndex = index >= keyLength ? index - 1 : index; if(isPersistent()) { Object old = keys[keyIndex]; addMemory(-map.getKeyType().getMemory(old)); if(isPersistent()) { Object old = values[index]; addMemory(-map.getValueType().getMemory(old)); if(isPersistent()) { addMemory(-DataUtils.PAGE_MEMORY_CHILD);
/** * Replace the value at an index in this page. * * @param index the index * @param value the new value * @return the old value */ public Object setValue(int index, Object value) { Object old = values[index]; // this is slightly slower: // values = Arrays.copyOf(values, values.length); values = values.clone(); DataType valueType = map.getValueType(); if(isPersistent()) { addMemory(valueType.getMemory(value) - valueType.getMemory(old)); } values[index] = value; return old; }
/** * Replace the key at an index in this page. * * @param index the index * @param key the new key */ public void setKey(int index, Object key) { // this is slightly slower: // keys = Arrays.copyOf(keys, keys.length); keys = keys.clone(); if(isPersistent()) { Object old = keys[index]; DataType keyType = map.getKeyType(); int mem = keyType.getMemory(key); if (old != null) { mem -= keyType.getMemory(old); } addMemory(mem); } keys[index] = key; }
/** * Insert a key-value pair into this leaf. * * @param index the index * @param key the key * @param value the value */ public void insertLeaf(int index, Object key, Object value) { int len = keys.length + 1; Object[] newKeys = new Object[len]; DataUtils.copyWithGap(keys, newKeys, len - 1, index); keys = newKeys; Object[] newValues = new Object[len]; DataUtils.copyWithGap(values, newValues, len - 1, index); values = newValues; keys[index] = key; values[index] = value; totalCount++; if(isPersistent()) { addMemory(map.getKeyType().getMemory(key) + map.getValueType().getMemory(value)); } }
/** * Insert a child page into this node. * * @param index the index * @param key the key * @param childPage the child page */ public void insertNode(int index, Object key, Page childPage) { Object[] newKeys = new Object[keys.length + 1]; DataUtils.copyWithGap(keys, newKeys, keys.length, index); newKeys[index] = key; keys = newKeys; int childCount = children.length; PageReference[] newChildren = new PageReference[childCount + 1]; DataUtils.copyWithGap(children, newChildren, childCount, index); newChildren[index] = new PageReference( childPage, childPage.getPos(), childPage.totalCount); children = newChildren; totalCount += childPage.totalCount; if(isPersistent()) { addMemory(map.getKeyType().getMemory(key) + DataUtils.PAGE_MEMORY_CHILD); } }
/** * Remove the page. */ public void removePage() { if(isPersistent()) { long p = pos; if (p == 0) { removedInMemory = true; } map.removePage(p, memory); } }
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(); }
/** * Split the page. This modifies the current page. * * @param at the split index * @return the page with the entries after the split index */ Page split(int at) { Page page = isLeaf() ? splitLeaf(at) : splitNode(at); if(isPersistent()) { recalculateMemory(); } return page; }
int keyLength = keys.length; int keyIndex = index >= keyLength ? index - 1 : index; if(isPersistent()) { Object old = keys[keyIndex]; addMemory(-map.getKeyType().getMemory(old)); if(isPersistent()) { Object old = values[index]; addMemory(-map.getValueType().getMemory(old)); if(isPersistent()) { addMemory(-DataUtils.PAGE_MEMORY_CHILD);
/** * Replace the key at an index in this page. * * @param index the index * @param key the new key */ public void setKey(int index, Object key) { // this is slightly slower: // keys = Arrays.copyOf(keys, keys.length); keys = keys.clone(); if(isPersistent()) { Object old = keys[index]; DataType keyType = map.getKeyType(); int mem = keyType.getMemory(key); if (old != null) { mem -= keyType.getMemory(old); } addMemory(mem); } keys[index] = key; }
/** * Replace the value at an index in this page. * * @param index the index * @param value the new value * @return the old value */ public Object setValue(int index, Object value) { Object old = values[index]; // this is slightly slower: // values = Arrays.copyOf(values, values.length); values = values.clone(); DataType valueType = map.getValueType(); if(isPersistent()) { addMemory(valueType.getMemory(value) - valueType.getMemory(old)); } values[index] = value; return old; }
/** * Insert a key-value pair into this leaf. * * @param index the index * @param key the key * @param value the value */ public void insertLeaf(int index, Object key, Object value) { int len = keys.length + 1; Object[] newKeys = new Object[len]; DataUtils.copyWithGap(keys, newKeys, len - 1, index); keys = newKeys; Object[] newValues = new Object[len]; DataUtils.copyWithGap(values, newValues, len - 1, index); values = newValues; keys[index] = key; values[index] = value; totalCount++; if(isPersistent()) { addMemory(map.getKeyType().getMemory(key) + map.getValueType().getMemory(value)); } }
/** * Insert a child page into this node. * * @param index the index * @param key the key * @param childPage the child page */ public void insertNode(int index, Object key, Page childPage) { Object[] newKeys = new Object[keys.length + 1]; DataUtils.copyWithGap(keys, newKeys, keys.length, index); newKeys[index] = key; keys = newKeys; int childCount = children.length; PageReference[] newChildren = new PageReference[childCount + 1]; DataUtils.copyWithGap(children, newChildren, childCount, index); newChildren[index] = new PageReference( childPage, childPage.getPos(), childPage.totalCount); children = newChildren; totalCount += childPage.totalCount; if(isPersistent()) { addMemory(map.getKeyType().getMemory(key) + DataUtils.PAGE_MEMORY_CHILD); } }