Goulib.interval module

operations on [a..b[ intervals

Goulib.interval.in_interval(interval, x, closed=True)[source]
Returns:bool True if x is in interval [a,b] or [b,a] (tuple)
Goulib.interval.intersect(t1, t2)[source]
Returns:bool True if intervals [t1[ [t2[ intersect
Goulib.interval.intersection(t1, t2)[source]
Returns:tuple intersection between 2 intervals (tuples),

or None if intervals don’t intersect

Goulib.interval.intersectlen(t1, t2, none=0)[source]
Parameters:
  • t1 – interval 1 (tuple)
  • t2 – interval 2 (tuple)
  • none – value to return when t1 does not intersect t2
Returns:

len of intersection between 2 intervals (tuples),

or none if intervals don’t intersect

class Goulib.interval.Interval(start, end)[source]

Bases: list

Represents an interval. Defined as half-open interval [start,end), which includes the start position but not the end. Start and end do not have to be numeric types. They might especially be time, date or timedate as used in datetime2

inspired from http://code.activestate.com/recipes/576816-interval/ alternatives could be https://pypi.python.org/pypi/interval/

(outdated, no more doc) or https://pypi.python.org/pypi/pyinterval/

Construct, start must be <= end.

__init__(start, end)[source]

Construct, start must be <= end.

start

The interval’s start

end

The interval’s end

__str__()[source]
__repr__()[source]
__hash__()[source]
__lt__(other)[source]
__eq__(other)[source]
size
center
separation(other)[source]
Returns:distance between self and other, negative if overlap
overlap(other, allow_contiguous=False)[source]
Returns:True iff self intersects other.
intersection(other)[source]
Returns:Intersection with other, or None if no intersection.
__iadd__(other)[source]

expands self to contain other.

hull(other)[source]
Returns:new Interval containing both self and other.
__add__(other)[source]
__contains__(x)[source]
Returns:True if x in self.
subset(other)[source]
Returns:True iff self is subset of other.
proper_subset(other)[source]
Returns:True iff self is proper subset of other.
empty()[source]
Returns:True iff self is empty.
__nonzero__()[source]
singleton()[source]
Returns:True iff self.end - self.start == 1.
__class__

alias of type

__delattr__

Implement delattr(self, name).

__delitem__

Delete self[key].

__dir__() → list

default dir() implementation

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__getitem__()

x.__getitem__(y) <==> x[y]

__gt__

Return self>value.

__imul__

Implement self*=value.

__iter__

Implement iter(self).

__le__

Return self<=value.

__len__

Return len(self).

__mul__

Return self*value.n

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__reversed__()

L.__reversed__() – return a reverse iterator over the list

__rmul__

Return self*value.

__setattr__

Implement setattr(self, name, value).

__setitem__

Set self[key] to value.

__sizeof__()

L.__sizeof__() – size of L in memory, in bytes

append(object) → None -- append object to end
clear() → None -- remove all items from L
copy() → list -- a shallow copy of L
count(value) → integer -- return number of occurrences of value
extend(iterable) → None -- extend list by appending elements from the iterable
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

insert()

L.insert(index, object) – insert object before index

pop([index]) → item -- remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(value) → None -- remove first occurrence of value.

Raises ValueError if the value is not present.

reverse()

L.reverse() – reverse IN PLACE

sort(key=None, reverse=False) → None -- stable sort *IN PLACE*
class Goulib.interval.Intervals(iterable=(), key=None)[source]

Bases: Goulib.container.SortedCollection

a list of intervals kept in ascending order

__repr__()[source]
insert(item)[source]
__iadd__(item)[source]
__add__(item)[source]
__call__(x)[source]

returns intervals containing x

__class__

alias of type

__contains__(item)
__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__getitem__(i)
__gt__

Return self>value.

__hash__

Return hash(self).

__init__(iterable=(), key=None)
__iter__()
__le__

Return self<=value.

__len__()
__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()
__reduce_ex__()

helper for pickle

__reversed__()
__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

clear()
copy()
count(item)

Return number of occurrences of item

find(k)

Return first item with a key == k. Raise ValueError if not found.

find_ge(k)

Return first item with a key >= equal to k. Raise ValueError if not found

find_gt(k)

Return first item with a key > k. Raise ValueError if not found

find_le(k)

Return last item with a key <= k. Raise ValueError if not found.

find_lt(k)

Return last item with a key < k. Raise ValueError if not found.

index(item)

Find the position of an item. Raise ValueError if not found.

insert_right(item)

Insert a new item. If equal keys are found, add to the right

key

key function

pop(i=-1)
remove(item)

Remove first occurence of item. Raise ValueError if not found

class Goulib.interval.Box(*args)[source]

Bases: list

a N dimensional rectangular box defined by a list of N Intervals

__init__(*args)[source]
corner(n)[source]

return n-th corner of box 0-th corner is “start” made of all minimal values of intervals -1.th corner is “end”, made of all maximal values of intervals

start
end
size
center
__call__()[source]
Returns:tuple of all intervals as tuples
__iadd__(other)[source]

enlarge box if required to contain specified point :param other: Box or (list of) N-tuple point(s)

__add__(other)[source]

enlarge box if required to contain specified point :param other: Box or (list of) N-tuple point(s) :return: new Box containing both

__contains__(other)[source]
Returns:True if x in self.
__nonzero__()[source]
empty()[source]
Returns:True iff Box is empty.
__class__

alias of type

__delattr__

Implement delattr(self, name).

__delitem__

Delete self[key].

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__getitem__()

x.__getitem__(y) <==> x[y]

__gt__

Return self>value.

__hash__ = None
__imul__

Implement self*=value.

__iter__

Implement iter(self).

__le__

Return self<=value.

__len__

Return len(self).

__lt__

Return self<value.

__mul__

Return self*value.n

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__reversed__()

L.__reversed__() – return a reverse iterator over the list

__rmul__

Return self*value.

__setattr__

Implement setattr(self, name, value).

__setitem__

Set self[key] to value.

__sizeof__()

L.__sizeof__() – size of L in memory, in bytes

__str__

Return str(self).

append(object) → None -- append object to end
clear() → None -- remove all items from L
copy() → list -- a shallow copy of L
count(value) → integer -- return number of occurrences of value
extend(iterable) → None -- extend list by appending elements from the iterable
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

insert()

L.insert(index, object) – insert object before index

max
min
pop([index]) → item -- remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(value) → None -- remove first occurrence of value.

Raises ValueError if the value is not present.

reverse()

L.reverse() – reverse IN PLACE

sort(key=None, reverse=False) → None -- stable sort *IN PLACE*