@Nonnull @Override public ResultMap scoreWithDetails(long user, @Nonnull Collection<Long> items) { ResultMap results = primaryScorer.scoreWithDetails(user, items); List<Result> allResults = new ArrayList<>(items.size()); LongList toFetch = new LongArrayList(items.size() - results.size()); LongIterator iter = LongIterators.asLongIterator(items.iterator()); while (iter.hasNext()) { final long item = iter.nextLong(); Result r = results.get(item); if (r == null) { toFetch.add(item); } else { allResults.add(new FallbackResult(r, true)); } } if (!toFetch.isEmpty()) { for (Result r: baselineScorer.scoreWithDetails(user, toFetch)) { allResults.add(new FallbackResult(r, false)); } } return new BasicResultMap(allResults); }
@Test public void testEmpty() { LongList out = accum.finishList(); assertTrue(out.isEmpty()); }
@Test public void testEmptyList() { LongList list = new CompactableLongArrayList(); assertThat(list.size(), equalTo(0)); assertThat(list.isEmpty(), equalTo(true)); }
@Test public void testEmpty() { LongList out = accum.finishList(); assertTrue(out.isEmpty()); }
@Test public void testSingletonNegativeLong() { LongList list = new CompactableLongArrayList(); long val = Integer.MIN_VALUE - 42L; list.add(val); assertThat(list.size(), equalTo(1)); assertThat(list.isEmpty(), equalTo(false)); assertThat(list, contains(val)); }
@Test public void testSingleton() { LongList list = new CompactableLongArrayList(); list.add(42L); assertThat(list.size(), equalTo(1)); assertThat(list.isEmpty(), equalTo(false)); assertThat(list, contains(42L)); }
@Test public void testSingletonLong() { LongList list = new CompactableLongArrayList(); long val = Integer.MAX_VALUE + 42L; list.add(val); assertThat(list.size(), equalTo(1)); assertThat(list.isEmpty(), equalTo(false)); assertThat(list, contains(val)); }
@Override public boolean isEmpty() { return list.isEmpty(); } @Override
public boolean isEmpty() { return invalid.isEmpty(); }
/** Creates a new select structure using a {@linkplain LongList list} of longs. * * @param list the list of the positions of ones. */ public SparseSelect(final LongList list) { super(list); this.n = list.isEmpty() ? 0 : list.getLong(list.size() - 1) + 1; fromRank = false; }
/** * Finds the largest event file position recorded in the index that is smaller than or equal to a given offset. * * @param offset an arbitrary file offset. * @return largest event file position that is smaller than or equal to the given offset. * */ long floorPosition(long offset) { if (positions.isEmpty()) { return 0L; } int idx = binarySearch(positions, offset); if (idx >= 0) { return offset; } return idx == -1 ? 0 : positions.getLong(-idx - 2); }
/** * Finds the largest event file position recorded in the index that has timestamp smaller than or equal to the given * timestamp. * * @param timestamp Stream event timestamp to search for. * @return The file position or {@code -1} if no record satisfied the requirement can be found. */ long floorPositionByTime(long timestamp) { if (timestamps.isEmpty()) { return -1; } // Binary search for a timestamp that is larger than or equals to the given timestamp. int idx = binarySearch(timestamps, timestamp); if (idx >= 0) { return positions.getLong(idx); } // Return the position that has smaller timestamp than the one to search for. // If every timestamp in the index is larger than the given one, return -1. return idx == -1 ? -1 : positions.getLong(-idx - 2); }
@Nonnull @Override public ResultMap scoreWithDetails(long user, @Nonnull Collection<Long> items) { ResultMap results = primaryScorer.scoreWithDetails(user, items); List<Result> allResults = new ArrayList<>(items.size()); LongList toFetch = new LongArrayList(items.size() - results.size()); LongIterator iter = LongIterators.asLongIterator(items.iterator()); while (iter.hasNext()) { final long item = iter.nextLong(); Result r = results.get(item); if (r == null) { toFetch.add(item); } else { allResults.add(new FallbackResult(r, true)); } } if (!toFetch.isEmpty()) { for (Result r: baselineScorer.scoreWithDetails(user, toFetch)) { allResults.add(new FallbackResult(r, false)); } } return new BasicResultMap(allResults); }