Пример #1
0
  @Override
  public Iterable<T> getIntersectingElements(long start, long end) {
    Iterable<T> matchStarts =
        Iterables.concat(fStartTimesIndex.asMap().headMap(end, true).values());
    Iterable<T> matchEnds = Iterables.concat(fEndTimesIndex.asMap().tailMap(start, true).values());

    return checkNotNull(
        Sets.intersection(Sets.newHashSet(matchStarts), Sets.newHashSet(matchEnds)));
  }
Пример #2
0
  @Override
  public Iterable<T> getIntersectingElements(long position) {
    /*
     * The intervals intersecting 't' are those whose 1) start time is
     * *lower* than 't' AND 2) end time is *higher* than 't'.
     */
    Iterable<T> matchStarts =
        Iterables.concat(fStartTimesIndex.asMap().headMap(position, true).values());
    Iterable<T> matchEnds =
        Iterables.concat(fEndTimesIndex.asMap().tailMap(position, true).values());

    return checkNotNull(
        Sets.intersection(Sets.newHashSet(matchStarts), Sets.newHashSet(matchEnds)));
  }
  @Test
  public void buildInt() throws IOException {
    final TreeMultimap<Integer, Integer> elements = TreeMultimap.create();
    for (int i = 0; i < DOCS; i++) {
      elements.put(i / 2, i);
    }
    final com.yandex.yoctodb.util.mutable.IndexToIndexMultiMap mutable =
        new com.yandex.yoctodb.util.mutable.impl.IntIndexToIndexMultiMap(elements.asMap().values());

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    mutable.writeTo(baos);

    final Buffer buf = Buffer.from(baos.toByteArray());

    final IndexToIndexMultiMap result = IndexToIndexMultiMapReader.from(buf);

    assertTrue(result instanceof IntIndexToIndexMultiMap);
  }