interval
index
/home/jacob/src/interval/interval.py

The interval module provides the Interval and IntervalSet data types.   
Intervals describe continuous ranges that can be open, closed, half-open,
or infinite.  IntervalSets contain zero to many disjoint sets of 
Intervals.
 
Intervals don't have to pertain to numbers.  They can contain any data 
that is comparable via the Python operators <, <=, ==, >=, and >.  Here's 
an example of how strings can be used with Intervals:
>>> volume1 = Interval.between("A", "Foe")
>>> volume2 = Interval.between("Fog", "McAfee")
>>> volume3 = Interval.between("McDonalds", "Space")
>>> volume4 = Interval.between("Spade", "Zygote")
>>> encyclopedia = IntervalSet([volume1, volume2, volume3, volume4])
>>> mySet = IntervalSet([volume1, volume3, volume4])
>>> "Meteor" in encyclopedia
True
>>> "Goose" in encyclopedia
True
>>> "Goose" in mySet
False
>>> volume2 in (encyclopedia ^ mySet)
True
 
Here's an example of how times can be used with Intervals:
>>> officeHours = IntervalSet.between("08:00", "17:00")
>>> myLunch = IntervalSet.between("11:30", "12:30")
>>> myHours = IntervalSet.between("08:30", "19:30") - myLunch
>>> myHours.issubset(officeHours)
False
>>> "12:00" in myHours
False
>>> "15:30" in myHours
True
>>> inOffice = officeHours & myHours
>>> print inOffice
['08:30','11:30'),('12:30','17:00']
>>> overtime = myHours - officeHours
>>> print overtime
('17:00','19:30']

 
Modules
       
copy

 
Classes
       
BaseIntervalSet
FrozenIntervalSet
IntervalSet
Interval
Largest
Smallest

 
class BaseIntervalSet
    BaseIntervalSet is the base class for IntervalSet and 
FrozenIntervalSet.
 
  Methods defined here:
__add__(self, other)
This function returns the union of two IntervalSets.  It does the 
same thing as __or__.
 
>>> empty     = IntervalSet()
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
This function returns the intersection of self and other.
 
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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
__contains__(self, obj)
Returns True if obj is contained in self.  obj can be either a 
discrete value, a set, or an Interval.
 
>>> some = IntervalSet([
...   2, 8, Interval(12, True, 17, False), 
...   Interval.greaterThan(17)])
>>> all = IntervalSet.all()
>>> empty = IntervalSet.empty()
>>> 17 in empty
False
>>> 17 in all
True
>>> 17 in some
False
>>> r = Interval(100, True, 400, False)
>>> r in empty
False
>>> r in all
True
>>> r in some
True
__eq__(self, other)
Two IntervalSets are identical if they contain the exact same 
sets.  Note that an empty set is never equal to any other set, 
even an empty one.
 
>>> IntervalSet([4]) == IntervalSet([1])
False
>>> IntervalSet([5]) == IntervalSet([5])
True
>>> s1 = IntervalSet.between(4, 7)
>>> s2 = IntervalSet([Interval(4, True, 7, False)])
>>> s1 == s2
False
>>> s2.add(7)
>>> s1 == s2
True
__ge__(self, other)
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.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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
__gt__(self, other)
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.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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
__init__(self, items=[])
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, False, 6, True)])
(4,6]
>>> print IntervalSet([Interval.lessThan(2, True)])
(-~,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]
__invert__(self)
This function returns the disjoint set of self.  In other words,
all values self doesn't include are in the returned set.
 
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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, set([2, 87, 4, 3]), Interval.greaterThan(12),
...   Interval.lessThan(-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
__le__(self, other)
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.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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)
This function returns the number of intervals contained in self.
 
>>> len(IntervalSet.empty())
0
>>> len(IntervalSet.all())
1
>>> len(IntervalSet([2, 6, 34]))
3
>>> len(IntervalSet.greaterThan(0))
1
__lt__(self, other)
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.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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
__nonzero__(self)
An empty IntervalSet is the zero-like value.
 
>>> nonempty = IntervalSet([3])
>>> if IntervalSet.empty():
...     print "Non-empty"
>>> if nonempty:
...     print "Non-empty"
Non-empty
__or__(self, other)
This function returns the union of two IntervalSets.  It does the 
same thing as the __add__ function.
 
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
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, True, 32, False)])
23,[26,32)
>>> print IntervalSet.lessThan(3) + IntervalSet.greaterThan(3)
(-~,3),(3,~)
>>> print IntervalSet([Interval.lessThan(6, True)])
(-~,6]
__sub__(self, other)
Returns all values of self minus all matching values in other.
 
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
This function returns the exclusive or of two IntervalSets.  
 
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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
copy(self)
Returns a copy of the object.
 
>>> s = IntervalSet(
...   [7, 2, 3, set([2, 6, 2]), Interval.greaterThan(3)])
>>> s2 = s.copy()
>>> s == s2
True
>>> s = FrozenIntervalSet(
...   [7, 2, 3, set([2, 6, 2]), Interval.greaterThan(3)])
>>> s2 = s.copy()
>>> s == s2
True
difference(self, other)
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.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
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.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
Returns true if self is a subset of other.  other can be any 
iterable object.
 
>>> zero = IntervalSet([0])
>>> positives = IntervalSet.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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)
Returns true if self is a superset of other.  other can be any
iterable object.
 
>>> zero = IntervalSet([0])
>>> positives = IntervalSet.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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
symmetric_difference(self, other)
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.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
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.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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

Class methods defined here:
all(cls) from __builtin__.classobj
Returns an interval set containing all values.
>>> print IntervalSet.all()
(-~,~)
between(cls, a, b, closed=True) from __builtin__.classobj
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) from __builtin__.classobj
Returns an interval set containing no values.
>>> print IntervalSet.empty()
<Empty>
greaterThan(cls, n, closed=False) from __builtin__.classobj
Returns an IntervalSet of all values greater than or equal to n.  If
closed is True, then an IntervalSet of all values greater than or 
equal to n is returned.
 
>>> print IntervalSet.greaterThan(0)
(0,~)
>>> print IntervalSet.greaterThan(0, True)
[0,~)
>>> print IntervalSet.greaterThan(-23)
(-23,~)
>>> print IntervalSet.greaterThan(-23, True)
[-23,~)
lessThan(cls, n, closed=False) from __builtin__.classobj
Returns an IntervalSet of all values less than n.  If closed is 
True, then an IntervalSet of all values less than or equal to n is
returned.
 
>>> print IntervalSet.lessThan(0)
(-~,0)
>>> print IntervalSet.lessThan(0, True)
(-~,0]
>>> print IntervalSet.lessThan(-23)
(-~,-23)
>>> print IntervalSet.lessThan(-23, True)
(-~,-23]
notEqualTo(cls, n) from __builtin__.classobj
Returns an IntervalSet of all values not equal to n.
 
>>> print IntervalSet.notEqualTo(0)
(-~,0),(0,~)
>>> print IntervalSet.notEqualTo(-23)
(-~,-23),(-23,~)

 
class FrozenIntervalSet(BaseIntervalSet)
    FrozenIntervalSet is like IntervalSet, only add and remove are not
implemented, and hashes can be generated.
 
>>> fs = FrozenIntervalSet([3, 6, 2, 4])
>>> fs.add(12)
Traceback (most recent call last):
  ...
AttributeError: FrozenIntervalSet instance has no attribute 'add'
>>> fs.remove(4)
Traceback (most recent call last):
  ...
AttributeError: FrozenIntervalSet instance has no attribute 'remove'
>>> fs.clear()
Traceback (most recent call last):
  ...
AttributeError: FrozenIntervalSet instance has no attribute 'clear'
 
Because FrozenIntervalSets are immutable, they can be used as a 
dictionary key.
 
>>> d = {
...   FrozenIntervalSet([3, 66]) : 52, 
...   FrozenIntervalSet.lessThan(3) : 3}
 
  Methods defined here:
__hash__(self)
Generates a 32-bit hash key
 
>>> fs = FrozenIntervalSet([4, 7, 3])
>>> key = hash(fs)
__init__(self, items=[])

Methods inherited from BaseIntervalSet:
__add__(self, other)
This function returns the union of two IntervalSets.  It does the 
same thing as __or__.
 
>>> empty     = IntervalSet()
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
This function returns the intersection of self and other.
 
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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
__contains__(self, obj)
Returns True if obj is contained in self.  obj can be either a 
discrete value, a set, or an Interval.
 
>>> some = IntervalSet([
...   2, 8, Interval(12, True, 17, False), 
...   Interval.greaterThan(17)])
>>> all = IntervalSet.all()
>>> empty = IntervalSet.empty()
>>> 17 in empty
False
>>> 17 in all
True
>>> 17 in some
False
>>> r = Interval(100, True, 400, False)
>>> r in empty
False
>>> r in all
True
>>> r in some
True
__eq__(self, other)
Two IntervalSets are identical if they contain the exact same 
sets.  Note that an empty set is never equal to any other set, 
even an empty one.
 
>>> IntervalSet([4]) == IntervalSet([1])
False
>>> IntervalSet([5]) == IntervalSet([5])
True
>>> s1 = IntervalSet.between(4, 7)
>>> s2 = IntervalSet([Interval(4, True, 7, False)])
>>> s1 == s2
False
>>> s2.add(7)
>>> s1 == s2
True
__ge__(self, other)
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.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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
__gt__(self, other)
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.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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)
This function returns the disjoint set of self.  In other words,
all values self doesn't include are in the returned set.
 
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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, set([2, 87, 4, 3]), Interval.greaterThan(12),
...   Interval.lessThan(-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
__le__(self, other)
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.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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)
This function returns the number of intervals contained in self.
 
>>> len(IntervalSet.empty())
0
>>> len(IntervalSet.all())
1
>>> len(IntervalSet([2, 6, 34]))
3
>>> len(IntervalSet.greaterThan(0))
1
__lt__(self, other)
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.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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
__nonzero__(self)
An empty IntervalSet is the zero-like value.
 
>>> nonempty = IntervalSet([3])
>>> if IntervalSet.empty():
...     print "Non-empty"
>>> if nonempty:
...     print "Non-empty"
Non-empty
__or__(self, other)
This function returns the union of two IntervalSets.  It does the 
same thing as the __add__ function.
 
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
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, True, 32, False)])
23,[26,32)
>>> print IntervalSet.lessThan(3) + IntervalSet.greaterThan(3)
(-~,3),(3,~)
>>> print IntervalSet([Interval.lessThan(6, True)])
(-~,6]
__sub__(self, other)
Returns all values of self minus all matching values in other.
 
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
This function returns the exclusive or of two IntervalSets.  
 
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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
copy(self)
Returns a copy of the object.
 
>>> s = IntervalSet(
...   [7, 2, 3, set([2, 6, 2]), Interval.greaterThan(3)])
>>> s2 = s.copy()
>>> s == s2
True
>>> s = FrozenIntervalSet(
...   [7, 2, 3, set([2, 6, 2]), Interval.greaterThan(3)])
>>> s2 = s.copy()
>>> s == s2
True
difference(self, other)
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.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
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.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
Returns true if self is a subset of other.  other can be any 
iterable object.
 
>>> zero = IntervalSet([0])
>>> positives = IntervalSet.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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)
Returns true if self is a superset of other.  other can be any
iterable object.
 
>>> zero = IntervalSet([0])
>>> positives = IntervalSet.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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
symmetric_difference(self, other)
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.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
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.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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

Class methods inherited from BaseIntervalSet:
all(cls) from __builtin__.classobj
Returns an interval set containing all values.
>>> print IntervalSet.all()
(-~,~)
between(cls, a, b, closed=True) from __builtin__.classobj
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) from __builtin__.classobj
Returns an interval set containing no values.
>>> print IntervalSet.empty()
<Empty>
greaterThan(cls, n, closed=False) from __builtin__.classobj
Returns an IntervalSet of all values greater than or equal to n.  If
closed is True, then an IntervalSet of all values greater than or 
equal to n is returned.
 
>>> print IntervalSet.greaterThan(0)
(0,~)
>>> print IntervalSet.greaterThan(0, True)
[0,~)
>>> print IntervalSet.greaterThan(-23)
(-23,~)
>>> print IntervalSet.greaterThan(-23, True)
[-23,~)
lessThan(cls, n, closed=False) from __builtin__.classobj
Returns an IntervalSet of all values less than n.  If closed is 
True, then an IntervalSet of all values less than or equal to n is
returned.
 
>>> print IntervalSet.lessThan(0)
(-~,0)
>>> print IntervalSet.lessThan(0, True)
(-~,0]
>>> print IntervalSet.lessThan(-23)
(-~,-23)
>>> print IntervalSet.lessThan(-23, True)
(-~,-23]
notEqualTo(cls, n) from __builtin__.classobj
Returns an IntervalSet of all values not equal to n.
 
>>> print IntervalSet.notEqualTo(0)
(-~,0),(0,~)
>>> print IntervalSet.notEqualTo(-23)
(-~,-23),(-23,~)

 
class Interval
    An Interval is composed of the lower bound, a closed lower bound 
flag, an upper bound, and a closed upper bound flag.  The attributes
are called min, minClosed, max, and maxClosed, respectively.  For an 
infinite interval, the bound is set to inf or -inf.  IntervalSets are 
composed of zero to many Intervals.
 
  Methods defined here:
__contains__(self, obj)
Returns True if obj lies wholly within the Interval.
 
>>> all    = Interval.all()
>>> lt     = Interval.lessThan(10)
>>> le     = Interval.lessThan(10, True)
>>> some   = Interval(10, False, 20, True)
>>> single = Interval.equalTo(10)
>>> ge     = Interval.greaterThan(10, True)
>>> gt     = Interval.greaterThan(10)
>>> ne     = Interval.equalTo(17)
>>> 10 in all
True
>>> 10 in lt
False
>>> 10 in le
True
>>> 10 in some
False
>>> 10 in single
True
>>> 10 in ge
True
>>> 10 in gt
False
>>> 10 in ne
False
>>> all in some
False
>>> lt in all
True
>>> lt in some
False
>>> single in ge
True
>>> ne in some
True
>>> set((4, 2, 6)) in some
False
>>> set((11, 13, 15)) in some
True
__hash__(self)
Intervals are to be considered immutable.  Thus, a 32-bit hash can
be generated for them.
 
>>> h = hash(Interval.lessThan(5))
__init__(self, min=-~, minClosed=False, max=~, maxClosed=False)
An Interval can represent an infinite set.
>>> r = Interval(-inf, False, inf, False) # All values
 
An unbound portion of an Interval cannot be included; negative and
positive infinity are not true values.
>>> r = Interval(-inf, True, inf, False) # Invalid Interval
Traceback (most recent call last):
    ...
ValueError: Unbound ends cannot be included in an interval.
>>> r = Interval(-inf, False, inf, True) # Invalid Interval
Traceback (most recent call last):
    ...
ValueError: Unbound ends cannot be included in an interval.
 
An Interval can represent sets unbounded on an end.
>>> r = Interval(-inf, False, 62, False)
>>> r = Interval(-inf, False, 37, True)
>>> r = Interval(246, True, inf, False)
>>> r = Interval(2468, False, inf, False)
 
An Interval can represent a set of values up to, but not including a
value.
>>> r = Interval(25, False, 28, False)
 
An Interval can represent a set of values that have an inclusive
boundary.
>>> r = Interval(29, True, 216, True)
 
An Interval can represent a single value
>>> r = Interval(82, True, 82, True)
 
Intervals that are not normalized, i.e. that have a lower bound
exceeding an upper bound, are silently normalized.
>>> print Interval(5, False, 2, True)
[2,5)
 
Intervals can represent an empty set.
>>> r = Interval(5, False, 5, False)
__nonzero__(self)
An interval is non-zero if the interval is not empty.
 
>>> if Interval(12, False, 12, False):
...   print "Non-empty"
>>> if Interval(12, False, 12, True):
...   print "Non-empty"
>>> if Interval(12, True, 12, True):
...   print "Non-empty"
Non-empty
__str__(self)
This function yields a graphical representation of an Interval.  
It is included in the __str__ of an IntervalSet.  Non-inclusive 
boundaries are bordered by a ( or ).  Inclusive boundaries are 
bordered by [ or ].  Unbound lower values are shown as -~, 
representing negative infinity.  Unbound upper values are shown as 
~, representing infinity.  Intervals consisting of only a single 
value are shown as that value.
 
>>> print Interval.all()
(-~,~)
>>> print Interval.lessThan(100)
(-~,100)
>>> print Interval.lessThan(2593, True)
(-~,2593]
>>> print Interval.greaterThan(2378)
(2378,~)
>>> print Interval.between(26, 8234, False)
(26,8234)
>>> print Interval(237, False, 2348, True)
(237,2348]
>>> print Interval.greaterThan(347, True)
[347,~)
>>> print Interval(237, True, 278, False)
[237,278)
>>> print Interval.between(723, 2378)
[723,2378]
>>> print Interval.equalTo(5)
5
adjacentTo(self, other)
Returns True if self is adjacent to other, meaning that if they 
were joined, there would be no discontinuity.  They cannot 
overlap.
 
>>> r1  = Interval.lessThan(-100)
>>> r2  = Interval.lessThan(-100, True)
>>> r3  = Interval.lessThan(100)
>>> r4  = Interval.lessThan(100, True)
>>> r5  = Interval.all()
>>> r6  = Interval.between(-100, 100, False)
>>> r7  = Interval(-100, False,  100, True)
>>> r8  = Interval.greaterThan(-100)
>>> r9  = Interval.equalTo(-100)
>>> r10 = Interval(-100, True,   100, False)
>>> r11 = Interval.between(-100, 100)
>>> r12 = Interval.greaterThan(-100, True)
>>> r13 = Interval.greaterThan(100)
>>> r14 = Interval.equalTo(100)
>>> r15 = Interval.greaterThan(100, True)
>>> r1.adjacentTo(r6)
False
>>> r6.adjacentTo(r11)
False
>>> r7.adjacentTo(r9)
True
>>> r3.adjacentTo(r10)
False
>>> r5.adjacentTo(r14)
False
>>> r6.adjacentTo(r15)
True
>>> r1.adjacentTo(r8)
False
>>> r12.adjacentTo(r14)
False
>>> r6.adjacentTo(r13)
False
>>> r2.adjacentTo(r15)
False
>>> r1.adjacentTo(r4)
False
comesBefore(self, other)
self comes before other when sorted if its lower bound is less 
than other's smallest value.  If the smallest value is the same, 
then the Interval with the smallest upper bound comes first.  
Otherwise, they are equal.
 
>>> Interval.equalTo(1).comesBefore(Interval.equalTo(4))
True
>>> Interval.lessThan(1, True).comesBefore(Interval.equalTo(4))
True
>>> Interval.lessThan(5, True).comesBefore(Interval.lessThan(5))
False
>>> Interval.lessThan(5).comesBefore(Interval.lessThan(5, True))
True
join(self, other)
Combines two continuous Intervals into one Interval.  If the two
Intervals are disjoint, then an exception is raised.
>>> r1  = Interval.lessThan(-100)
>>> r2  = Interval.lessThan(-100, True)
>>> r3  = Interval.lessThan(100)
>>> r4  = Interval.lessThan(100, True)
>>> r5  = Interval.all()
>>> r6  = Interval.between(-100, 100, False)
>>> r7  = Interval(-100, False,  100, True)
>>> r8  = Interval.greaterThan(-100)
>>> r9  = Interval.equalTo(-100)
>>> r10 = Interval(-100, True,   100, False)
>>> r11 = Interval.between(-100, 100)
>>> r12 = Interval.greaterThan(-100, True)
>>> r13 = Interval.greaterThan(100)
>>> r14 = Interval.equalTo(100)
>>> r15 = Interval.greaterThan(100, True)
>>> print r13.join(r15)
[100,~)
>>> print r7.join(r6)
(-100,100]
>>> print r11.join(r2)
(-~,100]
>>> print r4.join(r15)
(-~,~)
>>> print r8.join(r8)
(-100,~)
>>> print r3.join(r7)
(-~,100]
>>> print r5.join(r10)
(-~,~)
>>> print r9.join(r1)
(-~,-100]
>>> print r12.join(r5)
(-~,~)
>>> print r13.join(r1)
Traceback (most recent call last):
    ...
ArithmeticError: The Intervals are disjoint.
>>> print r14.join(r2)
Traceback (most recent call last):
    ...
ArithmeticError: The Intervals are disjoint.
overlaps(self, other)
Returns True if the one Interval overlaps another.  If they are
immediately adjacent, then this returns False.  Use the adjacentTo
function for testing for adjacent Intervals.
 
>>> r1  = Interval.lessThan(-100)
>>> r2  = Interval.lessThan(-100, True)
>>> r3  = Interval.lessThan(100)
>>> r4  = Interval.lessThan(100, True)
>>> r5  = Interval.all()
>>> r6  = Interval.between(-100, 100, False)
>>> r7  = Interval(-100, False,  100, True)
>>> r8  = Interval.greaterThan(-100)
>>> r9  = Interval.equalTo(-100)
>>> r10 = Interval(-100, True,   100, False)
>>> r11 = Interval.between(-100, 100)
>>> r12 = Interval.greaterThan(-100, True)
>>> r13 = Interval.greaterThan(100)
>>> r14 = Interval.equalTo(100)
>>> r15 = Interval.greaterThan(100, True)
>>> r8.overlaps(r9)
False
>>> r12.overlaps(r6)
True
>>> r7.overlaps(r8)
True
>>> r8.overlaps(r4)
True
>>> r14.overlaps(r11)
True
>>> r10.overlaps(r13)
False
>>> r5.overlaps(r1)
True
>>> r5.overlaps(r2)
True
>>> r15.overlaps(r6)
False
>>> r3.overlaps(r1)
True

Class methods defined here:
all(cls) from __builtin__.classobj
Returns an interval encompassing all values
>>> print Interval.all()
(-~,~)
between(cls, a, b, closed=True) from __builtin__.classobj
Returns an interval between values a and b.  If closed is True,
then the endpoints are included.  Otherwise, the endpoints are
excluded.
>>> print Interval.between(2, 4)
[2,4]
>>> print Interval.between(2, 4, False)
(2,4)
equalTo(cls, a) from __builtin__.classobj
Returns an interval containing only a.
>>> print Interval.equalTo(32)
32
greaterThan(cls, a, closed=False) from __builtin__.classobj
Returns an interval containing all values greater than a.  If 
closed is True, then all values greater than or equal to a are 
returned.
>>> print Interval.greaterThan(32)
(32,~)
>>> print Interval.greaterThan(32, True)
[32,~)
lessThan(cls, a, closed=False) from __builtin__.classobj
Returns an interval containing all values less than a.  If closed
is True, then all values less than or equal to a are returned.
>>> print Interval.lessThan(32)
(-~,32)
>>> print Interval.lessThan(32, True)
(-~,32]

 
class IntervalSet(BaseIntervalSet)
    IntervalSet is a class representing sets of continuous values, as 
opposed to a discrete set, which is already implemented by the set 
type in Python.
 
IntervalSets can be bounded, unbounded, and non-continuous.  They were 
designed to accomodate any sort of mathematical set dealing with
continuous values.  This will usually mean numbers, but any Python 
type that has valid comparison operations can be used in an 
IntervalSet.
 
Because IntervalSets are mutable, it cannot be used as a dictionary 
key.
 
>>> {IntervalSet([3, 66]) : 52}
Traceback (most recent call last):
  ...
TypeError: unhashable instance
 
  Methods defined here:
__init__(self, items=[])
add(self, obj)
This function adds an Interval, discrete value, or set to
an IntervalSet.
 
>>> r = IntervalSet()
>>> r.add(4)
>>> print r
4
>>> r.add(Interval(23, False, 39, True))
>>> print r
4,(23,39]
>>> r.add(Interval.lessThan(25))
>>> print r
(-~,39]
>>> r.add(set([25, 50, 75, 100]))
>>> print r
(-~,39],50,75,100
clear(self)
Removes all intervals from an IntervalSet.
>>> s = IntervalSet([2, 7, Interval.greaterThan(8), 2, 6, 34])
>>> print s
2,6,7,(8,~)
>>> s.clear()
>>> print s
<Empty>
difference_update(self, other)
This function removes the elements in other from self.  other can
be any iterable object.
 
>>> r = IntervalSet.all()
>>> r.difference_update([4])
>>> print r
(-~,4),(4,~)
>>> r.difference_update(
...   IntervalSet([Interval(23, False, 39, True)]))
>>> print r
(-~,4),(4,23],(39,~)
>>> r.difference_update(IntervalSet.lessThan(25))
>>> print r
(39,~)
>>> r2 = IntervalSet.all()
>>> r.difference_update(r2)
>>> print r
<Empty>
discard(self, obj)
This function removes an Interval, discrete value, or set 
from an IntervalSet.
 
>>> r = IntervalSet.all()
>>> r.discard(4)
>>> print r
(-~,4),(4,~)
>>> r.discard(Interval(23, False, 39, True))
>>> print r
(-~,4),(4,23],(39,~)
>>> r.discard(Interval.lessThan(25))
>>> print r
(39,~)
>>> r2 = set([25, 50, 75, 100])
>>> r.discard(r2)
>>> print r
(39,50),(50,75),(75,100),(100,~)
intersection_update(self, other)
Removes elements not found in other.  other can be any iterable
object
>>> r = IntervalSet.all()
>>> r.intersection_update([4])
>>> print r
4
>>> r = IntervalSet.all()
>>> r.intersection_update(
...   IntervalSet([Interval(23, False, 39, True)]))
>>> print r
(23,39]
>>> r.intersection_update(IntervalSet.lessThan(25))
>>> print r
(23,25)
>>> r2 = IntervalSet.all()
>>> r.intersection_update(r2)
>>> print r
(23,25)
pop(self)
Returns and discards an Interval from the set.
 
>>> s = IntervalSet([7, Interval.lessThan(2), 2, 0])
>>> l = []
>>> l.append(str(s.pop()))
>>> l.append(str(s.pop()))
>>> "(-~,2)" in l
False
>>> "(-~,2]" in l
True
>>> "7" in l
True
>>> print s
<Empty>
>>> i = s.pop()
Traceback (most recent call last):
  ...
KeyError: 'pop from an empty IntervalSet'
remove(self, obj)
This function removes an Interval, discrete value, or set 
from an IntervalSet.  If the object is not in the set, a KeyError
is raised.
 
>>> r = IntervalSet.all()
>>> r.remove(4)
>>> print r
(-~,4),(4,~)
>>> r.remove(Interval(23, False, 39, True))
>>> print r
(-~,4),(4,23],(39,~)
>>> r.remove(Interval.lessThan(25))
Traceback (most recent call last):
  ...
KeyError: '(-~,25)'
symmetric_difference_update(self, other)
Removes elements found in other and adds elements in other that 
are not in self.  other can be any iterable object.
>>> r = IntervalSet.empty()
>>> r.symmetric_difference_update([4])
>>> print r
4
>>> r.symmetric_difference_update(
...   IntervalSet([Interval(23, False, 39, True)]))
>>> print r
4,(23,39]
>>> r.symmetric_difference_update(IntervalSet.lessThan(25))
>>> print r
(-~,4),(4,23],[25,39]
>>> r2 = IntervalSet.all()
>>> r.symmetric_difference_update(r2)
>>> print r
4,(23,25),(39,~)
update(self, other)
Adds elements from other to self.  other can be any iterable 
object.
>>> r = IntervalSet()
>>> r.update([4])
>>> print r
4
>>> r.update(IntervalSet([Interval(23, False, 39, True)]))
>>> print r
4,(23,39]
>>> r.update(IntervalSet.lessThan(25))
>>> print r
(-~,39]
>>> r2 = IntervalSet.all()
>>> r.update(r2)
>>> print r
(-~,~)

Methods inherited from BaseIntervalSet:
__add__(self, other)
This function returns the union of two IntervalSets.  It does the 
same thing as __or__.
 
>>> empty     = IntervalSet()
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
This function returns the intersection of self and other.
 
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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
__contains__(self, obj)
Returns True if obj is contained in self.  obj can be either a 
discrete value, a set, or an Interval.
 
>>> some = IntervalSet([
...   2, 8, Interval(12, True, 17, False), 
...   Interval.greaterThan(17)])
>>> all = IntervalSet.all()
>>> empty = IntervalSet.empty()
>>> 17 in empty
False
>>> 17 in all
True
>>> 17 in some
False
>>> r = Interval(100, True, 400, False)
>>> r in empty
False
>>> r in all
True
>>> r in some
True
__eq__(self, other)
Two IntervalSets are identical if they contain the exact same 
sets.  Note that an empty set is never equal to any other set, 
even an empty one.
 
>>> IntervalSet([4]) == IntervalSet([1])
False
>>> IntervalSet([5]) == IntervalSet([5])
True
>>> s1 = IntervalSet.between(4, 7)
>>> s2 = IntervalSet([Interval(4, True, 7, False)])
>>> s1 == s2
False
>>> s2.add(7)
>>> s1 == s2
True
__ge__(self, other)
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.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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
__gt__(self, other)
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.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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)
This function returns the disjoint set of self.  In other words,
all values self doesn't include are in the returned set.
 
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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, set([2, 87, 4, 3]), Interval.greaterThan(12),
...   Interval.lessThan(-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
__le__(self, other)
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.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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)
This function returns the number of intervals contained in self.
 
>>> len(IntervalSet.empty())
0
>>> len(IntervalSet.all())
1
>>> len(IntervalSet([2, 6, 34]))
3
>>> len(IntervalSet.greaterThan(0))
1
__lt__(self, other)
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.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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
__nonzero__(self)
An empty IntervalSet is the zero-like value.
 
>>> nonempty = IntervalSet([3])
>>> if IntervalSet.empty():
...     print "Non-empty"
>>> if nonempty:
...     print "Non-empty"
Non-empty
__or__(self, other)
This function returns the union of two IntervalSets.  It does the 
same thing as the __add__ function.
 
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
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, True, 32, False)])
23,[26,32)
>>> print IntervalSet.lessThan(3) + IntervalSet.greaterThan(3)
(-~,3),(3,~)
>>> print IntervalSet([Interval.lessThan(6, True)])
(-~,6]
__sub__(self, other)
Returns all values of self minus all matching values in other.
 
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
This function returns the exclusive or of two IntervalSets.  
 
>>> negatives = IntervalSet.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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
copy(self)
Returns a copy of the object.
 
>>> s = IntervalSet(
...   [7, 2, 3, set([2, 6, 2]), Interval.greaterThan(3)])
>>> s2 = s.copy()
>>> s == s2
True
>>> s = FrozenIntervalSet(
...   [7, 2, 3, set([2, 6, 2]), Interval.greaterThan(3)])
>>> s2 = s.copy()
>>> s == s2
True
difference(self, other)
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.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
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.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
Returns true if self is a subset of other.  other can be any 
iterable object.
 
>>> zero = IntervalSet([0])
>>> positives = IntervalSet.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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)
Returns true if self is a superset of other.  other can be any
iterable object.
 
>>> zero = IntervalSet([0])
>>> positives = IntervalSet.greaterThan(0)
>>> naturals = IntervalSet.greaterThan(0, True)
>>> negatives = IntervalSet.lessThan(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
symmetric_difference(self, other)
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.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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)
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.lessThan(0)
>>> positives = IntervalSet.greaterThan(0)
>>> naturals  = IntervalSet.greaterThan(0, True)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.notEqualTo(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

Class methods inherited from BaseIntervalSet:
all(cls) from __builtin__.classobj
Returns an interval set containing all values.
>>> print IntervalSet.all()
(-~,~)
between(cls, a, b, closed=True) from __builtin__.classobj
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) from __builtin__.classobj
Returns an interval set containing no values.
>>> print IntervalSet.empty()
<Empty>
greaterThan(cls, n, closed=False) from __builtin__.classobj
Returns an IntervalSet of all values greater than or equal to n.  If
closed is True, then an IntervalSet of all values greater than or 
equal to n is returned.
 
>>> print IntervalSet.greaterThan(0)
(0,~)
>>> print IntervalSet.greaterThan(0, True)
[0,~)
>>> print IntervalSet.greaterThan(-23)
(-23,~)
>>> print IntervalSet.greaterThan(-23, True)
[-23,~)
lessThan(cls, n, closed=False) from __builtin__.classobj
Returns an IntervalSet of all values less than n.  If closed is 
True, then an IntervalSet of all values less than or equal to n is
returned.
 
>>> print IntervalSet.lessThan(0)
(-~,0)
>>> print IntervalSet.lessThan(0, True)
(-~,0]
>>> print IntervalSet.lessThan(-23)
(-~,-23)
>>> print IntervalSet.lessThan(-23, True)
(-~,-23]
notEqualTo(cls, n) from __builtin__.classobj
Returns an IntervalSet of all values not equal to n.
 
>>> print IntervalSet.notEqualTo(0)
(-~,0),(0,~)
>>> print IntervalSet.notEqualTo(-23)
(-~,-23),(-23,~)

 
class Largest
    This type doesn't do much; it implements a pseudo-value that's larger
than everything but itself.
 
>>> infinity = Largest()
>>> greatest = Largest()
>>> 6234 < infinity
True
>>> 6234 == infinity
False
>>> 6234 > infinity
False
>>> infinity > infinity
False
>>> infinity == greatest
True
 
  Methods defined here:
__cmp__(self, other)
Always indicates that self is greater than other, unless both are of
type Largest, in which case they are equal.
 
>>> 0 > Largest()
False
>>> Largest() < 9999999
False
>>> Largest() > 9999999
True
>>> Largest() < Largest()
False
>>> Largest() == Largest()
True
__hash__(self)
Returns a value that can be used for generating hashes
__neg__(self)
The opposite of infinity is negative infinity, the smallest value.
>>> print -Largest()
-~
__repr__(self)
The representation of the largest number is ~, which means infinity.
>>> Largest()
~

 
class Smallest
    This type doesn't do much; it implements a pseudo-value that's smaller
than everything but itself.
 
>>> negInf = Smallest()
>>> smallest = Smallest()
>>> -264 < negInf
False
>>> -264 == negInf
False
>>> -264 > negInf
True
>>> negInf < negInf
False
>>> negInf == smallest
True
 
  Methods defined here:
__cmp__(self, other)
Always indicates that self is less than other, unless both are of 
type Smallest, in which case they are equal.
 
>>> 0 < Smallest()
False
>>> -9999999 < Smallest()
False
>>> Smallest() < -9999999
True
>>> Smallest() < Smallest()
False
>>> Smallest() == Smallest()
True
__hash__(self)
Returns a value that can be used for generating hashes
__neg__(self)
The opposite of negative infinity is infinity, the largest value.
>>> print -Smallest()
~
__repr__(self)
The representation of the smallest number is -~, which means 
negative infinity.
>>> Smallest()
-~

 
Data
        inf = ~