/** An alias for {@link #length()}. * @return the interval length. */ public long size64() { return length(); }
@Override public LongSortedSet headSet(final long to) { if (this == EMPTY_INTERVAL) return this; if (to > left) return to > right ? this : valueOf(left, to - 1); else return EMPTY_INTERVAL; }
/** Returns an interval with given extremes. * * <P>You cannot obtain an empty interval with this factory method. Use {@link Intervals#EMPTY_INTERVAL} instead. * * @param left the left extreme. * @param right the right extreme (which must be greater than * or equal to the left extreme). * @return an interval with the given extremes. */ public static LongInterval valueOf(final long left, final long right) { if (left > right) throw new IllegalArgumentException("The left extreme (" + left + ") is greater than the right extreme (" + right + ")"); if (left == right) return valueOf(left); return new LongInterval(left, right); }
else if (o instanceof LongSortedSet) { // For sorted sets, we require the same order LongSortedSet s = (LongSortedSet) o; if (s.size() != length()) return false; long n = length(); LongIterator i = iterator(), j = s.iterator(); while(n-- != 0) if (i.nextLong() != j.nextLong()) return false; return true; if (s.size() != length()) return false; long n = length(); LongIterator i = iterator(); while(n-- != 0) if (! s.contains(i.nextLong())) return false; return true;
if (start < 0 && interval.length() == 1) return LongIntervals.EMPTY_INTERVAL; else start = count; if (interval.length() > 1) { dumpStream.position(LongBigArrays.get(blockOffset, interval.right) * blockSize); dumpStream.readBits(0); return LongInterval.valueOf(start, end - 1); } catch (IOException rethrow) { throw new RuntimeException(rethrow);
/** Returns a one-point interval. * * <P>You cannot obtain an empty interval with this factory method. Use {@link Intervals#EMPTY_INTERVAL} instead. * * @param point a point. * @return a one-point interval */ public static LongInterval valueOf(final long point) { if (point >= 0 && point < MAX_SINGLE_POINT) return POINT_INTERVAL[(int)point]; return new LongInterval(point, point); }
/** Returns a {@link MultiTermIndexIterator} over all terms starting with the given prefix, * provided their number does not exceed the given limit and that this index has a {@link #prefixMap}. */ public IndexIterator documents( final CharSequence prefix, final int limit ) throws IOException, TooManyTermsException { if ( prefixMap != null ) { final LongInterval interval = prefixMap.rangeMap().get( prefix ); if ( interval == LongIntervals.EMPTY_INTERVAL ) return new Index.EmptyIndexIterator(); final IndexIterator result; if ( interval.length() > limit ) throw new TooManyTermsException( interval.length() ); if ( interval.length() == 1 ) result = documents( interval.left ); else { IndexIterator[] baseIterator = new IndexIterator[ (int)interval.length() ]; int k = 0; for( LongIterator i = interval.iterator(); i.hasNext(); ) baseIterator[ k++ ] = documents( i.nextLong() ); result = MultiTermIndexIterator.getInstance( this, baseIterator ); } result.term( prefix + "*" ); return result; } else throw new UnsupportedOperationException( "Index " + this + " has no prefix map" ); }
@Override public LongSortedSet tailSet(final long from) { if (this == EMPTY_INTERVAL) return this; if (from <= right) return from <= left ? this : valueOf(from, right); else return EMPTY_INTERVAL; }
final IndexIterator result; if ( interval.length() > limit ) throw new TooManyTermsException( interval.length() ); if ( interval.length() == 1 ) result = documents( interval.left ); else { IndexIterator[] baseIterator = new IndexIterator[ (int)interval.length()]; int k = 0; for( LongIterator i = interval.iterator(); i.hasNext(); ) baseIterator[ k++ ] = documents( i.nextLong() );
/** An alias for {@link #length()} miminised with {@link Integer#MAX_VALUE}. * @return the interval length minimised with {@link Integer#MAX_VALUE}. */ @Override public int size() { return (int)Math.min(length(), Integer.MAX_VALUE); }
/** Creates a new subsequence. * * @param underlyingSequence the underlying document sequence. * @param first the first document (inclusive) in the subsequence. * @param last the last document (exclusive) in this subsequence. */ public SubsetDocumentSequence( DocumentSequence underlyingSequence, long first, long last ) { this.underlyingSequence = underlyingSequence; this.documents = last <= first? LongIntervals.EMPTY_INTERVAL : LongInterval.valueOf( first, last - 1 ); }
/** Returns an iterator over the integers in this interval larger than or equal to a given integer. * * @param from the starting integer. * @return an integer iterator over the elements in this interval. */ @Override public LongBidirectionalIterator iterator(final long from) { if (this == EMPTY_INTERVAL) return LongIterators.EMPTY_ITERATOR; // Note that fromTo() does NOT include the last integer. final LongBidirectionalIterator i = LongIterators.fromTo(left, right + 1); if (from >= left) { long toSkip = Math.min(length(), from + 1 - left); while(toSkip > 0) toSkip -= i.skip((int)Math.min(1 << 30, toSkip)); } return i; }
@Override public LongSortedSet subSet(final long from, final long to) { if (this == EMPTY_INTERVAL) return this; if (from > to) throw new IllegalArgumentException("Start element (" + from + ") is larger than end element (" + to + ")"); if (to <= left || from > right || from == to) return EMPTY_INTERVAL; if (from <= left && to > right) return this; return valueOf(Math.max(left, from), Math.min(right, to - 1)); }
@Override public MutableString get(final Object o) { final LongInterval interval = (LongInterval)o; final MutableString prefix = new MutableString(); if (interval == LongIntervals.EMPTY_INTERVAL || interval.left < 0 || interval.right < 0) throw new IllegalArgumentException(); getTerm(interval.left, prefix); if (interval.length() == 1) return prefix; final MutableString s = getTerm(interval.right, new MutableString()); final int l = Math.min(prefix.length(), s.length()); int i; for(i = 0; i < l; i++) if (s.charAt(i) != prefix.charAt(i)) break; return prefix.length(i); }
path = e.path; for(i = 0; i < path.length - 1 && offset + i < l && s.charAt(offset + i) == path[i]; i++); if (offset + i == l) return LongInterval.valueOf(wordsAtLeft, wordsAtLeft + e.numNodes - 1); if (i < path.length - 1) return LongIntervals.EMPTY_INTERVAL; offset += i; offset++; if (e.left != null) wordsAtLeft += e.left.numNodes; if (offset == l) return LongInterval.valueOf(wordsAtLeft, wordsAtLeft + (e.isWord ? 1 : 0) + (e.middle == null ? 0 : e.middle.numNodes) - 1); if (e.isWord) wordsAtLeft++; e = e.middle;
if (offset + i == l) { return wordsAtLeft > 0 ? LongInterval.valueOf(wordsAtLeft - 1, wordsAtLeft + e.numNodes - 1) : LongInterval.valueOf(wordsAtLeft, wordsAtLeft + e.numNodes - 1); if (s.charAt(offset + i) < path[i]) return wordsAtLeft > 0 ? LongInterval.valueOf(wordsAtLeft -1) : LongIntervals.EMPTY_INTERVAL; else return LongInterval.valueOf(wordsAtLeft + e.numNodes - 1); offset++; if (e.left != null) wordsAtLeft += e.left.numNodes; if (offset == l) return LongInterval.valueOf(wordsAtLeft - (e.isWord ? 0 : 1), wordsAtLeft + (e.isWord ? 1 : 0) + (e.middle == null ? 0 : e.middle.numNodes) - 1); if (e.isWord) wordsAtLeft++; e = e.middle; return wordsAtLeft > 0 ? LongInterval.valueOf(wordsAtLeft - 1) : LongIntervals.EMPTY_INTERVAL;
@Override public LongInterval get(final Object key) { final Interval interval = prefixMapRangeMap.get(key); return LongInterval.valueOf(interval.left, interval.right); }
public LongInterval get( Object o ) { CharSequence prefix = (CharSequence)o; try { ensureConnection(); remoteConnection.outputStream.writeByte( RemotePrefixMap.GET_INTERVAL ); new MutableString( prefix ).writeSelfDelimUTF8( (OutputStream)remoteConnection.outputStream ); remoteConnection.outputStream.flush(); return LongInterval.valueOf( remoteConnection.inputStream.readLong(), remoteConnection.inputStream.readLong() ); } catch ( Exception e ) { throw new RuntimeException( e ); } }
return n.word > 0 ? LongInterval.valueOf(n.word - 1) : LongIntervals.EMPTY_INTERVAL; return LongInterval.valueOf(n.word); return LongInterval.valueOf(n.word); return LongInterval.valueOf(n.word); if (l.word == 0) return mismatch ? LongIntervals.EMPTY_INTERVAL : LongInterval.valueOf(l.word, n.word); else return LongInterval.valueOf(l.word - 1, n.word); return LongInterval.valueOf(l.word, n.word);
return n.word > 0 ? LongInterval.valueOf(n.word - 1) : LongIntervals.EMPTY_INTERVAL; return LongInterval.valueOf(n.word); return LongInterval.valueOf(n.word); return LongInterval.valueOf(n.word); if (l.word == 0) return mismatch ? LongIntervals.EMPTY_INTERVAL : LongInterval.valueOf(0); else return LongInterval.valueOf(l.word - 1, n.word); return LongInterval.valueOf(l.word, n.word);