edu.emory.mathcs.util.collections.longs
Interface LongSortedSet

All Superinterfaces:
LongCollection, LongSet
All Known Subinterfaces:
LongInterval
All Known Implementing Classes:
AbstractLongInterval, AbstractLongSortedSet

public interface LongSortedSet
extends LongSet

Sorted set is a collection with no duplicate elements. Primitive sets have some features not found in object sets. A primitive set is associated with a domain with boundaries defined by LongSet.min() and LongSet.max(). All numbers contained within this set must fit between min and max, inclusive. Attempt to add a number from outside the domain will have no effect.

It is possible to obtain a complement view of a primitive set, using LongSet.complementSet(). The complement view contains all numbers between min and max, inclusive, which are not contained in this set. (In other words, complement view never contains numbers from outside of the domain of this set).

Contrary to standard Java collections, intervals in this primitive collection package are inclusive on both sides. In other words, interval [min, max] contains all numbers c such that min <= c <= max. (Otherwise, MAX_VALUE could not be put in the set).

It is possible to obtain a subset view of a sorted set, using one of the methods #subSet(), #headSet(), and #tailSet(). The subset view narrows the domain, and its size is thus never bigger than that of this set.

Sorted sets define a family of navigation methods, analogous to that found in NavigableSet.

Version:
1.0
Author:
Dawid Kurzyniec

Method Summary
 long ceiling(long e)
          Returns the smallest number in this set >= e.
 LongInterval ceilingInterval(long e)
          Returns the smallest (left-most), widest interval contained in this set which elements are not all smaller than the specified number.
 java.util.Iterator descendingIntervalIterator()
          Returns an iterator over intervals of this set, in a decreasing numerical order.
 LongIterator descendingIterator()
          Returns an iterator over numbers in this set, in a decreasing numerical order.
 LongInterval enclosingInterval(long e)
          Returns the widest interval contained in this set that includes the specified number, or null if this set does not include the specified number.
 long first()
          Returns the smallest number in this set.
 LongInterval firstInterval()
          Returns the first (left-most), widest interval contained in this set, or null if this set is empty.
 long floor(long e)
          Returns the largest number in this set <= e.
 LongInterval floorInterval(long e)
          Returns the largest (right-most), widest interval contained in this set which elements are not all greater than the specified number.
 LongSortedSet headSet(long last)
          A subset view containing all elements from this set that are not greater than last.
 long higher(long e)
          Returns the smallest number in this set > e.
 LongInterval higherInterval(long e)
          Returns the smallest (left-most), widest interval contained in this set which all elements are strictly greater than the specified number.
 int intervalCount()
          Returns the minimum count of intervals into which this set can be decomposed.
 java.util.Iterator intervalIterator()
          Returns an iterator over intervals of this set, in an increasing numerical order.
 LongIterator iterator()
          Returns an iterator over numbers in this set, in an increasing numerical order.
 long last()
          Returns the largest number in this set.
 LongInterval lastInterval()
          Returns the last (right-most), widest interval contained in this set, or null if this set is empty.
 long lower(long e)
          Returns the largest number in this set < e.
 LongInterval lowerInterval(long e)
          Returns the largest and widest interval contained in this set which all elements are strictly less than the specified number.
 long pollFirst()
          Returns and removes the smallest number in this set.
 LongInterval pollFirstInterval()
          Returns and removes the first (left-most), widest interval contained in this set, or null if this set is empty.
 long pollLast()
          Returns and removes the largest number in this set.
 LongInterval pollLastInterval()
          Returns and removes the last (right-most), widest interval contained in this set, or null if this set is empty.
 LongSortedSet subSet(long first, long last)
          A subset view containing all elements from this set between first, inclusive, and last, inclusive.
 LongSortedSet tailSet(long first)
          A subset view containing all elements from this set that are not smaller than first.
 java.lang.String toCompactString()
          Returns the interval-string representation of this set (suitable for representing sets that are possibly large but clustered).
 java.lang.String toString()
           
 
Methods inherited from interface edu.emory.mathcs.util.collections.longs.LongSet
add, addAll, addInterval, clear, complementSet, contains, containsAll, containsInterval, equals, hashCode, isEmpty, max, min, remove, removeAll, removeInterval, retainAll, retainInterval, size, size64, toArray, toArray
 

Method Detail

subSet

public LongSortedSet subSet(long first,
                            long last)
A subset view containing all elements from this set between first, inclusive, and last, inclusive. More precisely, the view is narrowed to the domain [min, max]. Hence, complement set of this set will NOT include any elements outside [min, max].

Parameters:
first - the minimum element of this view (inclusive).
last - the maximum element of this view (inclusive).
Returns:
the subset view

headSet

public LongSortedSet headSet(long last)
A subset view containing all elements from this set that are not greater than last. More precisely, the view is narrowed to the domain [MIN_VALUE, max]. Hence, complement set of this set will NOT include any elements > max.

Parameters:
last - the maximum element of this view (inclusive).
Returns:
the headset view

tailSet

public LongSortedSet tailSet(long first)
A subset view containing all elements from this set that are not smaller than first. More precisely, the view is narrowed to the domain [min, MAX_VALUE]. Hence, complement set of this set will NOT include any elements < min.

Parameters:
first - the minimum element of this view (inclusive).
Returns:
the tailset view

first

public long first()
Returns the smallest number in this set.

Returns:
the smallest number in this set.
Throws:
java.util.NoSuchElementException - if the set is empty.

last

public long last()
Returns the largest number in this set.

Returns:
the largest number in this set.
Throws:
java.util.NoSuchElementException - if the set is empty.

ceiling

public long ceiling(long e)
Returns the smallest number in this set >= e.

Returns:
the smallest number in this set >= e.
Throws:
java.util.NoSuchElementException - if all elements are < e.

higher

public long higher(long e)
Returns the smallest number in this set > e.

Returns:
the smallest number in this set > e.
Throws:
java.util.NoSuchElementException - if all elements are <= e.

floor

public long floor(long e)
Returns the largest number in this set <= e.

Returns:
the largest number in this set <= e.
Throws:
java.util.NoSuchElementException - if all elements are > e.

lower

public long lower(long e)
Returns the largest number in this set < e.

Returns:
the largest number in this set < e.
Throws:
java.util.NoSuchElementException - if all elements are >= e.

pollFirst

public long pollFirst()
Returns and removes the smallest number in this set.

Returns:
the smallest number in this set.
Throws:
java.util.NoSuchElementException - if the set is empty.

pollLast

public long pollLast()
Returns and removes the largest number in this set.

Returns:
the smallest number in this set.
Throws:
java.util.NoSuchElementException - if the set is empty.

intervalCount

public int intervalCount()
Returns the minimum count of intervals into which this set can be decomposed. For instance, {1, 3,4,5, 8,9}.intervalCount() == 3.

Returns:
int the interval count of this set.

intervalIterator

public java.util.Iterator intervalIterator()
Returns an iterator over intervals of this set, in an increasing numerical order.

Returns:
an iterator over intervals of this set

descendingIntervalIterator

public java.util.Iterator descendingIntervalIterator()
Returns an iterator over intervals of this set, in a decreasing numerical order.

Returns:
a descending iterator over intervals of this set

iterator

public LongIterator iterator()
Returns an iterator over numbers in this set, in an increasing numerical order.

Specified by:
iterator in interface LongSet
Returns:
an iterator over numbers in this set

descendingIterator

public LongIterator descendingIterator()
Returns an iterator over numbers in this set, in a decreasing numerical order.

Returns:
a descending iterator over numbers in this set

firstInterval

public LongInterval firstInterval()
Returns the first (left-most), widest interval contained in this set, or null if this set is empty.

Returns:
the first interval contained in this set

lastInterval

public LongInterval lastInterval()
Returns the last (right-most), widest interval contained in this set, or null if this set is empty.

Returns:
the last interval contained in this set

enclosingInterval

public LongInterval enclosingInterval(long e)
Returns the widest interval contained in this set that includes the specified number, or null if this set does not include the specified number.

Returns:
the interval containing the specified number.

lowerInterval

public LongInterval lowerInterval(long e)
Returns the largest and widest interval contained in this set which all elements are strictly less than the specified number.

Returns:
the largest interval smaller than the specified number.

higherInterval

public LongInterval higherInterval(long e)
Returns the smallest (left-most), widest interval contained in this set which all elements are strictly greater than the specified number.

Returns:
the smallest interval greater than the specified number.

floorInterval

public LongInterval floorInterval(long e)
Returns the largest (right-most), widest interval contained in this set which elements are not all greater than the specified number. In other words, it either includes the specified number or has all elements strictly less than the specified number.

Returns:
the largest interval which lower bound is <= than the specified number.

ceilingInterval

public LongInterval ceilingInterval(long e)
Returns the smallest (left-most), widest interval contained in this set which elements are not all smaller than the specified number. In other words, it either includes the specified number or has all elements strictly greater than the specified number.

Returns:
the smallest interval which upper bound is >= than the specified number.

pollFirstInterval

public LongInterval pollFirstInterval()
Returns and removes the first (left-most), widest interval contained in this set, or null if this set is empty.

Returns:
the first interval contained in this set

pollLastInterval

public LongInterval pollLastInterval()
Returns and removes the last (right-most), widest interval contained in this set, or null if this set is empty.

Returns:
the last interval contained in this set

toString

public java.lang.String toString()

toCompactString

public java.lang.String toCompactString()
Returns the interval-string representation of this set (suitable for representing sets that are possibly large but clustered).

Returns:
String