public class RangeSet
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
RangeSet.ValueIterator
Interface describing an iterator for going through all values in
a RangeSet object.
|
Modifier and Type | Field and Description |
---|---|
protected long[] |
r
Sorted list of interval boundaries.
|
protected int |
sz
Current number of active entries.
|
Constructor and Description |
---|
RangeSet()
Construct new object with initial space for 4 ranges.
|
RangeSet(int cap)
Construct new object with initial capacity for a given number of ranges.
|
RangeSet(long[] data)
Construct new object from an array of longs.
|
RangeSet(RangeSet other)
Construct new object from another RangeSet
|
Modifier and Type | Method and Description |
---|---|
void |
add(long a)
After this operation, the RangeSet contains the union of itself and
[a;a+1[.
|
void |
add(long a,
long b)
After this operation, the RangeSet contains the union of itself and
[a;b[.
|
void |
append(long val)
Append a single-value range to the object.
|
void |
append(long a,
long b)
Append a range to the object.
|
void |
append(RangeSet other)
Append an entire range set to the object.
|
void |
checkConsistency()
Checks the object for internal consistency.
|
void |
clear()
Remove all entries in the set.
|
boolean |
contains(long a)
Returns true if a is contained in the set, else false.
|
boolean |
contains(long a,
long b)
Returns true if all numbers [a;b[ are contained in the set, else false.
|
boolean |
contains(RangeSet other)
Returns true if the set completely contains "other", else false.
|
boolean |
containsAll(long a,
long b)
Deprecated.
|
boolean |
containsAll(RangeSet other)
Deprecated.
|
boolean |
containsAny(long a,
long b)
Deprecated.
|
boolean |
containsAny(RangeSet other)
Deprecated.
|
RangeSet |
difference(RangeSet other)
Return the difference of this RangeSet and other.
|
void |
ensureCapacity(int cap)
Make sure the object can hold at least the given number of entries.
|
boolean |
equals(java.lang.Object obj)
Returns true the object represents an identical set of ranges as obj.
|
static RangeSet |
fromArray(long[] v) |
static RangeSet |
fromCompressed(byte[] data)
Returns a RangeSet obtained by decompressing a byte array which was
originally generated by toCompressed().
|
int |
hashCode() |
void |
intersect(long a,
long b)
After this operation, the RangeSet contains the intersection of itself and
[a;b[.
|
RangeSet |
intersection(RangeSet other)
Return the intersection of this RangeSet and other.
|
boolean |
isEmpty() |
long |
ivbegin(int iv) |
long |
ivend(int iv) |
int |
nranges() |
long |
nval() |
boolean |
overlaps(long a,
long b)
Returns true if any of the numbers [a;b[ are contained in the set,
else false.
|
boolean |
overlaps(RangeSet other)
Returns true if there is overlap between the set and "other",
else false.
|
void |
remove(long a)
After this operation, the RangeSet contains the difference of itself and
[a;a+1[.
|
void |
remove(long a,
long b)
After this operation, the RangeSet contains the difference of itself and
[a;b[.
|
long[] |
toArray()
Creates an array containing all the numbers in the RangeSet.
|
byte[] |
toCompressed()
Returns a compressed representation of the RangeSet, using interpolative
coding.
|
java.lang.String |
toString() |
void |
trimIfTooLarge()
Shrinks the array for the entries to minimum size, if it is more than
twice the minimum size
|
void |
trimSize()
Shrinks the array for the entries to minimum size.
|
RangeSet |
union(RangeSet other)
Return the union of this RangeSet and other.
|
RangeSet.ValueIterator |
valueIterator()
Returns a ValueIterator, which iterates over all individual numbers
in the RangeSet.
|
protected long[] r
protected int sz
public RangeSet()
public RangeSet(int cap)
cap
- number of initially reserved ranges.public RangeSet(long[] data)
data
- public RangeSet(RangeSet other)
other
- public void checkConsistency()
public void ensureCapacity(int cap)
public void trimSize()
public void trimIfTooLarge()
public void append(long val)
val
- value to appendpublic void append(long a, long b)
a
- first long in rangeb
- one-after-last long in rangepublic void append(RangeSet other)
public int nranges()
public boolean isEmpty()
public long ivbegin(int iv)
public long ivend(int iv)
public void clear()
public RangeSet intersection(RangeSet other)
public RangeSet difference(RangeSet other)
public boolean contains(long a)
public boolean contains(long a, long b)
@Deprecated public boolean containsAll(long a, long b)
public boolean overlaps(long a, long b)
@Deprecated public boolean containsAny(long a, long b)
public boolean contains(RangeSet other)
@Deprecated public boolean containsAll(RangeSet other)
public boolean overlaps(RangeSet other)
@Deprecated public boolean containsAny(RangeSet other)
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public long nval()
public void intersect(long a, long b)
public void add(long a, long b)
public void add(long a)
public void remove(long a, long b)
public void remove(long a)
public long[] toArray()
public static RangeSet fromArray(long[] v)
public java.lang.String toString()
toString
in class java.lang.Object
public RangeSet.ValueIterator valueIterator()
public byte[] toCompressed() throws java.lang.Exception
java.lang.Exception
public static RangeSet fromCompressed(byte[] data) throws java.lang.Exception
java.lang.Exception