NASA - Jet Propulsion Laboratory
    + View the NASA Portal
Search JPL
Jet Propulsion Laboratory Home Earth Solar System Stars & Galaxies Technology
Introduction Background Software Links


healpix.core.base.set
Class LongRangeSet

java.lang.Object
  extended by healpix.core.base.set.LongRangeSet
All Implemented Interfaces:
Serializable, Iterable<Long>

public class LongRangeSet
extends Object
implements Serializable, Iterable<Long>

This class represents range based sets of long values. First and last boundaries are stored in sorted long[] array so it consumes very little place This is essentially equivilent to run length encoding of a bitmap-based set and thus works very well for sets with long runs of integers, but is quite poor for sets with very short runs.

Is readonly, so is thread safe.

To construct new LongRangeSet use LongRangeSetBuilder if our values are sorted. Or use LongSet if our values are unsorted.

Inspired by Justin F. Chapweske and Soren Bak

Author:
Jan Kotek
See Also:
Serialized Form

Constructor Summary
LongRangeSet(long[] values, int size)
          Construct new LongRangeSet from given values Dont use directly, use LongRangeSetBuilder instead This constructor makes integrity check and copyes values into new array.
 
Method Summary
 LongRangeSet complement()
          Create new LongRangeSet with complement (inversion) of values in this set.
 boolean contains(long i)
           
 boolean containsAll(LongIterator iter)
           
 boolean containsAll(long first, long last)
           
 boolean containsAll(LongRangeIterator iter)
           
 boolean containsAny(LongIterator iter)
           
 boolean containsAny(long first, long last)
           
 boolean containsAny(LongRangeIterator iter)
           
 boolean equals(Object obj)
           
 long first()
           
 int hashCode()
           
 LongRangeSet intersect(LongRangeSet rs)
          Construct new LongRangeSet with intersection of values from original set and parameter set.
 boolean isEmpty()
           
 Iterator<Long> iterator()
           
 long last()
           
 LongIterator longIterator()
           
 int rangeCount()
           
 LongRangeIterator rangeIterator()
           
 long size()
           
 LongRangeSet substract(LongRangeSet rs)
          Construct new LongRangeSet with values which are in original set, but not in parameter.
 long[] toArray()
          Convert all items in range set to array.
 LongSet toLongSet()
          Converts to LongSet which can be modified
 String toString()
           
 LongRangeSet union(LongRangeSet rs)
          Create new LongRangeSet which contains union of values from original set and parameter This operation is FAST.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LongRangeSet

public LongRangeSet(long[] values,
                    int size)
Construct new LongRangeSet from given values

Dont use directly, use LongRangeSetBuilder instead

This constructor makes integrity check and copyes values into new array. When LongRangeSet is constructed inside LongRangeSet this operation can be skipped and set can be constructed way faster.

Method Detail

longIterator

public LongIterator longIterator()
Returns:
Iterator over all longs in this set

rangeIterator

public LongRangeIterator rangeIterator()
Returns:
LongRangeIterator over ranges in this set

iterator

public Iterator<Long> iterator()
Specified by:
iterator in interface Iterable<Long>

first

public long first()
Returns:
first element in set
Throws:
NoSuchElementException - if set isEmpty()

last

public long last()
Returns:
last element in set
Throws:
NoSuchElementException - if set isEmpty()

contains

public boolean contains(long i)
Parameters:
i - The integer to check to see if it is in this set..
Returns:
true if i is in the set.

containsAll

public boolean containsAll(long first,
                           long last)

containsAny

public boolean containsAny(long first,
                           long last)

containsAll

public boolean containsAll(LongIterator iter)

containsAny

public boolean containsAny(LongIterator iter)

containsAll

public boolean containsAll(LongRangeIterator iter)

containsAny

public boolean containsAny(LongRangeIterator iter)

toLongSet

public LongSet toLongSet()
Converts to LongSet which can be modified

Returns:
LongSet

size

public long size()
Returns:
number of longs (pixels) in this set. !!NOT number of ranges!!

rangeCount

public int rangeCount()
Returns:
number of ranges in this set

toArray

public long[] toArray()
Convert all items in range set to array. With large set, this method will fail with OutOfMemoryException

Returns:
array of elements in collection

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

complement

public LongRangeSet complement()
Create new LongRangeSet with complement (inversion) of values in this set. Bounds of complement are Long.MIN_VALUE and Long.MAX_VALUE if operation is called twice, original set is produced

This operation is FAST. Requires only one traversal of ranges. It does not decompress RangeSet to pixels.

This operation does not modify original collection.

Returns:
inverted LongRangeSet

union

public LongRangeSet union(LongRangeSet rs)
Create new LongRangeSet which contains union of values from original set and parameter

This operation is FAST. Requires only one traversal of ranges. It does not decompress RangeSet to pixels.

This operation does not modify original collection.

Parameters:
rs - LongRangeSet to make union with
Returns:
LongRangeSet contains union of original set and parameter set

intersect

public LongRangeSet intersect(LongRangeSet rs)
Construct new LongRangeSet with intersection of values from original set and parameter set.

This operation is FAST. Requires only one traversal of ranges. It does not decompress RangeSet to pixels.

This operation does not modify original collection.

Parameters:
rs - The set with which to intersect with this set.
Returns:
new set that represents the intersect of original and parameter set

substract

public LongRangeSet substract(LongRangeSet rs)
Construct new LongRangeSet with values which are in original set, but not in parameter.

[1-5].substract[4-6] == [1-3]

This operation is FAST. Requires only one traversal of ranges. It does not decompress RangeSet to pixels.

This operation does not modify original collection.

Returns:
result of substraction

isEmpty

public boolean isEmpty()
Returns:
true if set does not have any ranges

"Built from revision exported"

Privacy / Copyright
FIRST GOV Contact: NASA Home Page Site Manager:
Webmaster:

CL 03-2650