@Override protected BTreeSearchIterator<V, V> slice(Dir dir) { return new BTreeSearchIterator<>(tree, comparator, dir, lowerBound, upperBound); }
public int indexOfCurrent() { checkOnItem(); return compareToFirst(index); } }
public V next() { switch (state) { case ON_ITEM: if (compareToLast(index = moveOne(forwards)) >= 0) state = END; break; case BEFORE_FIRST: seekTo(index = forwards ? lowerBound : upperBound); state = (byte) (upperBound == lowerBound ? LAST : MIDDLE); case LAST: case MIDDLE: state |= ON_ITEM; break; default: throw new NoSuchElementException(); } return current(); }
public V current() { checkOnItem(); return (V) currentValue(); }
public V next(K target) { if (!hasNext()) return null; int state = this.state; boolean found = seekTo(target, forwards, (state & (ON_ITEM | BEFORE_FIRST)) != 0); int index = cur.globalIndex(); V next = null; if (state == BEFORE_FIRST && compareToFirst(index) < 0) return null; int compareToLast = compareToLast(index); if ((compareToLast <= 0)) { state = compareToLast < 0 ? MIDDLE : LAST; if (found) { state |= ON_ITEM; next = (V) currentValue(); } } else state = END; this.state = (byte) state; this.index = index; return next; }
private static long encodeBitmap(Collection<ColumnDefinition> columns, Columns superset, int supersetCount) { long bitmap = 0L; BTreeSearchIterator<ColumnDefinition, ColumnDefinition> iter = superset.iterator(); // the index we would encounter next if all columns are present int expectIndex = 0; for (ColumnDefinition column : columns) { if (iter.next(column) == null) throw new IllegalStateException(columns + " is not a subset of " + superset); int currentIndex = iter.indexOfCurrent(); int count = currentIndex - expectIndex; // (1L << count) - 1 gives us count bits set at the bottom of the register // so << expectIndex moves these bits to start at expectIndex, which is where our missing portion // begins (assuming count > 0; if not, we're adding 0 bits, so it's a no-op) bitmap |= ((1L << count) - 1) << expectIndex; expectIndex = currentIndex + 1; } int count = supersetCount - expectIndex; bitmap |= ((1L << count) - 1) << expectIndex; return bitmap; }
/** * Whether this object is a superset of the provided other {@code Columns object}. * * @param other the other object to test for inclusion in this object. * * @return whether all the columns of {@code other} are contained by this object. */ public boolean containsAll(Collection<?> other) { if (other == this) return true; if (other.size() > this.size()) return false; BTreeSearchIterator<ColumnDefinition, ColumnDefinition> iter = BTree.slice(columns, Comparator.naturalOrder(), BTree.Dir.ASC); for (Object def : other) if (iter.next((ColumnDefinition) def) == null) return false; return true; }
public V next(K target) { if (!hasNext()) return null; int state = this.state; boolean found = seekTo(target, forwards, (state & (ON_ITEM | BEFORE_FIRST)) != 0); int index = cur.globalIndex(); V next = null; if (state == BEFORE_FIRST && compareToFirst(index) < 0) return null; int compareToLast = compareToLast(index); if ((compareToLast <= 0)) { state = compareToLast < 0 ? MIDDLE : LAST; if (found) { state |= ON_ITEM; next = (V) currentValue(); } } else state = END; this.state = (byte) state; this.index = index; return next; }
private static long encodeBitmap(Collection<ColumnDefinition> columns, Columns superset, int supersetCount) { long bitmap = 0L; BTreeSearchIterator<ColumnDefinition, ColumnDefinition> iter = superset.iterator(); // the index we would encounter next if all columns are present int expectIndex = 0; for (ColumnDefinition column : columns) { if (iter.next(column) == null) throw new IllegalStateException(columns + " is not a subset of " + superset); int currentIndex = iter.indexOfCurrent(); int count = currentIndex - expectIndex; // (1L << count) - 1 gives us count bits set at the bottom of the register // so << expectIndex moves these bits to start at expectIndex, which is where our missing portion // begins (assuming count > 0; if not, we're adding 0 bits, so it's a no-op) bitmap |= ((1L << count) - 1) << expectIndex; expectIndex = currentIndex + 1; } int count = supersetCount - expectIndex; bitmap |= ((1L << count) - 1) << expectIndex; return bitmap; }
public V current() { checkOnItem(); return (V) currentValue(); }
/** * Whether this object is a superset of the provided other {@code Columns object}. * * @param other the other object to test for inclusion in this object. * * @return whether all the columns of {@code other} are contained by this object. */ public boolean containsAll(Collection<?> other) { if (other == this) return true; if (other.size() > this.size()) return false; BTreeSearchIterator<ColumnDefinition, ColumnDefinition> iter = BTree.slice(columns, Comparator.naturalOrder(), BTree.Dir.ASC); for (Object def : other) if (iter.next((ColumnDefinition) def) == null) return false; return true; }
public V next(K target) { if (!hasNext()) return null; int state = this.state; boolean found = seekTo(target, forwards, (state & (ON_ITEM | BEFORE_FIRST)) != 0); int index = cur.globalIndex(); V next = null; if (state == BEFORE_FIRST && compareToFirst(index) < 0) return null; int compareToLast = compareToLast(index); if ((compareToLast <= 0)) { state = compareToLast < 0 ? MIDDLE : LAST; if (found) { state |= ON_ITEM; next = (V) currentValue(); } } else state = END; this.state = (byte) state; this.index = index; return next; }
public V next() { switch (state) { case ON_ITEM: if (compareToLast(index = moveOne(forwards)) >= 0) state = END; break; case BEFORE_FIRST: seekTo(index = forwards ? lowerBound : upperBound); state = (byte) (upperBound == lowerBound ? LAST : MIDDLE); case LAST: case MIDDLE: state |= ON_ITEM; break; default: throw new NoSuchElementException(); } return current(); }
private static long encodeBitmap(Collection<ColumnDefinition> columns, Columns superset, int supersetCount) { long bitmap = 0L; BTreeSearchIterator<ColumnDefinition, ColumnDefinition> iter = superset.iterator(); // the index we would encounter next if all columns are present int expectIndex = 0; for (ColumnDefinition column : columns) { if (iter.next(column) == null) throw new IllegalStateException(columns + " is not a subset of " + superset); int currentIndex = iter.indexOfCurrent(); int count = currentIndex - expectIndex; // (1L << count) - 1 gives us count bits set at the bottom of the register // so << expectIndex moves these bits to start at expectIndex, which is where our missing portion // begins (assuming count > 0; if not, we're adding 0 bits, so it's a no-op) bitmap |= ((1L << count) - 1) << expectIndex; expectIndex = currentIndex + 1; } int count = supersetCount - expectIndex; bitmap |= ((1L << count) - 1) << expectIndex; return bitmap; }
/** * Returns an Iterator over the entire tree * * @param btree the tree to iterate over * @param dir direction of iteration * @param <V> * @return */ public static <K, V> BTreeSearchIterator<K, V> slice(Object[] btree, Comparator<? super K> comparator, Dir dir) { return new BTreeSearchIterator<>(btree, comparator, dir); }
public int indexOfCurrent() { checkOnItem(); return compareToFirst(index); } }
public V current() { checkOnItem(); return (V) currentValue(); }
/** * Whether this object is a superset of the provided other {@code Columns object}. * * @param other the other object to test for inclusion in this object. * * @return whether all the columns of {@code other} are contained by this object. */ public boolean containsAll(Collection<?> other) { if (other == this) return true; if (other.size() > this.size()) return false; BTreeSearchIterator<ColumnDefinition, ColumnDefinition> iter = BTree.slice(columns, Comparator.naturalOrder(), BTree.Dir.ASC); for (Object def : other) if (iter.next((ColumnDefinition) def) == null) return false; return true; }
public V next(K target) { if (!hasNext()) return null; int state = this.state; boolean found = seekTo(target, forwards, (state & (ON_ITEM | BEFORE_FIRST)) != 0); int index = cur.globalIndex(); V next = null; if (state == BEFORE_FIRST && compareToFirst(index) < 0) return null; int compareToLast = compareToLast(index); if ((compareToLast <= 0)) { state = compareToLast < 0 ? MIDDLE : LAST; if (found) { state |= ON_ITEM; next = (V) currentValue(); } } else state = END; this.state = (byte) state; this.index = index; return next; }
public V next() { switch (state) { case ON_ITEM: if (compareToLast(index = moveOne(forwards)) >= 0) state = END; break; case BEFORE_FIRST: seekTo(index = forwards ? lowerBound : upperBound); state = (byte) (upperBound == lowerBound ? LAST : MIDDLE); case LAST: case MIDDLE: state |= ON_ITEM; break; default: throw new NoSuchElementException(); } return current(); }