edu.emory.mathcs.util.collections.ints
Class IntIntervalSet

java.lang.Object
  extended byedu.emory.mathcs.util.collections.ints.AbstractIntCollection
      extended byedu.emory.mathcs.util.collections.ints.AbstractIntSet
          extended byedu.emory.mathcs.util.collections.ints.AbstractIntSortedSet
              extended byedu.emory.mathcs.util.collections.ints.IntIntervalSet
All Implemented Interfaces:
IntCollection, IntSet, IntSortedSet, java.io.Serializable

public class IntIntervalSet
extends AbstractIntSortedSet
implements java.io.Serializable

Set of int numbers that is optimized towards clustered distributions. The implementation keeps the atomic information about intervals of numbers, hence this set can hold billions of elements as int as they form clusters (int consecutive runs). The main application of this class is in collision detection arrays, e.g. to aid in generation of unique IDs that are roughly sequential but possibly cyclic (process IDs, packet IDs) with ID recycling and gap filling.

Caution: descending iterators aren't particularly well tested.

Author:
Dawid Kurzyniec
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class edu.emory.mathcs.util.collections.ints.AbstractIntSortedSet
AbstractIntSortedSet.AbstractComplementSubView, AbstractIntSortedSet.AbstractSubView, AbstractIntSortedSet.ForwardIntervalItemIterator, AbstractIntSortedSet.ReverseIntervalItemIterator
 
Constructor Summary
IntIntervalSet()
          Creates a new set of ints.
IntIntervalSet(IntCollection c)
           
IntIntervalSet(int min, int max)
           
IntIntervalSet(IntSet c)
           
 
Method Summary
 boolean add(int n)
          Adds an element to the set if it is not already present.
 boolean addAll(IntCollection c)
          Adds all of the elements in the specified collection to this set if they're not already present, and if they fall within this set's domain.
 boolean addInterval(int first, int last)
          Adds to this set all the numbers between first and last, inclusive, that are not already present in this set and beint to this set's domain.
 int ceiling(int n)
          Returns the smallest number in this set >= e.
 IntInterval ceilingInterval(int n)
          Returns the smallest (left-most), widest interval contained in this set which elements are not all smaller than the specified number.
 void clear()
          Removes all elements from the set.
 IntSet complementSet()
          Returns a complement view of this set.
 boolean contains(int n)
          Checks whether the set contains a given element
 boolean containsInterval(int first, int last)
          Returns true if this set contains all the numbers between first and last, inclusive; false otherwise.
 java.util.Iterator descendingIntervalIterator()
          Returns an iterator over intervals of this set, in a decreasing numerical order.
 IntIterator descendingIterator()
          Returns an iterator over numbers in this set, in a decreasing numerical order.
 IntInterval enclosingInterval(int 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.
 int first()
          Returns the smallest number in this set.
 IntInterval firstInterval()
          Returns the first (left-most), widest interval contained in this set, or null if this set is empty.
 int floor(int n)
          Returns the largest number in this set <= e.
 IntInterval floorInterval(int n)
          Returns the largest (right-most), widest interval contained in this set which elements are not all greater than the specified number.
 int higher(int n)
          Returns the smallest number in this set > e.
 IntInterval higherInterval(int n)
          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.
 boolean isEmpty()
          Returns true if this set is empty; false otherwise.
 IntIterator iterator()
          Returns an iterator over numbers in this set, in an increasing numerical order.
 int last()
          Returns the largest number in this set.
 IntInterval lastInterval()
          Returns the last (right-most), widest interval contained in this set, or null if this set is empty.
 int lower(int n)
          Returns the largest number in this set < e.
 IntInterval lowerInterval(int n)
          Returns the largest and widest interval contained in this set which all elements are strictly less than the specified number.
 int max()
          The largest number that can be stored in this set.
 int min()
          The smallest number that can be stored in this set.
 int pollFirst()
          Returns and removes the smallest number in this set.
 IntInterval pollFirstInterval()
          Returns and removes the first (left-most), widest interval contained in this set, or null if this set is empty.
 int pollLast()
          Returns and removes the largest number in this set.
 IntInterval pollLastInterval()
          Returns and removes the last (right-most), widest interval contained in this set, or null if this set is empty.
 boolean remove(int n)
          Removes the specified number from this set if it is present.
 boolean removeAll(IntCollection c)
          Removes from this set all of its elements that are contained in the specified collection.
 boolean removeInterval(int first, int last)
          Removes from this set all the numbers between first and last, inclusive.
 int size64()
          Returns the number of elements in this set.
 IntSortedSet subSet(int first, int last)
          A subset view containing all elements from this set between first, inclusive, and last, inclusive.
 
Methods inherited from class edu.emory.mathcs.util.collections.ints.AbstractIntSortedSet
headSet, retainAll, retainInterval, tailSet, toCompactString
 
Methods inherited from class edu.emory.mathcs.util.collections.ints.AbstractIntSet
equals, hashCode
 
Methods inherited from class edu.emory.mathcs.util.collections.ints.AbstractIntCollection
containsAll, size, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.emory.mathcs.util.collections.ints.IntSortedSet
toString
 
Methods inherited from interface edu.emory.mathcs.util.collections.ints.IntSet
containsAll, equals, hashCode, size, toArray, toArray
 

Constructor Detail

IntIntervalSet

public IntIntervalSet()
Creates a new set of ints.


IntIntervalSet

public IntIntervalSet(int min,
                      int max)

IntIntervalSet

public IntIntervalSet(IntCollection c)

IntIntervalSet

public IntIntervalSet(IntSet c)
Method Detail

min

public int min()
Description copied from interface: IntSet
The smallest number that can be stored in this set.

Specified by:
min in interface IntSet
Overrides:
min in class AbstractIntSet

max

public int max()
Description copied from interface: IntSet
The largest number that can be stored in this set.

Specified by:
max in interface IntSet
Overrides:
max in class AbstractIntSet

intervalCount

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

Specified by:
intervalCount in interface IntSortedSet
Overrides:
intervalCount in class AbstractIntSortedSet

size64

public int size64()
Description copied from interface: IntSet
Returns the number of elements in this set.

Specified by:
size64 in interface IntSet
Overrides:
size64 in class AbstractIntSortedSet

isEmpty

public boolean isEmpty()
Description copied from interface: IntSet
Returns true if this set is empty; false otherwise.

Specified by:
isEmpty in interface IntSet
Overrides:
isEmpty in class AbstractIntSortedSet

clear

public void clear()
Removes all elements from the set.

Specified by:
clear in interface IntSet
Overrides:
clear in class AbstractIntCollection

add

public boolean add(int n)
Adds an element to the set if it is not already present.

Specified by:
add in interface IntSet
Overrides:
add in class AbstractIntCollection
Returns:
true is the element was added

addInterval

public boolean addInterval(int first,
                           int last)
Description copied from interface: IntSet
Adds to this set all the numbers between first and last, inclusive, that are not already present in this set and beint to this set's domain.

Specified by:
addInterval in interface IntSet
Overrides:
addInterval in class AbstractIntSet

addAll

public boolean addAll(IntCollection c)
Description copied from interface: IntSet
Adds all of the elements in the specified collection to this set if they're not already present, and if they fall within this set's domain. If the specified collection is also a set, the addAll operation effectively modifies this set so that its value is the union of the two sets, intersected with this set's domain. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress.

Specified by:
addAll in interface IntSet
Overrides:
addAll in class AbstractIntSet

remove

public boolean remove(int n)
Description copied from interface: IntSet
Removes the specified number from this set if it is present.

Specified by:
remove in interface IntSet
Overrides:
remove in class AbstractIntCollection

removeInterval

public boolean removeInterval(int first,
                              int last)
Description copied from interface: IntSet
Removes from this set all the numbers between first and last, inclusive.

Specified by:
removeInterval in interface IntSet
Overrides:
removeInterval in class AbstractIntSet

removeAll

public boolean removeAll(IntCollection c)
Description copied from interface: IntSet
Removes from this set all of its elements that are contained in the specified collection. If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets.

Specified by:
removeAll in interface IntSet
Overrides:
removeAll in class AbstractIntSet

contains

public boolean contains(int n)
Checks whether the set contains a given element

Specified by:
contains in interface IntSet
Overrides:
contains in class AbstractIntCollection
Parameters:
n - the element
Returns:
true if the set contains n, false otherwise

containsInterval

public boolean containsInterval(int first,
                                int last)
Description copied from interface: IntSet
Returns true if this set contains all the numbers between first and last, inclusive; false otherwise.

Specified by:
containsInterval in interface IntSet
Overrides:
containsInterval in class AbstractIntSet

enclosingInterval

public IntInterval enclosingInterval(int e)
Description copied from interface: IntSortedSet
Returns the widest interval contained in this set that includes the specified number, or null if this set does not include the specified number.

Specified by:
enclosingInterval in interface IntSortedSet
Returns:
the interval containing the specified number.

lower

public int lower(int n)
Description copied from interface: IntSortedSet
Returns the largest number in this set < e.

Specified by:
lower in interface IntSortedSet
Overrides:
lower in class AbstractIntSortedSet

floor

public int floor(int n)
Description copied from interface: IntSortedSet
Returns the largest number in this set <= e.

Specified by:
floor in interface IntSortedSet
Overrides:
floor in class AbstractIntSortedSet

higher

public int higher(int n)
Description copied from interface: IntSortedSet
Returns the smallest number in this set > e.

Specified by:
higher in interface IntSortedSet
Overrides:
higher in class AbstractIntSortedSet

ceiling

public int ceiling(int n)
Description copied from interface: IntSortedSet
Returns the smallest number in this set >= e.

Specified by:
ceiling in interface IntSortedSet
Overrides:
ceiling in class AbstractIntSortedSet

intervalIterator

public java.util.Iterator intervalIterator()
Description copied from interface: IntSortedSet
Returns an iterator over intervals of this set, in an increasing numerical order.

Specified by:
intervalIterator in interface IntSortedSet
Returns:
an iterator over intervals of this set

iterator

public IntIterator iterator()
Description copied from interface: IntSortedSet
Returns an iterator over numbers in this set, in an increasing numerical order.

Specified by:
iterator in interface IntSortedSet
Overrides:
iterator in class AbstractIntSortedSet

descendingIntervalIterator

public java.util.Iterator descendingIntervalIterator()
Description copied from interface: IntSortedSet
Returns an iterator over intervals of this set, in a decreasing numerical order.

Specified by:
descendingIntervalIterator in interface IntSortedSet
Returns:
a descending iterator over intervals of this set

descendingIterator

public IntIterator descendingIterator()
Description copied from interface: IntSortedSet
Returns an iterator over numbers in this set, in a decreasing numerical order.

Specified by:
descendingIterator in interface IntSortedSet
Overrides:
descendingIterator in class AbstractIntSortedSet

first

public int first()
Description copied from interface: IntSortedSet
Returns the smallest number in this set.

Specified by:
first in interface IntSortedSet
Overrides:
first in class AbstractIntSortedSet

last

public int last()
Description copied from interface: IntSortedSet
Returns the largest number in this set.

Specified by:
last in interface IntSortedSet
Overrides:
last in class AbstractIntSortedSet

pollFirst

public int pollFirst()
Description copied from interface: IntSortedSet
Returns and removes the smallest number in this set.

Specified by:
pollFirst in interface IntSortedSet
Overrides:
pollFirst in class AbstractIntSortedSet

pollLast

public int pollLast()
Description copied from interface: IntSortedSet
Returns and removes the largest number in this set.

Specified by:
pollLast in interface IntSortedSet
Overrides:
pollLast in class AbstractIntSortedSet

firstInterval

public IntInterval firstInterval()
Description copied from interface: IntSortedSet
Returns the first (left-most), widest interval contained in this set, or null if this set is empty.

Specified by:
firstInterval in interface IntSortedSet
Overrides:
firstInterval in class AbstractIntSortedSet

lastInterval

public IntInterval lastInterval()
Description copied from interface: IntSortedSet
Returns the last (right-most), widest interval contained in this set, or null if this set is empty.

Specified by:
lastInterval in interface IntSortedSet
Overrides:
lastInterval in class AbstractIntSortedSet

ceilingInterval

public IntInterval ceilingInterval(int n)
Description copied from interface: IntSortedSet
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.

Specified by:
ceilingInterval in interface IntSortedSet
Returns:
the smallest interval which upper bound is >= than the specified number.

floorInterval

public IntInterval floorInterval(int n)
Description copied from interface: IntSortedSet
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.

Specified by:
floorInterval in interface IntSortedSet
Returns:
the largest interval which lower bound is <= than the specified number.

higherInterval

public IntInterval higherInterval(int n)
Description copied from interface: IntSortedSet
Returns the smallest (left-most), widest interval contained in this set which all elements are strictly greater than the specified number.

Specified by:
higherInterval in interface IntSortedSet
Returns:
the smallest interval greater than the specified number.

lowerInterval

public IntInterval lowerInterval(int n)
Description copied from interface: IntSortedSet
Returns the largest and widest interval contained in this set which all elements are strictly less than the specified number.

Specified by:
lowerInterval in interface IntSortedSet
Returns:
the largest interval smaller than the specified number.

pollFirstInterval

public IntInterval pollFirstInterval()
Description copied from interface: IntSortedSet
Returns and removes the first (left-most), widest interval contained in this set, or null if this set is empty.

Specified by:
pollFirstInterval in interface IntSortedSet
Overrides:
pollFirstInterval in class AbstractIntSortedSet

pollLastInterval

public IntInterval pollLastInterval()
Description copied from interface: IntSortedSet
Returns and removes the last (right-most), widest interval contained in this set, or null if this set is empty.

Specified by:
pollLastInterval in interface IntSortedSet
Overrides:
pollLastInterval in class AbstractIntSortedSet

subSet

public IntSortedSet subSet(int first,
                           int last)
Description copied from interface: IntSortedSet
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].

Specified by:
subSet in interface IntSortedSet
Parameters:
first - the minimum element of this view (inclusive).
last - the maximum element of this view (inclusive).
Returns:
the subset view

complementSet

public IntSet complementSet()
Description copied from interface: IntSet
Returns a complement view of this set. Complement view is a set that has the same domain as this set, and consists of all numbers from the domain that are not contained in this set. Changes done to this set are reflected in the complement view after it is created.

Specified by:
complementSet in interface IntSet
Overrides:
complementSet in class AbstractIntSet