#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Transition;
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Place;
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Id<T> {
pub(super) index: usize,
kind: T,
}
pub type Tid = Id<Transition>;
impl Tid {
#[inline]
pub(super) fn new(index: usize) -> Self {
Self {
index,
kind: Transition,
}
}
#[inline(always)]
pub(super) fn assert(self, count: usize) {
assert!(self.index < count, "Transition id out of range");
}
}
pub type Pid = Id<Place>;
impl Pid {
#[inline]
pub(super) fn new(index: usize) -> Self {
Self { index, kind: Place }
}
#[inline(always)]
pub(super) fn assert(self, count: usize) {
assert!(self.index < count, "Place id out of range");
}
}
pub struct Ids<T> {
pub(super) start: usize,
pub(super) end: usize,
pub(super) kind: T,
}
impl<T: Copy> Iterator for Ids<T> {
type Item = Id<T>;
fn next(&mut self) -> Option<Id<T>> {
if self.start < self.end {
let id = Id {
index: self.start,
kind: self.kind,
};
self.start += 1;
Some(id)
} else {
None
}
}
}
impl<T: Copy> DoubleEndedIterator for Ids<T> {
fn next_back(&mut self) -> Option<Id<T>> {
if self.start < self.end {
self.end -= 1;
Some(Id {
index: self.end,
kind: self.kind,
})
} else {
None
}
}
}
impl<T: Copy> ExactSizeIterator for Ids<T> {
fn len(&self) -> usize {
self.end - self.start
}
}