pub struct NodeSet { /* private fields */ }Expand description
A set of cluster node names supporting range notation like node[1-100].
§Examples
use consortium::node_set::NodeSet;
let ns = NodeSet::parse("node[1-5,10]").unwrap();
assert_eq!(ns.len(), 6);
assert!(ns.contains("node3"));
assert!(!ns.contains("node7"));Implementations§
Source§impl NodeSet
impl NodeSet
Sourcepub fn parse(pattern: &str) -> Result<Self>
pub fn parse(pattern: &str) -> Result<Self>
Parse a node set from a string like "node[1-10,15],other[001-050]".
Sourcepub fn parse_with_autostep(pattern: &str, autostep: Option<u32>) -> Result<Self>
pub fn parse_with_autostep(pattern: &str, autostep: Option<u32>) -> Result<Self>
Parse with explicit autostep setting.
Sourcepub fn update_str(&mut self, pattern: &str) -> Result<()>
pub fn update_str(&mut self, pattern: &str) -> Result<()>
Update from a string pattern.
Sourcepub fn intersection_update(&mut self, other: &NodeSet)
pub fn intersection_update(&mut self, other: &NodeSet)
Intersection update: keep only elements in both.
Sourcepub fn intersection(&self, other: &NodeSet) -> NodeSet
pub fn intersection(&self, other: &NodeSet) -> NodeSet
Return the intersection of this nodeset and another.
Sourcepub fn difference_update(&mut self, other: &NodeSet)
pub fn difference_update(&mut self, other: &NodeSet)
Difference update: remove elements of other from self.
Sourcepub fn difference(&self, other: &NodeSet) -> NodeSet
pub fn difference(&self, other: &NodeSet) -> NodeSet
Return the difference of this nodeset and another.
Sourcepub fn symmetric_difference_update(&mut self, other: &NodeSet)
pub fn symmetric_difference_update(&mut self, other: &NodeSet)
Symmetric difference update.
Sourcepub fn symmetric_difference(&self, other: &NodeSet) -> NodeSet
pub fn symmetric_difference(&self, other: &NodeSet) -> NodeSet
Return the symmetric difference of this nodeset and another.
Sourcepub fn iter(&self) -> impl Iterator<Item = String> + '_
pub fn iter(&self) -> impl Iterator<Item = String> + '_
Iterate all individual node names in sorted order.
Sourcepub fn index(&self, name: &str) -> Option<usize>
pub fn index(&self, name: &str) -> Option<usize>
Return the zero-based position of the node name when iterating
over this nodeset, or None if the node is not present.
This is the list-like index() method (upstream commit 484d230):
the reverse operation of NodeSet::get. Zero-padding is
significant (prune003 matches, prune3 does not).
use consortium::node_set::NodeSet;
let ns = NodeSet::parse("node[0-9,20]").unwrap();
assert_eq!(ns.index("node20"), Some(10));
assert_eq!(ns.index("node42"), None);Sourcepub fn get(&self, index: i64) -> Option<String>
pub fn get(&self, index: i64) -> Option<String>
Return the node at position index in iteration order. Negative
index counts from the end, like Python’s nodeset[index].
Returns None when out of range (Python raises IndexError).
Sourcepub fn slice(
&self,
start: Option<i64>,
stop: Option<i64>,
step: i64,
) -> Result<NodeSet>
pub fn slice( &self, start: Option<i64>, stop: Option<i64>, step: i64, ) -> Result<NodeSet>
Python-style slice nodeset[start:stop:step] over iteration order,
returned as a new nodeset. start/stop may be negative (counted
from the end); a negative step is only allowed with no start and
no stop (mirroring NodeSet._extractslice). Stepped slices span
multiple patterns exactly like upstream (commit 1b2509b).
use consortium::node_set::NodeSet;
let ns = NodeSet::parse("stone[1-9],wood[1-9]").unwrap();
assert_eq!(ns.slice(None, None, 2).unwrap().to_string(),
"stone[1,3,5,7,9],wood[2,4,6,8]");Sourcepub fn split(&self, nbr: usize) -> Vec<NodeSet>
pub fn split(&self, nbr: usize) -> Vec<NodeSet>
Split the nodeset into nbr sub-nodesets (at most).
Sourcepub fn is_superset(&self, other: &NodeSet) -> bool
pub fn is_superset(&self, other: &NodeSet) -> bool
Check if this nodeset is a superset of another.