1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
}
}