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 + boperation support.Parameters: val : int or tuple or list or range
Integer or range to add.
Returns: range_t
New
range_tobject extended by val.
-
__contains__(val)[source]¶ Method which allows
inoperator usage.Parameters: val : int or tuple or list or range
Range or integer being checked.
Returns: bool
Trueif whole examined range is present in object. OtherwiseFalse.
-
__eq__(val)[source]¶ =operator support.Parameters: val : range_t
range_tobject for comparison.Returns: bool
Trueif set of subranges in this object is identical as in val object.
-
__iadd__(val)[source]¶ a += boperation 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.
-
__sub__(val)[source]¶ Substracting support.
Parameters: val : int or tuple or list or range
Integer or range to substract.
Returns: range_t
New
range_tobject bereft of val.
-
_range_t__add(val)¶ Helper method for range addition. It is allowed to add only one compact subrange or
range_tobject at once.Parameters: val : int or tuple or list or range
Integer or range to add.
Returns: __has : set
self.__hasextended 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.__hasattribute and update it. Called from all methods that modify object contents.Returns: None
Method does not return. It does internal modifications on
self.__hasattribute.
-
_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.
-