healpix.essentials
Class RangeSet

java.lang.Object
  extended by healpix.essentials.RangeSet
All Implemented Interfaces:
Externalizable, Serializable

public class RangeSet
extends Object
implements Externalizable

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
See Also:
Serialized Form
Copyright:
2011, 2012 Max-Planck-Society

Nested Class Summary
static interface RangeSet.ValueIterator
          Interface describing an iterator for going through all values in a RangeSet object.
 
Constructor Summary
RangeSet()
          Construct new object with space for 8 entries (4 ranges).
RangeSet(int cap)
          Construct new object with a given initial number of entries.
RangeSet(long[] data)
          Construct new object from an array of longs.
RangeSet(RangeSet other)
          Construct new object from another RangeSet
 
Method Summary
 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 containsAll(long a, long b)
          Returns true if all numbers [a;b[ are contained in the set, else false.
 boolean containsAll(RangeSet other)
          Returns true if the set completely contains "other", else false.
 boolean containsAny(long a, long b)
          Returns true if any of the numbers [a;b[ are contained in the set, else false.
 boolean containsAny(RangeSet other)
          Returns true if there is overlap between the set and "other", else false.
 RangeSet difference(RangeSet other)
          After this operation, the RangeSet contains the difference of itself and other.
 void ensureCapacity(int cap)
          Make sure the object can hold at least the given number of entries.
 boolean equals(Object obj)
          Returns true the object represents an identical set of ranges as obj.
 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)
          After this operation, the RangeSet contains the intersection of itself and other.
 boolean isEmpty()
           
 long ivbegin(int iv)
           
 long ivend(int iv)
           
 long nval()
           
 void readExternal(ObjectInput in)
           
 void remove(long a, long b)
          After this operation, the RangeSet contains the difference of itself and [a;b[.
 void setTo(RangeSet other)
           
 void setToDifference(RangeSet a, RangeSet b)
          After this operation, the RangeSet contains the difference of RangeSets a and b.
 void setToIntersection(RangeSet a, RangeSet b)
          After this operation, the RangeSet contains the intersection of RangeSets a and b.
 void setToUnion(RangeSet a, RangeSet b)
          After this operation, the RangeSet contains the union of RangeSets a and b.
 int size()
           
 long[] toArray()
          Creates an array cointainig all the numbers in the RangeSet.
 String toString()
           
 void trimSize()
          Shrinks the array for the entries to minimum size.
 RangeSet union(RangeSet other)
          After this operation, the RangeSet contains the union of itself and other.
 RangeSet.ValueIterator valueIterator()
          Returns a ValueIterator, which iterates over all individual numbers in the RangeSet.
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RangeSet

public RangeSet()
Construct new object with space for 8 entries (4 ranges).


RangeSet

public RangeSet(int cap)
Construct new object with a given initial number of entries.

Parameters:
cap - number of initially reserved entries.

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

setTo

public void setTo(RangeSet other)

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.


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 range
b - one-after-last long in range

append

public void append(RangeSet other)
Append an entire range set to the object.


size

public int size()
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.


setToUnion

public void setToUnion(RangeSet a,
                       RangeSet b)
After this operation, the RangeSet contains the union of RangeSets a and b.


setToIntersection

public void setToIntersection(RangeSet a,
                              RangeSet b)
After this operation, the RangeSet contains the intersection of RangeSets a and b.


setToDifference

public void setToDifference(RangeSet a,
                            RangeSet b)
After this operation, the RangeSet contains the difference of RangeSets a and b.


union

public RangeSet union(RangeSet other)
After this operation, the RangeSet contains the union of itself and other.


intersection

public RangeSet intersection(RangeSet other)
After this operation, the RangeSet contains the intersection of itself and other.


difference

public RangeSet difference(RangeSet other)
After this operation, the RangeSet contains the difference of itself and other.


contains

public boolean contains(long a)
Returns true if a is contained in the set, else false.


containsAll

public boolean containsAll(long a,
                           long b)
Returns true if all numbers [a;b[ are contained in the set, else false.


containsAny

public boolean containsAny(long a,
                           long b)
Returns true if any of the numbers [a;b[ are contained in the set, else false.


containsAll

public boolean containsAll(RangeSet other)
Returns true if the set completely contains "other", else false.


containsAny

public boolean containsAny(RangeSet other)
Returns true if there is overlap between the set and "other", else false.


equals

public boolean equals(Object obj)
Returns true the object represents an identical set of ranges as obj.

Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class 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[.


remove

public void remove(long a,
                   long b)
After this operation, the RangeSet contains the difference of itself and [a;b[.


toArray

public long[] toArray()
Creates an array cointainig 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.


toString

public String toString()
Overrides:
toString in class Object

valueIterator

public RangeSet.ValueIterator valueIterator()
Returns a ValueIterator, which iterates over all individual numbers in the RangeSet.


writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

"Built from revision exported"