Module interval
[show private | hide private]
[frames | no frames]

Module interval

Provides the Interval and IntervalSet classes

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']

Classes
BaseIntervalSet Base class for IntervalSet and FrozenIntervalSet.
FrozenIntervalSet An immutable version of BaseIntervalSet
Interval Represents a continuous range of values
IntervalSet The mutable version of BaseIntervalSet
Largest Class representing the universal largest value
Smallest Represents the smallest value

Variable Summary
Largest Inf = Inf

Variable Details

Inf

Type:
Largest
Value:
Inf                                                                    

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