Package healpix.essentials
Class RangeSet
- java.lang.Object
-
- healpix.essentials.RangeSet
-
public class RangeSet extends java.lang.ObjectClass 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRangeSet.ValueIteratorInterface describing an iterator for going through all values in a RangeSet object.
-
Constructor Summary
Constructors Constructor 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
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(long a)After this operation, the RangeSet contains the union of itself and [a;a+1[.voidadd(long a, long b)After this operation, the RangeSet contains the union of itself and [a;b[.voidappend(long val)Append a single-value range to the object.voidappend(long a, long b)Append a range to the object.voidappend(RangeSet other)Append an entire range set to the object.voidcheckConsistency()Checks the object for internal consistency.voidclear()Remove all entries in the set.booleancontains(long a)Returns true if a is contained in the set, else false.booleancontains(long a, long b)Returns true if all numbers [a;b[ are contained in the set, else false.booleancontains(RangeSet other)Returns true if the set completely contains "other", else false.booleancontainsAll(long a, long b)Deprecated.booleancontainsAll(RangeSet other)Deprecated.booleancontainsAny(long a, long b)Deprecated.booleancontainsAny(RangeSet other)Deprecated.RangeSetdifference(RangeSet other)Return the difference of this RangeSet and other.voidensureCapacity(int cap)Make sure the object can hold at least the given number of entries.booleanequals(java.lang.Object obj)Returns true the object represents an identical set of ranges as obj.static RangeSetfromArray(long[] v)static RangeSetfromCompressed(byte[] data)Returns a RangeSet obtained by decompressing a byte array which was originally generated by toCompressed().inthashCode()voidintersect(long a, long b)After this operation, the RangeSet contains the intersection of itself and [a;b[.RangeSetintersection(RangeSet other)Return the intersection of this RangeSet and other.booleanisEmpty()longivbegin(int iv)longivend(int iv)intnranges()longnval()booleanoverlaps(long a, long b)Returns true if any of the numbers [a;b[ are contained in the set, else false.booleanoverlaps(RangeSet other)Returns true if there is overlap between the set and "other", else false.voidremove(long a)After this operation, the RangeSet contains the difference of itself and [a;a+1[.voidremove(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.StringtoString()voidtrimIfTooLarge()Shrinks the array for the entries to minimum size, if it is more than twice the minimum sizevoidtrimSize()Shrinks the array for the entries to minimum size.RangeSetunion(RangeSet other)Return the union of this RangeSet and other.RangeSet.ValueIteratorvalueIterator()Returns a ValueIterator, which iterates over all individual numbers in the RangeSet.
-
-
-
Constructor Detail
-
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
public RangeSet(RangeSet other)
Construct new object from another RangeSet- Parameters:
other-
-
-
Method Detail
-
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
public void append(RangeSet other)
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.
-
intersection
public RangeSet intersection(RangeSet other)
Return the intersection of this RangeSet and other.
-
difference
public RangeSet difference(RangeSet other)
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 public boolean containsAll(long a, long b)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 public boolean containsAny(long a, long b)Deprecated.
-
contains
public boolean contains(RangeSet other)
Returns true if the set completely contains "other", else false.
-
containsAll
@Deprecated public boolean containsAll(RangeSet other)
Deprecated.
-
overlaps
public boolean overlaps(RangeSet other)
Returns true if there is overlap between the set and "other", else false.
-
containsAny
@Deprecated public boolean containsAny(RangeSet other)
Deprecated.
-
equals
public boolean equals(java.lang.Object obj)
Returns true the object represents an identical set of ranges as obj.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
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
public static RangeSet fromArray(long[] v)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
valueIterator
public RangeSet.ValueIterator valueIterator()
Returns a ValueIterator, which iterates over all individual numbers in the RangeSet.
-
toCompressed
public byte[] toCompressed() throws java.lang.ExceptionReturns a compressed representation of the RangeSet, using interpolative coding.- Throws:
java.lang.Exception
-
fromCompressed
public static RangeSet fromCompressed(byte[] data) throws java.lang.Exception
Returns a RangeSet obtained by decompressing a byte array which was originally generated by toCompressed().- Throws:
java.lang.Exception
-
-