Range classes for managing associations and sets whose items span ranges.
Engineering
Mapping, and a Stack thereof, are not yet implemented. Currently, there are some differences between the implementation of a Mapping and the extant Set. Notably, adjacent ranges can only be joined if the values are equivalent. Sets join adjacent ranges unconditionally.
operator
itertools0
typing0
collections0
builtins0
inclusive_range_set110%
inclusive_range_set(numbers)
Calculate the set of inclusive ranges.
Given a iterable of numbers, sort them and create ranges from the contiguous values.
inclusive_range_setParameters
combine0
combine(ranges)
Combine the ranges into a sequence of ranges reducing them according to their overlaps and contiguity. Used by Set to implement unions.
IRange0
Fully Inclusive range used for cases where the range length always is one or more.
IRange__slots__0
__slots__ = ()
IRangeType0type
Type:(type) = int
@property
IRangedirection40%
Returns -1 if the stop is less than the start. 1 if equal or greater than.
IRangestart20%
The beginning of the Range, inclusive.
IRangestop20%
The end of the Range, inclusive.
IRangenormal0
normal(Class, *args)
Create a normal range using the given boundaries; the minimum given will be the start and the maximum will be the stop.
IRangesingle0
single(Class, index)
Create a range consisting of a single unit.
IRangefrom_string0
from_string(Class, string)
IRange__contains__0
__contains__(self, x)
Whether or not the range contains the given number.
IRange__str__0
__str__(self)
IRangerelation40%
relation(self, r)
The relation of r with respect to the self. Returns -1 if r is less than the start; 1 if r is greater than the stop, and 0 if it is contained.
| WARNING | |
Does not compensate for negative direction ranges. |
IRangecontiguous0
contiguous(self, r)
The given range is contiguous with the other, but does not overlaps.
IRangeoverlaps0
overlaps(self, r)
The ranges overlap onto each other.
IRangecontinuation0
continuation(self, r)
The ranges are continuous: overlaps or contiguous.
IRangejoin0
join(self, r)
Combine the ranges regardless of adjacency.
IRangefilter0
filter(self, ranges)
Modify (filter) the ranges to be outside of self. If a range is wholly contained, filter it entirely.
The filter is a generator and is applied to an iterable of ranges because it is the necessary framework for dropping wholly contained inclusive ranges. Inclusive ranges cannot represent zero length sizes, so it has to drop contained ranges entirely from the generated sequence.
IRangefilterParameters
rangestyping.Iterable["IRange"]
Sequence of IRange instances to be filtered.
IRangeintersect0typing.Iterable["IRange"]
intersect(self, ranges)
Identify the parts of the ranges that intersect with self.
IRangeintersectParameters
IRangeintersectReturns
- Annotation
A iterable producing IRange instances.
IRangeexclusive20%
exclusive(self)
Return as an exclusive-end range pair.
IRangeunits420%
units(self)
Return an iterator to the units in the range.
Set0
A set of unique non-contiguous ranges.
Implemented using a pair of sequences containing the start and the stop of each range. For sets consisting of single unit ranges, regular set objects are more efficient. bisect is used as the search algorithm when checking for containment, so applications requiring high performance may need to convert the range set or portions thereof into a regular set.
Set_search0
Set__slots__0
__slots__ = ('starts', 'stops')
@classmethod
Setfrom_string0
from_string(Class, string)
Setfrom_set20%
from_set(Class, iterable)
Setfrom_normal_sequence0
from_normal_sequence(Class, ranges)
Low-level constructor building a Set from an ordered sequence of non-overlapping range instances.
Set__init__0
__init__(self, pair)
Set__repr__10%
__repr__(self)
Set__reduce__0
__reduce__(self)
Set__iter__0
__iter__(self)
Set__str__0
__str__(self)
Set__eq__0
__eq__(self, ns)
Set__len__0
__len__(self)
Total number of individual units held by the set.
Working with inclusive ranges, this means that spans from 0 to 100 will have a length of 101.
Setintersecting0
intersecting(self, range)
Get the ranges in the set that have intersections with the given range.
Setget40%
get(self, item)
Set__getitem__40%
__getitem__(self, item)
Set__contains__0
__contains__(self, item)
Setadd0
add(self, range)
Add a range to the set combining it with any continuations.
Setdiscard192%
discard(self, range)
Remove an arbitrary range from the set.
Setintersection0
intersection(self, range_set)
Calculate the intersection between two Set instances. Low-level method. Use | for high-level purposes.
Setdifference289%
difference(self, range_set)
Calculate the difference between two Set instances. Low-level method. Use - for high-level purposes.
Setunion0
union(self, range_set)
Calculate the union between two Set instances.
Set__add__0
__add__ = union
Set__sub__0
__sub__(self, range_set)
Set__or__10%
__or__(self, range_set)
XRange0
Exclusive numeric range. Only exclusive on the stop. Provides access to zero-sized ranges that need to maintain position.
XRange__slots__0
__slots__ = ()
XRangeType0type
Type:(type) = int
@property
XRangedirection40%
Returns -1 if the stop is less than the start.
XRangestart20%
The beginning of the Range, inclusive.
XRangestop20%
The end of the Range, inclusive.
XRangenormal20%
normal(Class, *args)
Create a normal range using the given boundaries; the minimum given will be the start and the maximum will be the stop.
XRangesingle20%
single(Class, index)
Create a range consisting of a single unit.
XRange__contains__20%
__contains__(self, x)
Whether or not the range contains the given number.
XRangerelation40%
relation(self, r)
The relation of r with respect to the self. Returns -1 if r is less than the start; 1 if r is greater than the stop, and 0 if it is contained.
| WARNING | |
Does not compensate for negative direction ranges. |
XRangecontiguous40%
contiguous(self, range)
XRangejoin20%
join(self, r)
Combine the ranges.
XRangeexclusive20%
exclusive(self)
Returns self.
XRangeunits420%
units(self)
Return an iterator to the units in the range.
Mapping0
A tiered, finite map of ranges explicitly associated with values.
| WARNING | |
Implementation is sensitive to the order in which items are set. Keys intending to contain other Ranges must be set before the narrow range is set. |
MappingEngineering
Rewrite by vectorizing k-index and v-index to eliminate the recursive implementation. In cases of instances with large depths, a vectorized form should help with execution (fewer stack frames) and memory (fewer instances) performance.
Mapping__init__0
__init__(self)
Mappingkeys0
keys(self)
Mappingvalues0
values(self)
Mappingitems0
items(self)
Mappingget0
get(self, key)
Mapping__getitem__175%
__getitem__(self, key)
Mapping__setitem__0
__setitem__(self, key, value)
Mappingupdate0
update(self, vs)
Mapping__delitem__60%
__delitem__(self, key)
Mappingpath0
path(self, key)
For the given key, identify the containing range and its associated value at each level in the mapping.
Mappinglevels0
levels(self, key)
Mappinglast0
last(self, key)