Skip to content
thiell edited this page Mar 4, 2012 · 2 revisions

RangeSet

Presentation

The RangeSet class implements a kind of set of integers internally organized as contiguous ranges (start, stop). This data structure is designed to manage cluster node indexes and is used by the NodeSet class itself.

The ClusterShell library also provides a nodeset command which has a -R switch to allow users to use most of the RangeSet class features directly from the command line, for example:

$ nodeset -R -e 1-15/2
1 3 5 7 9 11 13 15

$ nodeset -R -f 11 9 3 5 1 12 4 10
1,3-5,9-12

Thus, it can be used as a replacement for seq:

$ for i in $(nodeset -R -e 1-5,8,10-18/2); do do_something_with $i; done

Class API documentation

Please use the following command to see RangeSet API documentation:

$ pydoc ClusterShell.NodeSet.RangeSet

or as of v1.6:

$ pydoc ClusterShell.RangeSet.RangeSet

Class features

This section introduces some features of the RangeSet class. Like the NodeSet class, the RangeSet class is largely inspired from the standard Python Set class (as of v1.6, it derives from the set type).

Contructors

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
rset = RangeSet.fromlist([4, 7, 2, 3]) # => 2-4,7

Conditions

rset = RangeSet("0-10/2")
4 in rset   # returns True
5 in rset   # returns False
Clone this wiki locally