@SuppressWarnings("unchecked") @Override public Map.Entry<K, V> next() { if ((index + 1) < leaf.size()) { index++; Entry entry = leaf.get(index); return entry; } else if (leaf.next() != null) { leaf = leaf.next(); index = 0; Entry entry = leaf.get(index); return entry; } throw new NoSuchElementException(); }
public void mergeFrom(Node right) { assert (right.size() == capacity / 2) || (size == capacity / 2) : "Should have exactly half capacity nodes"; Leaf leaf = (Leaf) right; shallowCopy(leaf, 0, this, size, leaf.size()); next = leaf.next(); size += leaf.size(); }
public Object put(Comparator comparator, Object key, Object val) { Object oldVal; int search = binarySearch(this, 0, size, key, comparator); if (search > -1) { Entry entry = get(search); oldVal = entry.getValue(); entry.setValue(val); } else if (size < capacity) { oldVal = null; search = -(search + 1); insert(search, key, val); } else { Leaf next = Leaf.newInstance(capacity); int halfSize = size / 2; shallowCopy(this, halfSize, next, 0, halfSize); clear(halfSize, size); size = halfSize; next.size = halfSize; if (compare(comparator, key, next.firstKey()) < 0) { put(comparator, key, val); } else { next.put(comparator, key, val); } next.next = this.next; this.next = next; oldVal = Node.Sentinal.SPLIT; } return oldVal; }
@Override public boolean hasNext() { return (index + 1) < leaf.size() || leaf.next() != null; }