Ranger.src.Collections package

Submodules

Ranger.src.Collections.RangeBucketMap module

class Ranger.src.Collections.RangeBucketMap.RangeBucketMap(rangeDict=None)[source]

Bases: Ranger.src.Collections.RangeMap.RangeMap

Class used to represent a mapping of disjoint ranges to sets of items. Ranges do not coalesce. However, if a new Range is added over an existing Range, items belonging to the existing Range are retained in that Range

Methods

contains(val) Returns true if any of the ranges fully enclose the given
get(key) Get the item(s) corresponding to a given key.
iteritems([start, end]) Iterates over pairs of (Range, value)
overlaps(val) Returns true if any of the ranges at least partially overlap
put(key, val) Creates a mapping from a Range to a value, adding to
remove(aRange) Removes a range and its value(s) from the range set
whichOverlaps(val) Returns which of the Ranges overlap with a single value or
get(key)[source]

Get the item(s) corresponding to a given key. The key can be a Range or a single value that is within a Range

Parameters:

key : comparable

A single value or Range object

Returns:

A set containing all overlapping items

Raises:

KeyError

If there is no overlap with the key

ValueError

If the key type not compatible with the ranges

iteritems(start=None, end=None)[source]

Iterates over pairs of (Range, value)

Parameters:

start : comparable, optional

The starting point for iterating, inclusive

end : comparable, optional

The ending point for iterating, inclusive

Returns:

Generator of (Range intersecting [start,end], value), ordered by start point

put(key, val)[source]

Creates a mapping from a Range to a value, adding to any existing values over that Range

Parameters:

key : Range object

A Range to serve as a key

val : value, hashable

Some value that the Range should map to

Raises:

TypeError

If the key is not a Range object or value is not hashable

remove(aRange)[source]

Removes a range and its value(s) from the range set

Parameters:

aRange : A Range object

The Range to remove

Raises:

ValueError

If removing range of type not compatible with previously added ranges

TypeError

If not a Range

Ranger.src.Collections.RangeMap module

class Ranger.src.Collections.RangeMap.RangeMap(rangeDict=None)[source]

Bases: object

Class used to represent a mapping of disjoint ranges to some objects. Ranges do not coalesce. If a new Range is added over an existing Range, it overwrites the overlapping part of the existing Range

Methods

contains(val) Returns true if any of the ranges fully enclose the given
get(key) Get the item(s) corresponding to a given key.
overlaps(val) Returns true if any of the ranges at least partially overlap
put(key, val) Creates a mapping from a Range to a value.
remove(aRange) Removes a range and its value from the range set
whichOverlaps(val) Returns which of the Ranges overlap with a single value or
contains(val)[source]

Returns true if any of the ranges fully enclose the given value, which can be a single value or a Range object

Parameters:

val : A single value or a Range object

Returns:

true if any of the ranges fully enclose the given value

Raises:

ValueError

If the value type not compatible with the ranges

get(key)[source]

Get the item(s) corresponding to a given key. The key can be a Range or a single value that is within a Range

Parameters:

key : A single value or Range object

Returns:

A set containing all overlapping items

Raises:

KeyError

If there is no overlap with the key

ValueError

If the key type not compatible with the ranges

overlaps(val)[source]

Returns true if any of the ranges at least partially overlap the given value, which can be a single value or a Range object

Parameters:val : A single value or a Range object
Returns:true if any of the ranges fully enclose the given value
put(key, val)[source]

Creates a mapping from a Range to a value. Note that if the key Range overlaps any existing ranges, it will replace those Range(s) over the intersection

Parameters:

key : Range object

A Range to serve as a key

val : value

Some value that the Range should map to

Raises:

TypeError

If the key is not a Range object

remove(aRange)[source]

Removes a range and its value from the range set

Parameters:

aRange : A Range object

The Range to remove

Raises:

ValueError

If removing range of type not compatible with previously added ranges

TypeError

If not a Range

whichOverlaps(val)[source]

Returns which of the Ranges overlap with a single value or Range object

Parameters:val : A single value or a Range object
Returns:set of ranges overlapping with the value

Ranger.src.Collections.RangeSet module

class Ranger.src.Collections.RangeSet.RangeSet(ranges=None)[source]

Bases: object

Class used to represent a set of non-overlapping ranges of the same type. If a range is added that is connected to another range already in the set, those ranges are merged. Otherwise, it is added as a new range in the set

Methods

add(aRange) Adds a range to the range set.
contains(val) Returns true if any of the ranges fully enclose the given
difference(otherSet) Creates a new RangeSet in which all elements in another RangeSet
intersection(otherSet) Creates a new RangeSet that is the intersection of this and
overlaps(val) Returns true if any of the ranges at least partially overlap
remove(aRange) Removes a range from the range set.
union(otherSet) Creates a new RangeSet that is the union of this set and
whichOverlaps(val) Returns which of the Ranges overlap with a single value or
add(aRange)[source]

Adds a range to the range set. If this range is not connected to any current ranges, it will place the new range on its own. If there is a connection, any connected ranges will be merged into a single range

Parameters:

aRange : A Range object

The Range to add to the RangeSet

Raises:

ValueError

If adding range of type not compatible with previously added ranges

TypeError:

If not adding a Range

contains(val)[source]

Returns true if any of the ranges fully enclose the given value, which can be a single value or a Range object

Parameters:

val : A single value or a Range object

Returns:

true if any of the ranges fully enclose the given value

Raises:

ValueError

If the value type not compatible with the ranges

difference(otherSet)[source]

Creates a new RangeSet in which all elements in another RangeSet are taken out of this RangeSet

Parameters:

otherSet : RangeSet object

The RangeSet used for this difference

Returns:

RangeSet consisting of the difference of the two sets

Raises:

TypeError

If the object passed in is not a RangeSet

ValueError

If the value type of the ranges in the other set not compatible with the range’s values

intersection(otherSet)[source]

Creates a new RangeSet that is the intersection of this and another RangeSet

Parameters:

otherSet : RangeSet object

The RangeSet used for this intersection

Returns:

RangeSet consisting of the intersection of the two sets

Raises:

TypeError

If the object passed in is not a RangeSet

ValueError

If the value type of the ranges in the other set not compatible with the range’s values

overlaps(val)[source]

Returns true if any of the ranges at least partially overlap the given value, which can be a single value or a Range object

Parameters:val : A single value or a Range object
Returns:true if any of the ranges fully enclose the given value
remove(aRange)[source]

Removes a range from the range set.

Parameters:

aRange : A Range object

The Range to remove from the RangeSet

Raises:

ValueError

If removing range of type not compatible with previously added ranges

TypeError

If not a Range

union(otherSet)[source]

Creates a new RangeSet that is the union of this set and another RangeSet object

Parameters:

otherSet : RangeSet object

The RangeSet used for the union

Returns:

RangeSet consisting of union of two sets

Raises:

TypeError

If the object passed in is not a RangeSet

ValueError

If the value type of the set not compatible with the ranges

whichOverlaps(val)[source]

Returns which of the Ranges overlap with a single value or Range object

Parameters:val : A single value or a Range object
Returns:set of ranges overlapping with the value

Module contents