Package cds.moc

Class Range

java.lang.Object
cds.moc.Range
All Implemented Interfaces:
Comparable<Range>
Direct Known Subclasses:
Range2

public class Range extends Object implements Comparable<Range>
Adaptation & 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 Classes
    Modifier and Type
    Class
    Description
    static interface 
    Interface describing an iterator for going through all values in a Range object.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final Range.ValueIterator
     
    long[]
    Sorted list of interval boundaries.
    int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    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)
     
    Range(Range other)
    Construct new object from another Range
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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(Range other)
    Append an entire range set to the object.
    long
    begins(int i)
     
    void
    Checks the object for internal consistency.
    void
    Remove all entries in the set.
    int
    Fernique extension
    complement(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
    contains(Range other)
     
    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émoire
    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
    RAM usage (in bytes)
    int
     
    static int
    ilog2(long arg)
    Integer base 2 logarithm.
    int
    indexOf(long val)
    Returns an internal representation of the interval a number belongs to.
    Return the intersection of this Range and other.
    boolean
     
    int
     
    long
     
    boolean
    overlaps(long a, long b)
     
    boolean
    overlaps(Range other)
    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 vector
    void
    Sort and remove useless ranges and trim the buffer => Warning: not thread safe
    protected static int
    strategy(int sza, int szb)
    Estimate a good strategy for set operations involving two Ranges.
    long[]
    Creates an array containing all the numbers in the Range.
     
    void
    Shrinks the array for the entries to minimum size, if it is more than twice the minimum size
    void
    Shrinks the array for the entries to minimum size.
    union(Range other)
    Return the union of this Range and other.
    Returns a ValueIterator, which iterates over all individual numbers in the Range.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • r

      public long[] r
      Sorted list of interval boundaries.
    • sz

      public int sz
    • EMPTY_ITER

      protected static final Range.ValueIterator 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

      public Range(Range other)
      Construct new object from another Range
  • Method Details

    • compareTo

      public int compareTo(Range o1)
      Fernique extension
      Specified by:
      compareTo in interface Comparable<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

      public Range 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é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 range
      b - one-after-last long in range
    • append

      public void append(Range 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.
    • 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

      protected static boolean generalAllOrNothing(Range a, Range b, boolean flip_a, boolean flip_b)
    • complement

      public Range complement(long min, long max)
    • union

      public Range union(Range other)
      Return the union of this Range and other.
    • intersection

      public Range intersection(Range other)
      Return the intersection of this Range and other.
    • difference

      public Range difference(Range other)
      Return the difference of this Range and other.
    • contains

      public boolean contains(Range other)
    • overlaps

      public boolean overlaps(Range other)
      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

      public boolean equals(Object 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.
    • add

      public void add(Range m)
    • 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

      public long[] toArray() throws Exception
      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

      public static Range fromArray(long[] v)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • valueIterator

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