Class Domain


  • public class Domain
    extends java.lang.Object
    We call domain any subset of Int64 = [kint64min, kint64max].

    This class can be used to represent such set efficiently as a sorted and
    non-adjacent list of intervals. This is efficient as long as the size of such
    list stays reasonable.

    In the comments below, the domain of *this will always be written 'D'.
    Note that all the functions are safe with respect to integer overflow.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean swigCMemOwn  
    • Constructor Summary

      Constructors 
      Constructor Description
      Domain()
      By default, Domain will be empty.
      Domain​(long value)
      Constructor for the common case of a singleton domain.
      Domain​(long cPtr, boolean cMemoryOwn)  
      Domain​(long left, long right)
      Constructor for the common case of a single interval [left, right].
      If left > right, this will result in the empty domain.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Domain additionWith​(Domain domain)
      Returns {x ∈ Int64, ∃ a ∈ D, ∃ b ∈ domain, x = a + b}.
      static Domain allValues()
      Returns the full domain Int64.
      Domain complement()
      Returns the set Int64 ∖ D.
      boolean contains​(long value)
      Returns true iff value is in Domain.
      void delete()  
      protected void finalize()  
      long[] flattenedIntervals()
      This method returns the flattened list of interval bounds of the domain.

      Thus the domain {0, 1, 2, 5, 8, 9, 10} will return [0, 2, 5, 5,
      8, 10] (as a C++ std::vector<int64_t>, as a java or C# long[], as
      a python list of integers).
      static Domain fromFlatIntervals​(long[] flat_intervals)
      This method is available in Python, Java and .NET.
      static Domain fromIntervals​(long[][] intervals)
      This method is available in Python, Java and .NET.
      static Domain fromValues​(long[] values)
      Creates a domain from the union of an unsorted list of integer values.
      Input values may be repeated, with no consequence on the output
      static long getCPtr​(Domain obj)  
      Domain intersectionWith​(Domain domain)
      Returns the intersection of D and domain.
      boolean isEmpty()
      Returns true if this is the empty set.
      long max()
      Returns the max value of the domain.
      The domain must not be empty.
      long min()
      Returns the min value of the domain.
      The domain must not be empty.
      Domain negation()
      Returns {x ∈ Int64, ∃ e ∈ D, x = -e}.

      Note in particular that if the negation of Int64 is not Int64 but
      Int64 \ {kint64min} !!
      long size()
      Returns the number of elements in the domain.
      static long swigRelease​(Domain obj)  
      java.lang.String toString()
      Returns a compact string of a vector of intervals like "[1,4][6][10,20]".
      Domain unionWith​(Domain domain)
      Returns the union of D and domain.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • swigCMemOwn

        protected transient boolean swigCMemOwn
    • Constructor Detail

      • Domain

        public Domain​(long cPtr,
                      boolean cMemoryOwn)
      • Domain

        public Domain()
        By default, Domain will be empty.
      • Domain

        public Domain​(long value)
        Constructor for the common case of a singleton domain.
      • Domain

        public Domain​(long left,
                      long right)
        Constructor for the common case of a single interval [left, right].
        If left > right, this will result in the empty domain.
    • Method Detail

      • getCPtr

        public static long getCPtr​(Domain obj)
      • swigRelease

        public static long swigRelease​(Domain obj)
      • finalize

        protected void finalize()
        Overrides:
        finalize in class java.lang.Object
      • delete

        public void delete()
      • allValues

        public static Domain allValues()
        Returns the full domain Int64.
      • fromValues

        public static Domain fromValues​(long[] values)
        Creates a domain from the union of an unsorted list of integer values.
        Input values may be repeated, with no consequence on the output
      • fromIntervals

        public static Domain fromIntervals​(long[][] intervals)
        This method is available in Python, Java and .NET. It allows
        building a Domain object from a list of intervals (long[][] in Java and
        .NET, [[0, 2], [5, 5], [8, 10]] in python).
      • fromFlatIntervals

        public static Domain fromFlatIntervals​(long[] flat_intervals)
        This method is available in Python, Java and .NET. It allows
        building a Domain object from a flattened list of intervals
        (long[] in Java and .NET, [0, 2, 5, 5, 8, 10] in python).
      • flattenedIntervals

        public long[] flattenedIntervals()
        This method returns the flattened list of interval bounds of the domain.

        Thus the domain {0, 1, 2, 5, 8, 9, 10} will return [0, 2, 5, 5,
        8, 10] (as a C++ std::vector<int64_t>, as a java or C# long[], as
        a python list of integers).
      • isEmpty

        public boolean isEmpty()
        Returns true if this is the empty set.
      • size

        public long size()
        Returns the number of elements in the domain. It is capped at kint64max
      • min

        public long min()
        Returns the min value of the domain.
        The domain must not be empty.
      • max

        public long max()
        Returns the max value of the domain.
        The domain must not be empty.
      • contains

        public boolean contains​(long value)
        Returns true iff value is in Domain.
      • complement

        public Domain complement()
        Returns the set Int64 ∖ D.
      • negation

        public Domain negation()
        Returns {x ∈ Int64, ∃ e ∈ D, x = -e}.

        Note in particular that if the negation of Int64 is not Int64 but
        Int64 \ {kint64min} !!
      • intersectionWith

        public Domain intersectionWith​(Domain domain)
        Returns the intersection of D and domain.
      • unionWith

        public Domain unionWith​(Domain domain)
        Returns the union of D and domain.
      • additionWith

        public Domain additionWith​(Domain domain)
        Returns {x ∈ Int64, ∃ a ∈ D, ∃ b ∈ domain, x = a + b}.
      • toString

        public java.lang.String toString()
        Returns a compact string of a vector of intervals like "[1,4][6][10,20]".
        Overrides:
        toString in class java.lang.Object