Macro partitions::partition_vec
source · macro_rules! partition_vec {
($elem: expr; $len: expr) => { ... };
($($elem: expr),*) => { ... };
($($elem: expr,)*) => { ... };
($($elem: expr => $set: expr),*) => { ... };
($($elem: expr => $set: expr,)*) => { ... };
}
Expand description
Creates a PartitionVec
containing the arguments.
There are tree forms of the partition_vec!
macro:
- Create a
PartitionVec
containing a given list of elements all in distinct sets:
let partition_vec = partition_vec!['a', 'b', 'c'];
assert!(partition_vec[0] == 'a');
assert!(partition_vec[1] == 'b');
assert!(partition_vec[2] == 'c');
assert!(partition_vec.is_singleton(0));
assert!(partition_vec.is_singleton(1));
assert!(partition_vec.is_singleton(2));
- Create a
PartitionVec
containing a given list of elements in the sets specified:
let partition_vec = partition_vec![
'a' => 0,
'b' => 1,
'c' => 2,
'd' => 1,
'e' => 0,
];
assert!(partition_vec[0] == 'a');
assert!(partition_vec[1] == 'b');
assert!(partition_vec[2] == 'c');
assert!(partition_vec[3] == 'd');
assert!(partition_vec[4] == 'e');
assert!(partition_vec.same_set(0, 4));
assert!(partition_vec.same_set(1, 3));
assert!(partition_vec.is_singleton(2));
You can use any identifiers that implement Hash
and Eq
.
Elements with the same set identifiers will be placed in the same set.
These identifiers will only be used when constructing a PartitionVec
and will not be stored further.
This means println!("{:?}", partition_vec![3 => 'a', 1 => 'a'])
will display [3 => 0, 1 => 0]
.
- Create a
PartitionVec
of distinct sets from a given element and size:
let partition_vec = partition_vec!['a'; 3];
assert!(partition_vec[0] == 'a');
assert!(partition_vec[1] == 'a');
assert!(partition_vec[2] == 'a');
assert!(partition_vec.is_singleton(0));
assert!(partition_vec.is_singleton(1));
assert!(partition_vec.is_singleton(2));