/** * Remove a key-value pair. * * @param p the page (may not be null) * @param writeVersion the write version * @param key the key * @return the old value, or null if the key did not exist */ protected Object remove(Page p, long writeVersion, Object key) { int index = p.binarySearch(key); Object result = null; if (p.isLeaf()) { if (index >= 0) { result = p.getValue(index); p.remove(index); if (p.getKeyCount() == 0) { removePage(p.getPos()); } } return result; } // node if (index < 0) { index = -index - 1; } else { index++; } Page cOld = p.getChildPage(index); Page c = copyOnWrite(cOld, writeVersion); result = remove(c, writeVersion, key); if (result == null) { return null; } if (c.getTotalCount() == 0) { // this child was deleted if (p.getKeyCount() == 0) { p.setChild(index, c); p.setCounts(index, c); removePage(p.getPos()); } else { p.remove(index); } } else { p.setChild(index, c); p.setCounts(index, c); } return result; }