Module interval :: Class BaseIntervalSet
[show private | hide private]
[frames | no frames]

Type BaseIntervalSet

object --+
         |
        BaseIntervalSet

Known Subclasses:
FrozenIntervalSet, IntervalSet

Base class for IntervalSet and FrozenIntervalSet.
Method Summary
  __init__(self, items)
Initializes a BaseIntervalSet
  __add__(self, other)
Returns the union of two IntervalSets
  __and__(self, other)
Returns the intersection of self and other.
  __cmp__(self, other)
Compares two BaseIntervalSets
  __contains__(self, obj)
Tells whether the BaseIntervalSet contains the given value
  __eq__(self, other)
Tests if two BaseIntervalSets are equivalent
  __ge__(self, other)
Tests if the given operand is a superset or is equal to the object
  __getitem__(self, index)
Gets the interval at the given index
  __gt__(self, other)
Tests if the given operand is a superset of the object
  __invert__(self)
Returns the disjoint set of self
  __iter__(self)
Returns an iterator over the intervals in the set
  __le__(self, other)
Tests if the given operand is a subset or is equal to the object
  __len__(self)
Returns the number of intervals contained in the object
  __lt__(self, other)
Tests if the given operand is a subset of the object
  __ne__(self, other)
Tests if two BaseIntervalSets are not equivalent
  __or__(self, other)
Returns the union of two IntervalSets.
  __str__(self)
Returns a string representation of the object
  __sub__(self, other)
Subtracts intervals in the given object from the object and returns the result
  __xor__(self, other)
Returns the exclusive or of two IntervalSets.
  all(cls)
Returns an interval set containing all values (Class method)
  between(cls, a, b, closed)
Returns an IntervalSet of all values between a and b. (Class method)
  bounds(self)
Returns an interval that encompasses the entire BaseIntervalSet
  copy(self)
Returns a copy of the object
  difference(self, other)
Returns the difference between the object and the given object
  empty(cls)
Returns an interval set containing no values. (Class method)
  greater_than(cls, n)
Returns an IntervalSet containing values greater than the given value (Class method)
  greater_than_or_equal_to(cls, n)
Returns an IntervalSet containing values greater than or equal to the given value (Class method)
  intersection(self, other)
Returns the intersection between the object and the given value
  issubset(self, other)
Tells if the given object is a subset of the object
  issuperset(self, other)
Tells whether the given object is a superset of the object
  less_than(cls, n)
Returns an IntervalSet containing values less than the given value (Class method)
  less_than_or_equal_to(cls, n, closed)
Returns an IntervalSet containing values less than or equal to the given value (Class method)
  lower_bound(self)
Returns the lower boundary of the BaseIntervalSet
  lower_closed(self)
Returns a boolean telling whether the lower bound is closed or not
  not_equal_to(cls, n)
Returns an IntervalSet of all values not equal to n (Class method)
  symmetric_difference(self, other)
Returns the exclusive or of the given value with the object
  union(self, other)
Returns the union of the given value with the object
  upper_bound(self)
Returns the upper boundary of the BaseIntervalSet
  upper_closed(self)
Returns a boolean telling whether the upper bound is closed or not
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value

Instance Method Details

__init__(self, items=[])
(Constructor)

Initializes a BaseIntervalSet

This function initializes an IntervalSet. It takes an iterable object, such as a set, list, or generator. The elements returned by the iterator are interpreted as intervals for Interval objects and discrete values for all other values.

If no parameters are provided, then an empty IntervalSet is constructed.
>>> print IntervalSet() # An empty set
<Empty>
Interval objects arguments are added directly to the IntervalSet.
>>> print IntervalSet([Interval(4, 6, lower_closed=False)])
(4..6]

>>> print IntervalSet([Interval.less_than_or_equal_to(2)])
(...2]
Each non-Interval value of an iterator is added as a discrete value.
>>> print IntervalSet(set([3, 7, 2, 1]))
1,2,3,7

>>> print IntervalSet(["Bob", "Fred", "Mary"])
'Bob','Fred','Mary'

>>> print IntervalSet(range(10))
0,1,2,3,4,5,6,7,8,9

>>> print IntervalSet(
...   Interval.between(l, u) for l, u in [(10, 20), (30, 40)])
[10..20],[30..40]
Overrides:
__builtin__.object.__init__

__add__(self, other)
(Addition operator)

Returns the union of two IntervalSets
>>> empty     = IntervalSet()
>>> negatives = IntervalSet.less_than(0)
>>> positives = IntervalSet.greater_than(0)
>>> naturals  = IntervalSet.greater_than_or_equal_to(0)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.not_equal_to(0)
>>> empty     = IntervalSet.empty()
>>> print evens + positives
-8,-6,-4,-2,[0...)

>>> print negatives + zero
(...0]

>>> print empty + negatives
(...0)

>>> print empty + naturals
[0...)

>>> print nonzero + evens
(...)

__and__(self, other)
(And operator)

Returns the intersection of self and other.
>>> negatives = IntervalSet.less_than(0)
>>> positives = IntervalSet.greater_than(0)
>>> naturals  = IntervalSet.greater_than_or_equal_to(0)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.not_equal_to(0)
>>> empty     = IntervalSet.empty()
>>> print naturals and naturals
[0...)

>>> print evens & zero
0

>>> print negatives & zero
<Empty>

>>> print nonzero & positives
(0...)

>>> print empty & zero
<Empty>

>>> positives & [0]
Traceback (most recent call last):

    ...

TypeError: unsupported operand type(s) for &: expected BaseIntervalSet

__cmp__(self, other)
(Comparison operator)

Compares two BaseIntervalSets

Like set, raises a TypeError when invoked. >>> IntervalSet().__cmp__(IntervalSet()) Traceback (most recent call last): ... TypeError: cannot compare BaseIntervalSets using cmp()

__contains__(self, obj)
(In operator)

Tells whether the BaseIntervalSet contains the given value

Returns True if obj is contained in self. obj can be either a discrete value, a sequence, or an Interval.
>>> some = IntervalSet([
...   2, 8, Interval(12, 17, upper_closed=False), 
...   Interval.greater_than(17)])
>>> all = IntervalSet.all()
>>> empty = IntervalSet.empty()
>>> 17 in empty
False

>>> 17 in all
True

>>> 17 in some
False

>>> r = Interval(100, 400, upper_closed=False)
>>> r in empty
False

>>> r in all
True

>>> r in some
True

__eq__(self, other)
(Equality operator)

Tests if two BaseIntervalSets are equivalent

Two IntervalSets are identical if they contain the exact same sets.
>>> IntervalSet([4]) == IntervalSet([1])
False

>>> IntervalSet([5]) == IntervalSet([5])
True

>>> s1 = IntervalSet.between(4, 7)
>>> s2 = IntervalSet([Interval(4, 7, upper_closed=False)])
>>> s1 == s2
False

>>> s2.add(7)
>>> s1 == s2
True

>>> s1.clear()
>>> s1 == IntervalSet.empty()
True
An IntervalSet, when compared to a non-BaseIntervalSet, yields False
>>> s1 == [0, 2, 7, 4]
False

>>> IntervalSet([3, 4, 5]) == set([3, 4, 5])
False

>>> IntervalSet([3, 4, 5]) == [3, 4, 5, 3]
False

>>> IntervalSet([3]) == 3
False

__ge__(self, other)
(Greater-than-or-equals operator)

Tests if the given operand is a superset or is equal to the object

To test if a set is a superset of another, you can use the >= operator. I don't like this, personally, but in my attempt to implement a set-like object, I've duplicated this functionality.
>>> zero = IntervalSet([0])
>>> positives = IntervalSet.greater_than(0)
>>> naturals = IntervalSet.greater_than_or_equal_to(0)
>>> negatives = IntervalSet.less_than(0)
>>> r = IntervalSet.between(3, 6)
>>> r2 = IntervalSet.between(-8, -2)
>>> zero >= positives
False

>>> zero >= naturals
False

>>> positives >= zero
False

>>> r >= zero
False

>>> r >= positives
False

>>> positives >= r
True

>>> negatives >= IntervalSet.all()
False

>>> r2 >= negatives
False

>>> negatives >= positives
False

>>> negatives >= [-2, -63]
Traceback (most recent call last):

    ...

TypeError: unsupported operand type(s) for >=: expected BaseIntervalSet

__getitem__(self, index)
(Indexing operator)

Gets the interval at the given index

Unlike sets, which do not have ordering, BaseIntervalSets do. Therefore, indexing was implemented. Intervals are stored in order, starting with that with the left-most lower bound to that with the right-most.
>>> IntervalSet()[0]
Traceback (most recent call last):

    ...

IndexError: Index is out of range

>>> interval = IntervalSet.greater_than(5)
>>> print interval[0]
(5...)

>>> print interval[1]
Traceback (most recent call last):

    ...

IndexError: Index is out of range

>>> print interval[-1]
(5...)

>>> interval = IntervalSet([3, 6])
>>> print interval[1]
6

>>> print interval[0]
3

>>> print interval[2]
Traceback (most recent call last):

    ...

IndexError: Index is out of range

__gt__(self, other)
(Greater-than operator)

Tests if the given operand is a superset of the object

To test if a set is a superset of another, but not equal to it, you can use the > operator. I don't like this, personally, but in my attempt to implement a set-like object, I've duplicated this functionality.
>>> zero = IntervalSet([0])
>>> positives = IntervalSet.greater_than(0)
>>> naturals = IntervalSet.greater_than_or_equal_to(0)
>>> negatives = IntervalSet.less_than(0)
>>> r = IntervalSet.between(3, 6)
>>> r2 = IntervalSet.between(-8, -2)
>>> zero > positives
False

>>> zero > naturals
False

>>> positives > zero
False

>>> r > zero
False

>>> r > positives
False

>>> positives > r
True

>>> negatives > IntervalSet.all()
False

>>> r2 > negatives
False

>>> negatives > positives
False

>>> positives > positives
False

>>> negatives > [-2, -63]
Traceback (most recent call last):

    ...

TypeError: unsupported operand type(s) for >: expected BaseIntervalSet

__invert__(self)

Returns the disjoint set of self
>>> negatives = IntervalSet.less_than(0)
>>> positives = IntervalSet.greater_than(0)
>>> naturals  = IntervalSet.greater_than_or_equal_to(0)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.not_equal_to(0)
>>> print ~(IntervalSet.empty())
(...)

>>> ~negatives == naturals
True

>>> print ~positives
(...0]

>>> ~naturals == negatives
True

>>> print ~evens
(...-8),(-8..-6),(-6..-4),(-4..-2),(-2..0),(0..2),(2..4),(4..6),(6..8),(8...)

>>> ~zero == nonzero
True

>>> ~nonzero == zero
True

__iter__(self)

Returns an iterator over the intervals in the set
>>> s = IntervalSet(
...   [2, 7, 2, 87, 4, 3, Interval.greater_than(12),
...   Interval.less_than(-2)])
>>> l = set()
>>> for i in s:
...   l.add(str(i))
...
>>> print len(l)
6

>>> "2" in l
True

>>> "7" in l
True

>>> "87" in l
False

>>> "4" in l
True

>>> "3" in l
True

>>> "(12...)" in l
True

>>> "(...-2)" in l
True
Though an IntervalSet contains only Interval objects, we pretend that they contain discrete objects as well.
>>> s = IntervalSet([2])
>>> for i in s:
...   i == 2
...

True

__le__(self, other)
(Less-than-or-equals operator)

Tests if the given operand is a subset or is equal to the object

To test if a set is a subset of another, you can use the <= operator. I don't like this, personally, but in my attempt to implement a set-like object, I've duplicated this functionality.
>>> zero = IntervalSet([0])
>>> positives = IntervalSet.greater_than(0)
>>> naturals = IntervalSet.greater_than_or_equal_to(0)
>>> negatives = IntervalSet.less_than(0)
>>> r = IntervalSet.between(3, 6)
>>> r2 = IntervalSet.between(-8, -2)
>>> zero <= positives
False

>>> zero <= naturals
True

>>> positives <= zero
False

>>> r <= zero
False

>>> r <= positives
True

>>> positives <= r
False

>>> negatives <= IntervalSet.all()
True

>>> r2 <= negatives
True

>>> negatives <= positives
False

>>> zero <= [0, 2, 6, 7]
Traceback (most recent call last):

    ...

TypeError: unsupported operand type(s) for <=: expected BaseIntervalSet

>>> positives <= positives
True

__len__(self)
(Length operator)

Returns the number of intervals contained in the object
>>> len(IntervalSet.empty())
0

>>> len(IntervalSet.all())
1

>>> len(IntervalSet([2, 6, 34]))
3

>>> len(IntervalSet.greater_than(0))
1

>>> nonempty = IntervalSet([3])
>>> if IntervalSet.empty():
...     print "Non-empty"
>>> if nonempty:
...     print "Non-empty"
Non-empty

__lt__(self, other)
(Less-than operator)

Tests if the given operand is a subset of the object

To test if a set is a subset that's not equal to another, you can use the < operator. I don't like this, personally, but in my attempt to implement a set-like object, I've duplicated this functionality.
>>> zero = IntervalSet([0])
>>> positives = IntervalSet.greater_than(0)
>>> naturals = IntervalSet.greater_than_or_equal_to(0)
>>> negatives = IntervalSet.less_than(0)
>>> r = IntervalSet.between(3, 6)
>>> r2 = IntervalSet.between(-8, -2)
>>> zero < positives
False

>>> zero < naturals
True

>>> positives < zero
False

>>> r < zero
False

>>> r < positives
True

>>> positives < r
False

>>> negatives < IntervalSet.all()
True

>>> r2 < negatives
True

>>> negatives < positives
False

>>> zero < [0, 2, 6, 7]
Traceback (most recent call last):

    ...

TypeError: unsupported operand type(s) for <: expected BaseIntervalSet

>>> positives < positives
False

__ne__(self, other)

Tests if two BaseIntervalSets are not equivalent

Two IntervalSets are not identical if they contain different values or Intervals.
>>> IntervalSet([4]) != IntervalSet([1])
True

>>> IntervalSet([5]) != IntervalSet([5])
False

>>> s1 = IntervalSet.between(4, 7)
>>> s2 = IntervalSet([Interval(4, 7, upper_closed=False)])
>>> s1 != s2
True

>>> s2.add(7)
>>> s1 != s2
False

>>> s1.clear()
>>> s1 != IntervalSet.empty()
False
An IntervalSet can also be compared to any other value. The result is always True.
>>> s1 != [0, 2, 7, 4]
True

>>> IntervalSet([3, 4, 5]) != set([3, 4, 5])
True

>>> IntervalSet([3, 4, 5]) != [3, 4, 5, 3]
True

__or__(self, other)
(Or operator)

Returns the union of two IntervalSets.
>>> negatives = IntervalSet.less_than(0)
>>> positives = IntervalSet.greater_than(0)
>>> naturals  = IntervalSet.greater_than_or_equal_to(0)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.not_equal_to(0)
>>> empty     = IntervalSet.empty()
>>> all       = IntervalSet.all()
>>> print evens | positives
-8,-6,-4,-2,[0...)

>>> print negatives | zero
(...0]

>>> print empty | negatives
(...0)

>>> print empty | naturals
[0...)

>>> print nonzero | evens
(...)

>>> print negatives | range(5)
Traceback (most recent call last):

    ...

TypeError: unsupported operand type(s) for |: expected BaseIntervalSet

__str__(self)
(Informal representation operator)

Returns a string representation of the object

This function shows a string representation of an IntervalSet. The string is shown sorted, with all intervals normalized.
>>> print IntervalSet()
<Empty>

>>> print IntervalSet([62])
62

>>> print IntervalSet([62, 56])
56,62

>>> print IntervalSet([23, Interval(26, 32, upper_closed=False)])
23,[26..32)

>>> print IntervalSet.less_than(3) + IntervalSet.greater_than(3)
(...3),(3...)

>>> print IntervalSet([Interval.less_than_or_equal_to(6)])
(...6]
Overrides:
__builtin__.object.__str__

__sub__(self, other)
(Subtraction operator)

Subtracts intervals in the given object from the object and returns the result
>>> negatives = IntervalSet.less_than(0)
>>> positives = IntervalSet.greater_than(0)
>>> naturals  = IntervalSet.greater_than_or_equal_to(0)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.not_equal_to(0)
>>> empty     = IntervalSet.empty()
>>> all       = IntervalSet.all()
>>> print evens - nonzero
0

>>> print empty - naturals
<Empty>

>>> print zero - naturals
<Empty>

>>> print positives - zero
(0...)

>>> print naturals - negatives
[0...)

>>> print all - zero
(...0),(0...)

>>> all - zero == nonzero
True

>>> naturals - [0]
Traceback (most recent call last):

    ...

TypeError: unsupported operand type(s) for -: expected BaseIntervalSet

__xor__(self, other)

Returns the exclusive or of two IntervalSets.
>>> negatives = IntervalSet.less_than(0)
>>> positives = IntervalSet.greater_than(0)
>>> naturals  = IntervalSet.greater_than_or_equal_to(0)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.not_equal_to(0)
>>> empty     = IntervalSet.empty()
>>> print nonzero ^ naturals
(...0]

>>> print zero ^ negatives
(...0]

>>> print positives ^ empty
(0...)

>>> print evens ^ zero
-8,-6,-4,-2,2,4,6,8

>>> negatives ^ [0]
Traceback (most recent call last):

    ...

TypeError: unsupported operand type(s) for ^: expected BaseIntervalSet

bounds(self)

Returns an interval that encompasses the entire BaseIntervalSet
>>> print IntervalSet([Interval.between(4, 6), 2, 12]).bounds()
[2..12]

>>> print IntervalSet().bounds()
<Empty>

>>> print IntervalSet.all().bounds()
(...)

copy(self)

Returns a copy of the object
>>> s = IntervalSet(
...   [7, 2, 3, 2, 6, 2, Interval.greater_than(3)])
>>> s2 = s.copy()
>>> s == s2
True

>>> s = FrozenIntervalSet(
...   [7, 2, 3, 2, 6, 2, Interval.greater_than(3)])
>>> s2 = s.copy()
>>> s == s2
True

difference(self, other)

Returns the difference between the object and the given object

Returns all values of self minus all matching values in other. It is identical to the - operator, only it accepts any iterable as the operand.
>>> negatives = IntervalSet.less_than(0)
>>> positives = IntervalSet.greater_than(0)
>>> naturals  = IntervalSet.greater_than_or_equal_to(0)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.not_equal_to(0)
>>> empty     = IntervalSet.empty()
>>> all       = IntervalSet.all()
>>> print evens.difference(nonzero)
0

>>> print empty.difference(naturals)
<Empty>

>>> print zero.difference(naturals)
<Empty>

>>> print positives.difference(zero)
(0...)

>>> print naturals.difference(negatives)
[0...)

>>> print all.difference(zero)
(...0),(0...)

>>> all.difference(zero) == nonzero
True

>>> naturals.difference([0]) == positives
True

intersection(self, other)

Returns the intersection between the object and the given value

This function returns the intersection of self and other. It is identical to the & operator, except this function accepts any iterable as an operand, and & accepts only another BaseIntervalSet.
>>> negatives = IntervalSet.less_than(0)
>>> positives = IntervalSet.greater_than(0)
>>> naturals  = IntervalSet.greater_than_or_equal_to(0)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.not_equal_to(0)
>>> empty     = IntervalSet.empty()
>>> print naturals.intersection(naturals)
[0...)

>>> print evens.intersection(zero)
0

>>> print negatives.intersection(zero)
<Empty>

>>> print nonzero.intersection(positives)
(0...)

>>> print empty.intersection(zero)
<Empty>

issubset(self, other)

Tells if the given object is a subset of the object

Returns true if self is a subset of other. other can be any iterable object.
>>> zero = IntervalSet([0])
>>> positives = IntervalSet.greater_than(0)
>>> naturals = IntervalSet.greater_than_or_equal_to(0)
>>> negatives = IntervalSet.less_than(0)
>>> r = IntervalSet.between(3, 6)
>>> r2 = IntervalSet.between(-8, -2)
>>> zero.issubset(positives)
False

>>> zero.issubset(naturals)
True

>>> positives.issubset(zero)
False

>>> r.issubset(zero)
False

>>> r.issubset(positives)
True

>>> positives.issubset(r)
False

>>> negatives.issubset(IntervalSet.all())
True

>>> r2.issubset(negatives)
True

>>> negatives.issubset(positives)
False

>>> zero.issubset([0, 1, 2, 3])
True

issuperset(self, other)

Tells whether the given object is a superset of the object

Returns true if self is a superset of other. other can be any iterable object.
>>> zero = IntervalSet([0])
>>> positives = IntervalSet.greater_than(0)
>>> naturals = IntervalSet.greater_than_or_equal_to(0)
>>> negatives = IntervalSet.less_than(0)
>>> r = IntervalSet.between(3, 6)
>>> r2 = IntervalSet.between(-8, -2)
>>> zero.issuperset(positives)
False

>>> zero.issuperset(naturals)
False

>>> positives.issuperset(zero)
False

>>> r.issuperset(zero)
False

>>> r.issuperset(positives)
False

>>> positives.issuperset(r)
True

>>> negatives.issuperset(IntervalSet.all())
False

>>> r2.issuperset(negatives)
False

>>> negatives.issuperset(positives)
False

>>> negatives.issuperset([-2, -632])
True

lower_bound(self)

Returns the lower boundary of the BaseIntervalSet
>>> IntervalSet([Interval.between(4, 6), 2, 12]).lower_bound()
2

>>> IntervalSet().lower_bound()
Traceback (most recent call last):

    ...

IndexError: The BaseIntervalSet is empty

>>> IntervalSet.all().lower_bound()
-Inf

lower_closed(self)

Returns a boolean telling whether the lower bound is closed or not
>>> IntervalSet([Interval.between(4, 6), 2, 12]).lower_closed()
True

>>> IntervalSet().lower_closed()
Traceback (most recent call last):

    ...

IndexError: The BaseIntervalSet is empty

>>> IntervalSet.all().lower_closed()
False

symmetric_difference(self, other)

Returns the exclusive or of the given value with the object

This function returns the exclusive or of two IntervalSets. It is identical to the ^ operator, except it accepts any iterable object for the operand.
>>> negatives = IntervalSet.less_than(0)
>>> positives = IntervalSet.greater_than(0)
>>> naturals  = IntervalSet.greater_than_or_equal_to(0)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.not_equal_to(0)
>>> empty     = IntervalSet.empty()
>>> print nonzero.symmetric_difference(naturals)
(...0]

>>> print zero.symmetric_difference(negatives)
(...0]

>>> print positives.symmetric_difference(empty)
(0...)

>>> print evens.symmetric_difference(zero)
-8,-6,-4,-2,2,4,6,8

>>> print evens.symmetric_difference(range(0, 9, 2))
-8,-6,-4,-2

union(self, other)

Returns the union of the given value with the object

This function returns the union of a BaseIntervalSet and an iterable object. It is identical to the | operator, except that | only accepts a BaseIntervalSet operand and union accepts any iterable.
>>> negatives = IntervalSet.less_than(0)
>>> positives = IntervalSet.greater_than(0)
>>> naturals  = IntervalSet.greater_than_or_equal_to(0)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.not_equal_to(0)
>>> empty     = IntervalSet.empty()
>>> all       = IntervalSet.all()
>>> print evens.union(positives)
-8,-6,-4,-2,[0...)

>>> print negatives.union(zero)
(...0]

>>> print empty.union(negatives)
(...0)

>>> print empty.union(naturals)
[0...)

>>> print nonzero.union(evens)
(...)

>>> print negatives.union(range(5))
(...0],1,2,3,4

upper_bound(self)

Returns the upper boundary of the BaseIntervalSet
>>> IntervalSet([Interval.between(4, 6), 2, 12]).upper_bound()
12

>>> IntervalSet().upper_bound()
Traceback (most recent call last):

    ...

IndexError: The BaseIntervalSet is empty

>>> IntervalSet.all().upper_bound()
Inf

upper_closed(self)

Returns a boolean telling whether the upper bound is closed or not
>>> IntervalSet([Interval.between(4, 6), 2, 12]).upper_closed()
True

>>> IntervalSet().upper_closed()
Traceback (most recent call last):

    ...

IndexError: The BaseIntervalSet is empty

>>> IntervalSet.all().upper_closed()
False

Class Method Details

all(cls)

Returns an interval set containing all values
>>> print IntervalSet.all()
(...)

between(cls, a, b, closed=True)

Returns an IntervalSet of all values between a and b.

If closed is True, then the endpoints are included; otherwise, they aren't.
>>> print IntervalSet.between(0, 100)
[0..100]

>>> print IntervalSet.between(-1, 1)
[-1..1]

empty(cls)

Returns an interval set containing no values.
>>> print IntervalSet.empty()
<Empty>

greater_than(cls, n)

Returns an IntervalSet containing values greater than the given value
>>> print IntervalSet.greater_than(0)
(0...)

>>> print IntervalSet.greater_than(-23)
(-23...)

greater_than_or_equal_to(cls, n)

Returns an IntervalSet containing values greater than or equal to the given value
>>> print IntervalSet.greater_than_or_equal_to(0)
[0...)

>>> print IntervalSet.greater_than_or_equal_to(-23)
[-23...)

less_than(cls, n)

Returns an IntervalSet containing values less than the given value
>>> print IntervalSet.less_than(0)
(...0)

>>> print IntervalSet.less_than(-23)
(...-23)

less_than_or_equal_to(cls, n, closed=False)

Returns an IntervalSet containing values less than or equal to the given value
>>> print IntervalSet.less_than_or_equal_to(0)
(...0]

>>> print IntervalSet.less_than_or_equal_to(-23)
(...-23]

not_equal_to(cls, n)

Returns an IntervalSet of all values not equal to n
>>> print IntervalSet.not_equal_to(0)
(...0),(0...)

>>> print IntervalSet.not_equal_to(-23)
(...-23),(-23...)

Generated by Epydoc 2.1 on Wed Nov 9 22:22:38 2005 http://epydoc.sf.net