use fxhash::FxBuildHasher;
use indexmap::{IndexMap, IndexSet};
pub type Map<K, V> = IndexMap<K, V, FxBuildHasher>;
pub type Set<T> = IndexSet<T, FxBuildHasher>;
pub type Labels = Set<String>;
pub type States = Map<String, Set<String>>;
#[macro_export]
macro_rules! set {
[] => { $crate::types::Set::default() };
[$($value:expr,)+] => { $crate::set!($($value),+) };
[$($value:expr),*] => {
{
const CAPACITY: usize = <[()]>::len(&[$({ stringify!($value); }),*]);
let mut set = $crate::types::Set::with_capacity_and_hasher(
CAPACITY,
fxhash::FxBuildHasher::default(),
);
$(
set.insert($value);
)*
set
}
};
}
#[macro_export]
macro_rules! labels {
[] => { $crate::types::Labels::default() };
[$($label:expr),+ $(,)?] => {
{
const CAPACITY: usize = <[()]>::len(&[$({ stringify!($label); }),*]);
let mut labels = $crate::types::Labels::with_capacity_and_hasher(
CAPACITY,
fxhash::FxBuildHasher::default(),
);
$(
labels.insert(::std::string::ToString::to_string(&$label));
)*
labels
}
};
}
#[macro_export]
macro_rules! map {
[] => { $crate::types::Map::default() };
[$(($key:expr, $value:expr),)+] => { $crate::map!($(($key, $value)),+) };
[$(($key:expr, $value:expr)),*] => {
{
const CAPACITY: usize = <[()]>::len(&[$({ stringify!($key); stringify!($value); }),*]);
let mut map = $crate::types::Map::with_capacity_and_hasher(
CAPACITY,
fxhash::FxBuildHasher::default(),
);
$(
map.insert($key, $value);
)*
map
}
};
}
#[macro_export]
macro_rules! states {
[] => { $crate::types::States::default() };
[$(($label:expr, [$($state:expr),* $(,)?]),)+] => { $crate::states!($(($label, [$($state),*])),+) };
[$(($label:expr, [$($state:expr),* $(,)?])),*] => {
{
const CAPACITY: usize = <[()]>::len(&[$({ stringify!($label); $( stringify!($state); )* }),*]);
let mut states = $crate::types::States::with_capacity_and_hasher(
CAPACITY,
fxhash::FxBuildHasher::default(),
);
$(
let label = ::std::string::ToString::to_string(&$label);
let state = $crate::set![$(
::std::string::ToString::to_string(&$state)
),*];
states.insert(label, state);
)*
states
}
};
}