Package cds.moc
Class Range
java.lang.Object
cds.moc.Range
- All Implemented Interfaces:
Comparable<Range>
- Direct Known Subclasses:
Range2
Adaptation invalid input: '&' extension of RangeSet from Healpix.essentials lib (GNU General Public License)
from Martin Reinecke [Max-Planck-Society] built from Jan Kotek's "LongRange" class
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Interface describing an iterator for going through all values in a Range object. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Range.ValueIterator
long[]
Sorted list of interval boundaries.int
-
Constructor Summary
ConstructorsConstructorDescriptionRange()
Default constuctor with initial space for 4 ranges.Range
(int cap) Construct new object with initial capacity for a given number of ranges.Range
(long[] buf) Construct new object with the provided buffer (not copy).Range
(long[] buf, int size) Construct new object from another Range -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(long a) After this operation, the Range contains the union of itself and [a;a+1[.void
add
(long a, long b) After this operation, the Range contains the union of itself and [a;b[.void
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.long
begins
(int i) void
Checks the object for internal consistency.void
clear()
Remove all entries in the set.int
Fernique extensioncomplement
(long min, long max) 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
degrade
(int shift) Retourne un range dont la précision des intervalles est dégradée en fonction d'un nombre de bits Aggrège les intervalles si nécessaires et ajuste l'occupation mémoiredifference
(Range other) Return the difference of this Range and other.long
ends
(int i) void
ensureCapacity
(int cap) Make sure the object can hold at least the given number of entries.boolean
static Range
fromArray
(long[] v) protected static boolean
generalAllOrNothing
(Range a, Range b, boolean flip_a, boolean flip_b) long
getMem()
RAM usage (in bytes)int
hashCode()
static int
ilog2
(long arg) Integer base 2 logarithm.int
indexOf
(long val) Returns an internal representation of the interval a number belongs to.intersection
(Range other) Return the intersection of this Range and other.boolean
isEmpty()
int
nranges()
long
nval()
boolean
overlaps
(long a, long b) boolean
Returns true if there is overlap between the set and "other", else false.void
push
(long v) Push a single entry at the end of the entry vector.void
remove
(long a) After this operation, the Range contains the difference of itself and [a;a+1[.void
remove
(long a, long b) After this operation, the Range contains the difference of itself and [a;b[.void
resize
(int newsize) Modify the size of the vectorvoid
Sort and remove useless ranges and trim the buffer => Warning: not thread safeprotected static int
strategy
(int sza, int szb) Estimate a good strategy for set operations involving two Ranges.long[]
toArray()
Creates an array containing all the numbers in the Range.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 Range and other.Returns a ValueIterator, which iterates over all individual numbers in the Range.
-
Field Details
-
r
public long[] rSorted list of interval boundaries. -
sz
public int sz -
EMPTY_ITER
-
-
Constructor Details
-
Range
public Range(long[] buf) Construct new object with the provided buffer (not copy). -
Range
public Range(long[] buf, int size) -
Range
public Range()Default constuctor with initial space for 4 ranges. -
Range
public Range(int cap) Construct new object with initial capacity for a given number of ranges. -
Range
Construct new object from another Range
-
-
Method Details
-
compareTo
Fernique extension- Specified by:
compareTo
in interfaceComparable<Range>
-
sortAndFix
public void sortAndFix()Sort and remove useless ranges and trim the buffer => Warning: not thread safe -
getMem
public long getMem()RAM usage (in bytes) -
degrade
Retourne un range dont la précision des intervalles est dégradée en fonction d'un nombre de bits Aggrège les intervalles si nécessaires et ajuste l'occupation mémoire- Parameters:
shift
- Nombre de bits dégradés (1 => dégradation d'un facteur 2, 2 => d'un facteur 4...)- Returns:
- un nouveau Range dégradé
-
checkConsistency
public void checkConsistency()Checks the object for internal consistency. If a problem is detected, an IllegalArgumentException is thrown. -
resize
public void resize(int newsize) Modify the size of the vector -
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 -
indexOf
public int indexOf(long val) Returns an internal representation of the interval a number belongs to.- Parameters:
val
- number whose interval is requested- Returns:
- interval number, starting with -1 (smaller than all numbers in the Range), 0 (first "on" interval), 1 (first "off" interval etc.), up to (and including) sz-1 (larger than all numbers in the Range).
-
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.
-
begins
public long begins(int i) - Returns:
- first number in range iv.
-
ends
public long ends(int i) - Returns:
- one-past-last number in range iv.
-
clear
public void clear()Remove all entries in the set. -
push
public void push(long v) Push a single entry at the end of the entry vector. -
strategy
protected static int strategy(int sza, int szb) Estimate a good strategy for set operations involving two Ranges. -
ilog2
public static int ilog2(long arg) Integer base 2 logarithm. -
generalAllOrNothing
-
complement
-
union
Return the union of this Range and other. -
intersection
Return the intersection of this Range and other. -
difference
Return the difference of this Range and other. -
contains
-
overlaps
Returns true if there is overlap between the set and "other", else false. -
contains
public boolean contains(long a) Returns true if a is contained in the set, else false. -
overlaps
public boolean overlaps(long a, long b) -
contains
public boolean contains(long a, long b) Returns true if all numbers [a;b[ are contained in the set, else false. -
equals
-
hashCode
public int hashCode() -
nval
public long nval()- Returns:
- total number of values (not ranges) in the set.
-
add
-
add
public void add(long a, long b) After this operation, the Range contains the union of itself and [a;b[. -
add
public void add(long a) After this operation, the Range contains the union of itself and [a;a+1[. -
remove
public void remove(long a, long b) After this operation, the Range contains the difference of itself and [a;b[. -
remove
public void remove(long a) After this operation, the Range contains the difference of itself and [a;a+1[. -
toArray
Creates an array containing all the numbers in the Range. Not recommended, because the arrays can become prohibitively large. It is preferrable to use a ValueIterator or explicit loops.- Throws:
Exception
-
fromArray
-
toString
-
valueIterator
Returns a ValueIterator, which iterates over all individual numbers in the Range.
-