/** * Get a value by its position in the map. Used for optimizing certain operations. * @param i The index. * @return The value at position {@code i}. */ public double getValueByIndex(int i) { return values[i + keys.getLowerBound()]; }
@Override public Entry first() { if (isEmpty()) { throw new NoSuchElementException(); } return entry(keys.getLowerBound()); }
/** * Get a key by its position in the map. Used for optimizing certain operations. * @param i The index. * @return The key at position {@code i}. */ public long getKeyByIndex(int i) { return keys.getKey(i + keys.getLowerBound()); }
@Override public long firstLong() { if (keys.size() > 0) { return keys.getKey(keys.getLowerBound()); } else { throw new NoSuchElementException(); } }
@Override public Long2DoubleSortedMap headMap(long l) { int endIdx = keys.findLowerBound(l); // lower bound so we don't include 'l' return createSubMap(keys.getLowerBound(), endIdx); }
public EntryIter() { iter = IntIterators.fromTo(keys.getLowerBound(), keys.getUpperBound()); }
@Override public LongSortedSet headSet(long key) { int start = keys.getLowerBound(); int end = keys.findLowerBound(key); return new LongSortedArraySet(keys.subIndex(start, end)); }
@Override public long getLong(int i) { Preconditions.checkElementIndex(i, SortedKeyIndex.this.size()); return getKey(getLowerBound() + i); } }
long[] nks = new long[Math.min(tn, on)]; double[] nvs = new double[Math.min(tn, on)]; int tlb = keys.getLowerBound(); int olb = oks.getLowerBound(); int ni = 0;
/** * Get a value by its position in the map. Used for optimizing certain operations. * @param i The index. * @return The value at position {@code i}. */ public double getValueByIndex(int i) { return values[i + keys.getLowerBound()]; }
private Long2DoubleSortedArrayMap slowSubMap(LongSet toKeep) { LongSortedSet kept = LongUtils.setIntersect(keySet(), toKeep); double[] nvs = new double[kept.size()]; int i = keys.getLowerBound(); int j = 0; LongIterator iter = kept.iterator(); while (iter.hasNext()) { long key = iter.nextLong(); while (keys.getKey(i) < key) { i++; } nvs[j] = values[i]; j++; i++; } return wrap(SortedKeyIndex.fromCollection(kept), nvs); }
@Test public void testSubViewLowerBound() { SortedKeyIndex keys = SortedKeyIndex.create(0, 1, 2, 3, 4, 5, 6, 7); SortedKeyIndex subk = keys.subIndex(1, 5); assertThat(subk.getLowerBound(), equalTo(1)); assertThat(subk.getUpperBound(), equalTo(5)); assertThat(subk.tryGetIndex(1), equalTo(1)); assertThat(subk.tryGetIndex(4), equalTo(4)); assertThat(subk.tryGetIndex(5), lessThan(0)); assertThat(subk.tryGetIndex(6), lessThan(0)); assertThat(subk.tryGetIndex(0), lessThan(0)); assertThat(subk.findLowerBound(1L), equalTo(1)); assertThat(subk.findLowerBound(0L), equalTo(1)); assertThat(subk.findLowerBound(2L), equalTo(2)); assertThat(subk.findLowerBound(7L), equalTo(5)); assertThat(subk.findUpperBound(1), equalTo(2)); assertThat(subk.findUpperBound(5), equalTo(5)); assertThat(subk.findUpperBound(4), equalTo(5)); } }
/** * Get a key by its position in the map. Used for optimizing certain operations. * @param i The index. * @return The key at position {@code i}. */ public long getKeyByIndex(int i) { return keys.getKey(i + keys.getLowerBound()); }
@Override public Entry first() { if (isEmpty()) { throw new NoSuchElementException(); } return entry(keys.getLowerBound()); }
@Override public long firstLong() { if (keys.size() > 0) { return keys.getKey(keys.getLowerBound()); } else { throw new NoSuchElementException(); } }
@Override public Long2DoubleSortedMap headMap(long l) { int endIdx = keys.findLowerBound(l); // lower bound so we don't include 'l' return createSubMap(keys.getLowerBound(), endIdx); }
public EntryIter() { iter = IntIterators.fromTo(keys.getLowerBound(), keys.getUpperBound()); }
@Override public long getLong(int i) { Preconditions.checkElementIndex(i, SortedKeyIndex.this.size()); return getKey(getLowerBound() + i); } }
@Override public LongSortedSet headSet(long key) { int start = keys.getLowerBound(); int end = keys.findLowerBound(key); return new LongSortedArraySet(keys.subIndex(start, end)); }
private Long2DoubleSortedArrayMap slowSubMap(LongSet toKeep) { LongSortedSet kept = LongUtils.setIntersect(keySet(), toKeep); double[] nvs = new double[kept.size()]; int i = keys.getLowerBound(); int j = 0; LongIterator iter = kept.iterator(); while (iter.hasNext()) { long key = iter.nextLong(); while (keys.getKey(i) < key) { i++; } nvs[j] = values[i]; j++; i++; } return wrap(SortedKeyIndex.fromCollection(kept), nvs); }