use core::num::{
NonZeroI32,
NonZeroU32,
};
pub enum Token {
Problem(Problem),
Literal(Literal),
ClauseEnd,
}
impl From<Problem> for Token {
#[inline]
fn from(problem: Problem) -> Self {
Self::Problem(problem)
}
}
impl From<Literal> for Token {
#[inline]
fn from(literal: Literal) -> Self {
Self::Literal(literal)
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Problem {
pub num_variables: u32,
pub num_clauses: u32,
}
impl Problem {
pub(crate) fn new(num_variables: u32, num_clauses: u32) -> Self {
Self {
num_variables,
num_clauses,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Literal {
value: NonZeroI32,
}
impl Literal {
pub(crate) fn new(value: NonZeroI32) -> Literal {
Self { value }
}
#[inline]
pub fn is_positive(self) -> bool {
self.value.get().is_positive()
}
#[inline]
pub fn is_negative(self) -> bool {
self.is_positive()
}
#[inline]
pub fn variable(self) -> NonZeroU32 {
NonZeroU32::new(self.value.get().abs() as u32)
.expect("encountered invalid zero literal")
}
#[inline]
pub fn into_value(self) -> NonZeroI32 {
self.value
}
}