use crate::structures::atom::Atom;
use crate::structures::valuation::Valuation;
use super::AtomDB;
impl AtomDB {
pub fn value_of(&self, atom: Atom) -> Option<bool> {
unsafe { *self.valuation.get_unchecked(atom as usize) }
}
pub fn previous_value_of(&self, atom: Atom) -> bool {
unsafe { *self.previous_valuation.get_unchecked(atom as usize) }
}
pub fn clear_value(&mut self, atom: Atom) {
if let Some(present) = self.value_of(atom) {
unsafe { *self.previous_valuation.get_unchecked_mut(atom as usize) = present };
}
unsafe { *self.valuation.get_unchecked_mut(atom as usize) = None };
unsafe { *self.decision_indicies.get_unchecked_mut(atom as usize) = None };
}
pub fn valuation_string(&self) -> String {
self.valuation()
.av_pairs()
.filter_map(|(i, v)| {
let idx = i as Atom;
match v {
None => None,
Some(true) => Some(format!(" {}", self.external_representation(idx))),
Some(false) => Some(format!("-{}", self.external_representation(idx))),
}
})
.collect::<Vec<_>>()
.join(" ")
}
pub fn internal_valuation_string(&self) -> String {
let mut v = self
.valuation()
.av_pairs()
.filter_map(|(i, v)| match v {
None => None,
Some(true) => Some(i as isize),
Some(false) => Some(-(i as isize)),
})
.collect::<Vec<_>>();
v.sort_unstable();
v.iter()
.map(|v| v.to_string())
.collect::<Vec<_>>()
.join(" ")
}
}