| Home | Trees | Index | Help |
|---|
| Module interval :: Class BaseIntervalSet |
|
object --+
|
BaseIntervalSet
FrozenIntervalSet,
IntervalSet| Method Summary | |
|---|---|
Initializes a BaseIntervalSet | |
Returns the union of two IntervalSets | |
Returns the intersection of self and other. | |
Compares two BaseIntervalSets | |
Tells whether the BaseIntervalSet contains the given value | |
Tests if two BaseIntervalSets are equivalent | |
Tests if the given operand is a superset or is equal to the object | |
Gets the interval at the given index | |
Tests if the given operand is a superset of the object | |
Returns the disjoint set of self | |
Returns an iterator over the intervals in the set | |
Tests if the given operand is a subset or is equal to the object | |
Returns the number of intervals contained in the object | |
Tests if the given operand is a subset of the object | |
Tests if two BaseIntervalSets are not equivalent | |
Returns the union of two IntervalSets. | |
Returns a string representation of the object | |
Subtracts intervals in the given object from the object and returns the result | |
Returns the exclusive or of two IntervalSets. | |
Returns an interval set containing all values (Class method) | |
Returns an IntervalSet of all values between a and b. (Class method) | |
Returns an interval that encompasses the entire BaseIntervalSet | |
Returns a copy of the object | |
Returns the difference between the object and the given object | |
Returns an interval set containing no values. (Class method) | |
Returns an IntervalSet containing values greater than the given value (Class method) | |
Returns an IntervalSet containing values greater than or equal to the given value (Class method) | |
Returns the intersection between the object and the given value | |
Tells if the given object is a subset of the object | |
Tells whether the given object is a superset of the object | |
Returns an IntervalSet containing values less than the given value (Class method) | |
Returns an IntervalSet containing values less than or equal to the given value (Class method) | |
Returns the lower boundary of the BaseIntervalSet | |
Returns a boolean telling whether the lower bound is closed or not | |
Returns an IntervalSet of all values not equal to n (Class method) | |
Returns the exclusive or of the given value with the object | |
Returns the union of the given value with the object | |
Returns the upper boundary of the BaseIntervalSet | |
Returns a boolean telling whether the upper bound is closed or not | |
| Inherited from object | |
x.__delattr__('name') <==> del x.name | |
x.__getattribute__('name') <==> x.name | |
x.__hash__() <==> hash(x) | |
T.__new__(S, ...) -> a new object with type S, a subtype of T | |
helper for pickle | |
helper for pickle | |
x.__repr__() <==> repr(x) | |
x.__setattr__('name', value) <==> x.name = value | |
| Instance Method Details |
|---|
__init__(self,
items=[])
|
__add__(self,
other)
Returns the union of two IntervalSets
|
__and__(self,
other)
Returns the intersection of self and other.
|
__cmp__(self,
other)
|
__contains__(self,
obj)
|
__eq__(self,
other)
|
__ge__(self,
other)
|
__getitem__(self,
index)
|
__gt__(self,
other)
|
__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 TrueThough 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)
|
__len__(self)
Returns the number of intervals contained in the object
|
__lt__(self,
other)
|
__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() FalseAn 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)
Returns the union of two IntervalSets.
|
__str__(self)
|
__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.>>> 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...) |
| Home | Trees | Index | Help |
|---|
| Generated by Epydoc 2.1 on Wed Nov 9 22:22:38 2005 | http://epydoc.sf.net |