#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum Step {
Lookup,
Edge,
Visit,
Nav,
}
#[cfg(any(test, feature = "__internal-checks"))]
thread_local! {
static COUNTS: core::cell::Cell<(u64, u64)> = const { core::cell::Cell::new((0, 0)) };
static VISITS: core::cell::Cell<u64> = const { core::cell::Cell::new(0) };
static NAVS: core::cell::Cell<u64> = const { core::cell::Cell::new(0) };
}
#[inline(always)]
pub(super) fn count(step: Step) {
#[cfg(any(test, feature = "__internal-checks"))]
match step {
Step::Visit => VISITS.with(|v| v.set(v.get().saturating_add(1))),
Step::Nav => NAVS.with(|v| v.set(v.get().saturating_add(1))),
_ => COUNTS.with(|c| {
let (l, e) = c.get();
c.set(match step {
Step::Lookup => (l.saturating_add(1), e),
_ => (l, e.saturating_add(1)),
});
}),
}
#[cfg(not(any(test, feature = "__internal-checks")))]
let _ = step;
}
#[cfg(test)]
pub(super) fn take() -> (u64, u64) {
COUNTS.with(|c| c.replace((0, 0)))
}
#[cfg(test)]
pub(super) fn take_visits() -> u64 {
VISITS.with(|v| v.replace(0))
}
#[cfg(feature = "__internal-checks")]
pub(super) fn take_total() -> u64 {
let (lookups, edges) = COUNTS.with(|c| c.replace((0, 0)));
let visits = VISITS.with(|v| v.replace(0));
let navs = NAVS.with(|v| v.replace(0));
lookups
.saturating_add(edges)
.saturating_add(visits)
.saturating_add(navs)
}