| Home | Trees | Index | Help |
|---|
| Module interval :: Class IntervalSet |
|
object --+
|
BaseIntervalSet --+
|
IntervalSet
The mutable version of 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
| Method Summary | |
|---|---|
Initializes the IntervalSet | |
Removes the interval at the given index from the IntervalSet | |
Raises an error since IntervalSets are mutable | |
Returns an evaluable representation of the object | |
Adds an Interval or discrete value to the object | |
Removes all Intervals from the object | |
Removes any elements in the given value from the object | |
Removes a value from the object | |
Removes values not found in the parameter | |
Returns and discards an Interval or value from the IntervalSet | |
Removes a value from the object | |
Updates the object as though doing an xor with the parameter | |
Adds elements from the given value to the object | |
| Inherited from 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 | |
T.__new__(S, ...) -> a new object with type S, a subtype of T | |
helper for pickle | |
helper for pickle | |
x.__setattr__('name', value) <==> x.name = value | |
| Instance Method Details |
|---|
__init__(self,
items=[])
Initializes the IntervalSet
|
__delitem__(self,
index)
Removes the interval at the given index from the IntervalSet
|
__hash__(self)
Raises an error since IntervalSets are mutable
|
__repr__(self)
Returns an evaluable representation of the object
|
add(self, obj)Adds an Interval or discrete value to the object>>> r = IntervalSet() >>> r.add(4) >>> print r 4 >>> r.add(Interval(23, 39, lower_closed=False)) >>> print r 4,(23..39] >>> r.add(Interval.less_than(25)) >>> print r (...39] |
clear(self)Removes all Intervals from the object>>> s = IntervalSet([2, 7, Interval.greater_than(8), 2, 6, 34]) >>> print s 2,6,7,(8...) >>> s.clear() >>> print s <Empty> |
difference_update(self, other)Removes any elements in the given value from the object 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, 39, lower_closed=False)])) >>> print r (...4),(4..23],(39...) >>> r.difference_update(IntervalSet.less_than(25)) >>> print r (39...) >>> r2 = IntervalSet.all() >>> r.difference_update(r2) >>> print r <Empty> |
discard(self, obj)Removes a value from the object This function removes an Interval or discrete value from an IntervalSet.>>> r = IntervalSet.all() >>> r.discard(4) >>> print r (...4),(4...) >>> r.discard(Interval(23, 39, lower_closed=False)) >>> print r (...4),(4..23],(39...) >>> r.discard(Interval.less_than(25)) >>> print r (39...) |
intersection_update(self, other)Removes values not found in the parameter 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, 39, lower_closed=False)])) >>> print r (23..39] >>> r.intersection_update(IntervalSet.less_than(25)) >>> print r (23..25) >>> r2 = IntervalSet.all() >>> r.intersection_update(r2) >>> print r (23..25) |
pop(self)Returns and discards an Interval or value from the IntervalSet>>> s = IntervalSet([7, Interval.less_than(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)Removes a value from the object 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, 39, lower_closed=False)) >>> print r (...4),(4..23],(39...) >>> r.remove(Interval.less_than(25)) Traceback (most recent call last): ... KeyError: '(...25)' |
symmetric_difference_update(self, other)Updates the object as though doing an xor with the parameter 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, 39, lower_closed=False)])) >>> print r 4,(23..39] >>> r.symmetric_difference_update(IntervalSet.less_than(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 the given value to the object 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, 39, lower_closed=False)])) >>> print r 4,(23..39] >>> r.update(IntervalSet.less_than(25)) >>> print r (...39] >>> r2 = IntervalSet.all() >>> r.update(r2) >>> print r (...) |
| Home | Trees | Index | Help |
|---|
| Generated by Epydoc 2.1 on Wed Nov 9 22:22:38 2005 | http://epydoc.sf.net |