use std::cmp::Ordering;
pub const LEAF_MIN_MEMBERS: usize = 64;
pub struct BacktrackEntry {
pub margin: f64,
pub node_idx: u32,
}
impl PartialEq for BacktrackEntry {
fn eq(&self, other: &Self) -> bool {
self.margin == other.margin
}
}
impl Eq for BacktrackEntry {}
impl PartialOrd for BacktrackEntry {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for BacktrackEntry {
fn cmp(&self, other: &Self) -> Ordering {
self.margin
.partial_cmp(&other.margin)
.unwrap_or(Ordering::Equal)
}
}
pub struct VisitedSet {
data: Vec<u64>,
}
impl VisitedSet {
pub fn new(capacity: usize) -> Self {
let size = capacity.div_ceil(64);
Self {
data: vec![0; size],
}
}
#[inline]
pub fn mark(&mut self, index: usize) -> bool {
let chunk = index / 64;
let bit = 1 << (index % 64);
unsafe {
let slot = self.data.get_unchecked_mut(chunk);
if (*slot & bit) != 0 {
return true;
}
*slot |= bit;
false
}
}
}