Module range_t

Module that provides range_t class which offers a simple and compact way of representing number sets.

class ytfs.range_t.range_t(initset=set())[source]

Class offers simple representation of multiple ranges as one object. Subranges are represented as two element tuples, where first element is a left boundary and second element is a right range boundary. The left one is always included, whereas right is always excluded from the range.

Parameters:

initset : set, optional

Initial set of subranges. Empty set is the default value.

Attributes

__has (set) Set of subranges.
__add__(val)[source]

a + b operation support.

Parameters:

val : int or tuple or list or range

Integer or range to add.

Returns:

range_t

New range_t object extended by val.

__contains__(val)[source]

Method which allows in operator usage.

Parameters:

val : int or tuple or list or range

Range or integer being checked.

Returns:

bool

True if whole examined range is present in object. Otherwise False.

__eq__(val)[source]

= operator support.

Parameters:

val : range_t

range_t object for comparison.

Returns:

bool

True if set of subranges in this object is identical as in val object.

__iadd__(val)[source]

a += b operation support. The difference from + is that no new object is created.

Parameters:

val : int or tuple or list or range

Integer or range to add.

Returns:

self : range_t

No new object is created, the current one is extended by val and returned.

__len__()[source]

Length of object.

Returns:

ret : int

Sum of subranges lengths.

__sub__(val)[source]

Substracting support.

Parameters:

val : int or tuple or list or range

Integer or range to substract.

Returns:

range_t

New range_t object bereft of val.

_range_t__add(val)

Helper method for range addition. It is allowed to add only one compact subrange or range_t object at once.

Parameters:

val : int or tuple or list or range

Integer or range to add.

Returns:

__has : set

self.__has extended by val.

_range_t__match_l(k, _set)

Method for searching subranges from _set that overlap on k range.

Parameters:

k : tuple or list or range

Range for which we search overlapping subranges from _set.

_set : set

Subranges set.

Returns:

matched : set

Set of subranges from _set that overlaps on k.

_range_t__optimize()

Merge overlapping or contacting subranges from self.__has attribute and update it. Called from all methods that modify object contents.

Returns:

None

Method does not return. It does internal modifications on self.__has attribute.

_range_t__val_convert(val)

Convert input data to a range tuple (start, end).

Parameters:

val : int or tuple or list or range

Two element indexed object, that represents a range, or integer.

Returns:

converted : tuple

Tuple that represents a range.

contains(val)[source]

Check if given value or range is present.

Parameters:

val : int or tuple or list or range

Range or integer being checked.

Returns:

retlen : int

Length of overlapping with val subranges.

match(val)[source]

Search for overlapping with val subranges. In fact, it is a visible wrapper of hidden __match_l.

Parameters:

val : int or tuple or list or range

Range or integer being checked.

Returns:

set

Set of overlapping subranges.

toset()[source]

Convert object to a set of subranges.

Returns:

set

self.__has is returned.