Skip to main content

NodeSet

Struct NodeSet 

Source
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

Source

pub fn new() -> Self

Create an empty NodeSet.

Source

pub fn parse(pattern: &str) -> Result<Self>

Parse a node set from a string like "node[1-10,15],other[001-050]".

Source

pub fn parse_with_autostep(pattern: &str, autostep: Option<u32>) -> Result<Self>

Parse with explicit autostep setting.

Source

pub fn len(&self) -> usize

Number of individual nodes in the set.

Source

pub fn is_empty(&self) -> bool

Whether the set is empty.

Source

pub fn contains(&self, node: &str) -> bool

Check if a specific node name is in the set.

Source

pub fn update(&mut self, other: &NodeSet)

Update (union) this nodeset with another.

Source

pub fn update_str(&mut self, pattern: &str) -> Result<()>

Update from a string pattern.

Source

pub fn union(&self, other: &NodeSet) -> NodeSet

Return the union of this nodeset and another.

Source

pub fn intersection_update(&mut self, other: &NodeSet)

Intersection update: keep only elements in both.

Source

pub fn intersection(&self, other: &NodeSet) -> NodeSet

Return the intersection of this nodeset and another.

Source

pub fn difference_update(&mut self, other: &NodeSet)

Difference update: remove elements of other from self.

Source

pub fn difference(&self, other: &NodeSet) -> NodeSet

Return the difference of this nodeset and another.

Source

pub fn symmetric_difference_update(&mut self, other: &NodeSet)

Symmetric difference update.

Source

pub fn symmetric_difference(&self, other: &NodeSet) -> NodeSet

Return the symmetric difference of this nodeset and another.

Source

pub fn clear(&mut self)

Clear all nodes from this set.

Source

pub fn iter(&self) -> impl Iterator<Item = String> + '_

Iterate all individual node names in sorted order.

Source

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);
Source

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).

Source

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]");
Source

pub fn split(&self, nbr: usize) -> Vec<NodeSet>

Split the nodeset into nbr sub-nodesets (at most).

Source

pub fn is_subset(&self, other: &NodeSet) -> bool

Check if this nodeset is a subset of another.

Source

pub fn is_superset(&self, other: &NodeSet) -> bool

Check if this nodeset is a superset of another.

Trait Implementations§

Source§

impl Clone for NodeSet

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NodeSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NodeSet

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for NodeSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for NodeSet

Source§

type Err = NodeSetError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.