Package ClusterShell :: Module RangeSet :: Class RangeSet
[hide private]
[frames] | no frames]

Class RangeSet

source code


Mutable set of cluster node indexes featuring a fast range-based API.

This class aims to ease the management of potentially large cluster range sets and is used by the :class:`.NodeSet` class.

RangeSet basic constructors:

>>> rset = RangeSet()            # empty RangeSet
>>> rset = RangeSet("5,10-42")   # contains 5, 10 to 42
>>> rset = RangeSet("0-10/2")    # contains 0, 2, 4, 6, 8, 10

Also any iterable of integers can be specified as first argument:

>>> RangeSet([3, 6, 8, 7, 1])
1,3,6-8
>>> rset2 = RangeSet(rset)

Padding of ranges (eg. "003-009") can be managed through a public RangeSet instance variable named padding. It may be changed at any time. Padding is a simple display feature per RangeSet object, thus current padding value is not taken into account when computing set operations. RangeSet is itself an iterator over its items as integers (instead of strings). To iterate over string items with optional padding, you can use the :meth:`RangeSet.striter`: method.

RangeSet provides methods like :meth:`RangeSet.union`, :meth:`RangeSet.intersection`, :meth:`RangeSet.difference`, :meth:`RangeSet.symmetric_difference` and their in-place versions :meth:`RangeSet.update`, :meth:`RangeSet.intersection_update`, :meth:`RangeSet.difference_update`, :meth:`RangeSet.symmetric_difference_update` which conform to the Python Set API.

Instance Methods [hide private]
new empty set object
__init__(self, pattern=None, autostep=None)
Initialize RangeSet object.
source code
 
_parse(self, pattern)
Parse string of comma-separated x-y/step -like ranges
source code
 
get_autostep(self)
Get autostep value (property)
source code
 
set_autostep(self, val)
Set autostep value (property)
source code
 
dim(self)
Get the number of dimensions of this RangeSet object.
source code
 
_sorted(self)
Get sorted list from inner set.
source code
 
__iter__(self)
Iterate over each element in RangeSet.
source code
 
striter(self)
Iterate over each (optionally padded) string element in RangeSet.
source code
 
contiguous(self)
Object-based iterator over contiguous range sets.
source code
 
__reduce__(self)
Return state information for pickling.
source code
 
__setstate__(self, dic)
called upon unpickling
source code
 
_strslices(self)
Stringify slices list (x-y/step format)
source code
 
__str__(self)
Get comma-separated range-based string (x-y/step format).
source code
 
__repr__(self)
Get comma-separated range-based string (x-y/step format).
source code
 
_contiguous_slices(self)
Internal iterator over contiguous slices in RangeSet.
source code
 
_folded_slices(self)
Internal generator that is able to retrieve ranges organized by step.
source code
 
slices(self)
Iterate over RangeSet ranges as Python slice objects.
source code
 
__getitem__(self, index)
Return the element at index or a subrange when a slice is specified.
source code
 
split(self, nbr)
Split the rangeset into nbr sub-rangesets (at most).
source code
 
add_range(self, start, stop, step=1, pad=0)
Add a range (start, stop, step and padding length) to RangeSet.
source code
 
copy(self)
Return a shallow copy of a RangeSet.
source code
 
__copy__(self)
Return a shallow copy of a RangeSet.
source code
 
__eq__(self, other)
RangeSet equality comparison.
source code
 
_wrap_set_op(self, fun, arg)
Wrap built-in set operations for RangeSet to workaround built-in set base class issues (RangeSet.__new/init__ not called)
source code
 
__or__(self, other)
Return the union of two RangeSets as a new RangeSet.
source code
 
union(self, other)
Return the union of two RangeSets as a new RangeSet.
source code
 
__and__(self, other)
Return the intersection of two RangeSets as a new RangeSet.
source code
 
intersection(self, other)
Return the intersection of two RangeSets as a new RangeSet.
source code
 
__xor__(self, other)
Return the symmetric difference of two RangeSets as a new RangeSet.
source code
 
symmetric_difference(self, other)
Return the symmetric difference of two RangeSets as a new RangeSet.
source code
 
__sub__(self, other)
Return the difference of two RangeSets as a new RangeSet.
source code
 
difference(self, other)
Return the difference of two RangeSets as a new RangeSet.
source code
 
__contains__(self, element)
Report whether an element is a member of a RangeSet.
source code
 
issubset(self, other)
Report whether another set contains this RangeSet.
source code
 
issuperset(self, other)
Report whether this RangeSet contains another set.
source code
 
__le__(self, other)
Report whether another set contains this RangeSet.
source code
 
__ge__(self, other)
Report whether this RangeSet contains another set.
source code
 
__lt__(self, other)
x<y
source code
 
__gt__(self, other)
x>y
source code
 
_binary_sanity_check(self, other)
Check that the other argument to a binary operation is also a set, raising a TypeError otherwise.
source code
 
__ior__(self, other)
Update a RangeSet with the union of itself and another.
source code
 
union_update(self, other)
Update a RangeSet with the union of itself and another.
source code
 
__iand__(self, other)
Update a RangeSet with the intersection of itself and another.
source code
 
intersection_update(self, other)
Update a RangeSet with the intersection of itself and another.
source code
 
__ixor__(self, other)
Update a RangeSet with the symmetric difference of itself and another.
source code
 
symmetric_difference_update(self, other)
Update a RangeSet with the symmetric difference of itself and another.
source code
 
__isub__(self, other)
Remove all elements of another set from this RangeSet.
source code
 
difference_update(self, other, strict=False)
Remove all elements of another set from this RangeSet.
source code
 
update(self, iterable)
Add all integers from an iterable (such as a list).
source code
 
updaten(self, rangesets)
Update a rangeset with the union of itself and several others.
source code
 
clear(self)
Remove all elements from this RangeSet.
source code
 
add(self, element, pad=0)
Add an element to a RangeSet.
source code
 
remove(self, element)
Remove an element from a RangeSet; it must be a member.
source code
 
discard(self, element)
Remove element from the RangeSet if it is a member.
source code

Inherited from set: __cmp__, __getattribute__, __len__, __ne__, __rand__, __ror__, __rsub__, __rxor__, __sizeof__, isdisjoint, pop

Inherited from object: __delattr__, __format__, __reduce_ex__, __setattr__, __subclasshook__

Class Methods [hide private]
 
fromlist(cls, rnglist, autostep=None)
Class method that returns a new RangeSet with ranges from provided list.
source code
 
fromone(cls, index, pad=0, autostep=None)
Class method that returns a new RangeSet of one single item or a single range (from integer or slice object).
source code
Static Methods [hide private]
a new object with type S, a subtype of T
__new__(cls, pattern=None, autostep=None)
Object constructor
source code
Class Variables [hide private]
  _VERSION = 3

Inherited from set: __hash__

Properties [hide private]
  autostep
autostep threshold public instance attribute

Inherited from object: __class__

Method Details [hide private]

__new__(cls, pattern=None, autostep=None)
Static Method

source code 

Object constructor

Returns: a new object with type S, a subtype of T
Overrides: object.__new__

__init__(self, pattern=None, autostep=None)
(Constructor)

source code 

Initialize RangeSet object.

:param pattern: optional string pattern :param autostep: optional autostep threshold

Returns: new empty set object
Overrides: object.__init__

dim(self)

source code 

Get the number of dimensions of this RangeSet object. Common method with RangeSetND. Here, it will always return 1 unless the object is empty, in that case it will return 0.

__iter__(self)

source code 

Iterate over each element in RangeSet.

Overrides: set.__iter__

__reduce__(self)

source code 

Return state information for pickling.

Overrides: object.__reduce__

__str__(self)
(Informal representation operator)

source code 

Get comma-separated range-based string (x-y/step format).

Overrides: object.__str__

__repr__(self)
(Representation operator)

source code 

Get comma-separated range-based string (x-y/step format).

Overrides: object.__repr__

split(self, nbr)

source code 

Split the rangeset into nbr sub-rangesets (at most). Each sub-rangeset will have the same number of elements more or less 1. Current rangeset remains unmodified. Returns an iterator.

>>> RangeSet("1-5").split(3) 
RangeSet("1-2")
RangeSet("3-4")
RangeSet("foo5")

add_range(self, start, stop, step=1, pad=0)

source code 

Add a range (start, stop, step and padding length) to RangeSet. Like the Python built-in function *range()*, the last element is the largest start + i * step less than stop.

copy(self)

source code 

Return a shallow copy of a RangeSet.

Overrides: set.copy

__eq__(self, other)
(Equality operator)

source code 

RangeSet equality comparison.

Overrides: set.__eq__

__or__(self, other)
(Or operator)

source code 

Return the union of two RangeSets as a new RangeSet.

(I.e. all elements that are in either set.)

Overrides: set.__or__

union(self, other)

source code 

Return the union of two RangeSets as a new RangeSet.

(I.e. all elements that are in either set.)

Overrides: set.union

__and__(self, other)
(And operator)

source code 

Return the intersection of two RangeSets as a new RangeSet.

(I.e. all elements that are in both sets.)

Overrides: set.__and__

intersection(self, other)

source code 

Return the intersection of two RangeSets as a new RangeSet.

(I.e. all elements that are in both sets.)

Overrides: set.intersection

__xor__(self, other)
(Exclusive-Or operator)

source code 

Return the symmetric difference of two RangeSets as a new RangeSet.

(I.e. all elements that are in exactly one of the sets.)

Overrides: set.__xor__

symmetric_difference(self, other)

source code 

Return the symmetric difference of two RangeSets as a new RangeSet.

(ie. all elements that are in exactly one of the sets.)

Overrides: set.symmetric_difference

__sub__(self, other)
(Subtraction operator)

source code 

Return the difference of two RangeSets as a new RangeSet.

(I.e. all elements that are in this set and not in the other.)

Overrides: set.__sub__

difference(self, other)

source code 

Return the difference of two RangeSets as a new RangeSet.

(I.e. all elements that are in this set and not in the other.)

Overrides: set.difference

__contains__(self, element)
(In operator)

source code 

Report whether an element is a member of a RangeSet. Element can be either another RangeSet object, a string or an integer.

Called in response to the expression ``element in self``.

Overrides: set.__contains__

issubset(self, other)

source code 

Report whether another set contains this RangeSet.

Overrides: set.issubset

issuperset(self, other)

source code 

Report whether this RangeSet contains another set.

Overrides: set.issuperset

__le__(self, other)
(Less-than-or-equals operator)

source code 

Report whether another set contains this RangeSet.

Overrides: set.__le__

__ge__(self, other)
(Greater-than-or-equals operator)

source code 

Report whether this RangeSet contains another set.

Overrides: set.__ge__

__lt__(self, other)
(Less-than operator)

source code 

x<y

Overrides: set.__lt__
(inherited documentation)

__gt__(self, other)
(Greater-than operator)

source code 

x>y

Overrides: set.__gt__
(inherited documentation)

__ior__(self, other)

source code 

Update a RangeSet with the union of itself and another.

Overrides: set.__ior__

__iand__(self, other)

source code 

Update a RangeSet with the intersection of itself and another.

Overrides: set.__iand__

intersection_update(self, other)

source code 

Update a RangeSet with the intersection of itself and another.

Overrides: set.intersection_update

__ixor__(self, other)

source code 

Update a RangeSet with the symmetric difference of itself and another.

Overrides: set.__ixor__

symmetric_difference_update(self, other)

source code 

Update a RangeSet with the symmetric difference of itself and another.

Overrides: set.symmetric_difference_update

__isub__(self, other)

source code 

Remove all elements of another set from this RangeSet.

Overrides: set.__isub__

difference_update(self, other, strict=False)

source code 

Remove all elements of another set from this RangeSet.

If strict is True, raise KeyError if an element cannot be removed. (strict is a RangeSet addition)

Overrides: set.difference_update

update(self, iterable)

source code 

Add all integers from an iterable (such as a list).

Overrides: set.update

clear(self)

source code 

Remove all elements from this RangeSet.

Overrides: set.clear

add(self, element, pad=0)

source code 

Add an element to a RangeSet. This has no effect if the element is already present.

Overrides: set.add

remove(self, element)

source code 

Remove an element from a RangeSet; it must be a member.

:param element: the element to remove :raises KeyError: element is not contained in RangeSet :raises ValueError: element is not castable to integer

Overrides: set.remove

discard(self, element)

source code 

Remove element from the RangeSet if it is a member.

If the element is not a member, do nothing.

Overrides: set.discard

Property Details [hide private]

autostep

autostep threshold public instance attribute

Get Method:
get_autostep(self) - Get autostep value (property)
Set Method:
set_autostep(self, val) - Set autostep value (property)