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

Type FrozenIntervalSet

     object --+    
              |    
BaseIntervalSet --+
                  |
                 FrozenIntervalSet


An immutable version of 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' object has no attribute 'add'

>>> fs.remove(4)
Traceback (most recent call last):

  ...

AttributeError: 'FrozenIntervalSet' object has no attribute 'remove'

>>> fs.clear()
Traceback (most recent call last):

  ...

AttributeError: 'FrozenIntervalSet' object has no attribute 'clear'
Because FrozenIntervalSets are immutable, they can be used as a dictionary key.
>>> d = {
...   FrozenIntervalSet([3, 66]) : 52, 
...   FrozenIntervalSet.less_than(3) : 3}

Method Summary
  __init__(self, items)
Initializes the FrozenIntervalSet
  __hash__(self)
Generates a 32-bit hash key
  __new__(cls, items)
Constructs a new FrozenInteralSet (Static method)
  __repr__(self)
Returns an evaluable representation of the object
  copy(self)
Duplicates the object
    Inherited from 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
  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
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value

Instance Method Details

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

Initializes the FrozenIntervalSet
Overrides:
interval.BaseIntervalSet.__init__

__hash__(self)
(Hashing function)

Generates a 32-bit hash key
>>> fs = FrozenIntervalSet([4, 7, 3])
>>> key = hash(fs)
Overrides:
__builtin__.object.__hash__

__repr__(self)
(Representation operator)

Returns an evaluable representation of the object
>>> FrozenIntervalSet([Interval()])
FrozenIntervalSet([Interval(-Inf, Inf, lower_closed=False, upper_closed=False)])

>>> FrozenIntervalSet()
FrozenIntervalSet([])

>>> FrozenIntervalSet([2, 4])
FrozenIntervalSet([Interval(2, 2, lower_closed=True, upper_closed=True), Interval(4, 4, lower_closed=True, upper_closed=True)])
Overrides:
__builtin__.object.__repr__

copy(self)

Duplicates the object

For FrozenIntervalSet objects, since they're immutable, a reference, not a copy, of self is returned.
>>> s = FrozenIntervalSet(
...   [7, 2, 3, 2, 6, 2, Interval.greater_than(3)])
>>> s2 = s.copy()
>>> s == s2
True

>>> id(s) == id(s2)
True
Overrides:
interval.BaseIntervalSet.copy

Static Method Details

__new__(cls, items=[])

Constructs a new FrozenInteralSet

Object creation is just like with a regular IntervalSet, except for the special case where another FrozenIntervalSet is passed as the initializer iterable. If it is, then the result points to the same object.
>>> fs1 = FrozenIntervalSet.greater_than(12)
>>> fs2 = FrozenIntervalSet(fs1)
>>> id(fs1) == id(fs2)
True
Overrides:
__builtin__.object.__new__

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