use crate::structures::atom::Atom;
use crate::structures::literal::IntLiteral;
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 unsafe fn clear_value(&mut self, atom: Atom) {
if let Some(present) = self.value_of(atom) {
*self.previous_valuation.get_unchecked_mut(atom as usize) = present;
}
*self.valuation.get_unchecked_mut(atom as usize) = None;
*self.decision_indicies.get_unchecked_mut(atom as usize) = None;
}
pub fn valuation_string(&self) -> String {
self.valuation()
.atom_value_pairs()
.filter_map(|(atom, v)| match v {
None => None,
Some(true) => Some(format!(" {atom}")),
Some(false) => Some(format!("-{atom}")),
})
.collect::<Vec<_>>()
.join(" ")
}
pub fn valuations_ints(&self) -> Vec<IntLiteral> {
self.valuation()
.atom_value_pairs()
.filter_map(|(atom, v)| match v {
None => None,
Some(true) => Some(atom as IntLiteral),
Some(false) => Some(-(atom as IntLiteral)),
})
.collect()
}
pub fn internal_valuation_string(&self) -> String {
self.valuation()
.atom_value_pairs()
.filter_map(|(atom, v)| match v {
None => None,
Some(true) => Some((atom as isize).to_string()),
Some(false) => Some((-(atom as isize)).to_string()),
})
.collect::<Vec<_>>()
.join(" ")
}
pub fn internal_valuation_decision_string(&self) -> String {
unsafe {
self.valuation()
.atom_value_pairs()
.filter_map(|(atom, v)| match self.atom_decision_level_unchecked(atom) {
None => None,
Some(level) => match v {
None => None,
Some(true) => Some(format!("{atom} ({level})",)),
Some(false) => Some(format!("-{atom} ({level})",)),
},
})
.collect::<Vec<_>>()
.join(" ")
}
}
}