Package healpix.essentials
Class RangeSet
java.lang.Object
healpix.essentials.RangeSet
Class for dealing with sets of integer ranges.
Ranges are described by the first element and the one-past-last element.
This code was inspired by Jan Kotek's "LongRangeSet" class, but has been
completely reimplemented.
- Author:
- Martin Reinecke
- Copyright:
- 2011-2015 Max-Planck-Society
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Interface describing an iterator for going through all values in a RangeSet object. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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 an entire range set to the object.void
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
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.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
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[.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
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[]
Returns a compressed representation of the RangeSet, using interpolative coding.toString()
void
Shrinks the array for the entries to minimum size, if it is more than twice the minimum sizevoid
trimSize()
Shrinks the array for the entries to minimum size.Return the union of this RangeSet and other.Returns a ValueIterator, which iterates over all individual numbers in the RangeSet.
-
Field Details
-
r
protected long[] rSorted list of interval boundaries. -
sz
protected int szCurrent number of active entries.
-
-
Constructor Details
-
RangeSet
public RangeSet()Construct new object with initial space for 4 ranges. -
RangeSet
public RangeSet(int cap) Construct new object with initial capacity for a given number of ranges.- Parameters:
cap
- number of initially reserved ranges.
-
RangeSet
public RangeSet(long[] data) Construct new object from an array of longs.- Parameters:
data
-
-
RangeSet
Construct new object from another RangeSet- Parameters:
other
-
-
-
Method Details
-
checkConsistency
public void checkConsistency()Checks the object for internal consistency. If a problem is detected, an IllegalArgumentException is thrown. -
ensureCapacity
public void ensureCapacity(int cap) Make sure the object can hold at least the given number of entries. -
trimSize
public void trimSize()Shrinks the array for the entries to minimum size. -
trimIfTooLarge
public void trimIfTooLarge()Shrinks the array for the entries to minimum size, if it is more than twice the minimum size -
append
public void append(long val) Append a single-value range to the object.- Parameters:
val
- value to append
-
append
public void append(long a, long b) Append a range to the object.- Parameters:
a
- first long in rangeb
- one-after-last long in range
-
append
Append an entire range set to the object. -
nranges
public int nranges()- Returns:
- number of ranges in the set.
-
isEmpty
public boolean isEmpty()- Returns:
- true if no entries are stored, else false.
-
ivbegin
public long ivbegin(int iv) - Returns:
- first number in range iv.
-
ivend
public long ivend(int iv) - Returns:
- one-past-last number in range iv.
-
clear
public void clear()Remove all entries in the set. -
union
Return the union of this RangeSet and other. -
intersection
Return the intersection of this RangeSet and other. -
difference
Return the difference of this RangeSet and other. -
contains
public boolean contains(long a) Returns true if a is contained in the set, else false. -
contains
public boolean contains(long a, long b) Returns true if all numbers [a;b[ are contained in the set, else false. -
containsAll
Deprecated. -
overlaps
public boolean overlaps(long a, long b) Returns true if any of the numbers [a;b[ are contained in the set, else false. -
containsAny
Deprecated. -
contains
Returns true if the set completely contains "other", else false. -
containsAll
Deprecated. -
overlaps
Returns true if there is overlap between the set and "other", else false. -
containsAny
Deprecated. -
equals
Returns true the object represents an identical set of ranges as obj. -
hashCode
public int hashCode() -
nval
public long nval()- Returns:
- total number of values (not ranges) in the set.
-
intersect
public void intersect(long a, long b) After this operation, the RangeSet contains the intersection of itself and [a;b[. -
add
public void add(long a, long b) After this operation, the RangeSet contains the union of itself and [a;b[. -
add
public void add(long a) After this operation, the RangeSet contains the union of itself and [a;a+1[. -
remove
public void remove(long a, long b) After this operation, the RangeSet contains the difference of itself and [a;b[. -
remove
public void remove(long a) After this operation, the RangeSet contains the difference of itself and [a;a+1[. -
toArray
public long[] toArray()Creates an array containing all the numbers in the RangeSet. Not recommended, because the arrays can become prohibitively large. It is preferrable to use a ValueIterator or explicit loops. -
fromArray
-
toString
-
valueIterator
Returns a ValueIterator, which iterates over all individual numbers in the RangeSet. -
toCompressed
Returns a compressed representation of the RangeSet, using interpolative coding.- Throws:
Exception
-
fromCompressed
Returns a RangeSet obtained by decompressing a byte array which was originally generated by toCompressed().- Throws:
Exception
-