use std::cmp::Ordering;
use std::hash::Hash;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Direction {
Ascending,
Descending,
}
impl Direction {
pub fn apply(self, ord: Ordering) -> Ordering {
match self {
Direction::Descending => ord,
Direction::Ascending => ord.reverse(),
}
}
}
#[derive(Debug, Clone, Copy, Hash)]
pub struct TaskMetadata<const N: usize> {
pub id: &'static str,
pub dims: [&'static str; N],
pub spawn_dim: Option<&'static str>,
pub priority: &'static [(&'static str, Direction)],
}
#[derive(Debug)]
pub struct EntityMetadata<const N: usize, T> {
pub id: &'static str,
pub dims: [&'static str; N],
pub _phantom: std::marker::PhantomData<T>,
}
impl<const N: usize, T> Clone for EntityMetadata<N, T> {
fn clone(&self) -> Self {
*self
}
}
impl<const N: usize, T> Copy for EntityMetadata<N, T> {}
impl<const N: usize, T> Hash for EntityMetadata<N, T> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.id.hash(state);
self.dims.hash(state);
}
}
#[derive(Debug, Clone, Copy, Hash)]
pub struct DimensionMetadata<const N: usize> {
pub id: &'static str,
pub deps: [&'static str; N],
}
impl<const N: usize> TaskMetadata<N> {
pub fn spawn_dim_meta(&self) -> Option<DimensionMetadata<N>> {
let id = self.spawn_dim?;
let deps = self.dims;
Some(DimensionMetadata { id, deps })
}
}