pub struct Literal {
pub encoding: u32,
}
Expand description
A literal, encoded as 32 bit unsigned integer.
Fields§
§encoding: u32
We use a sign-magnitude encoding (also used by AIGER and others). This allows us to directly use this as offset.
- The least significant bit is the sign (negative if it is 1).
- The remaining bits encode the variable.
Implementations§
Source§impl Literal
impl Literal
Sourcepub const NEVER_READ: Literal
pub const NEVER_READ: Literal
Sentinel value of u32::max_value()
to detect errors.
Sourcepub fn new(value: i32) -> Literal
pub fn new(value: i32) -> Literal
Create a literal from the signed representation used in DIMACS.
Sourcepub fn decode(self) -> i32
pub fn decode(self) -> i32
DIMACS representation.
§Examples
use rate_common::literal::Literal;
assert_eq!(Literal::new(-1).decode(), -1);
Sourcepub const fn variable(self) -> Variable
pub const fn variable(self) -> Variable
§Examples
use rate_common::literal::{Literal, Variable};
assert_eq!(Literal::new(-3).variable(), Variable(3));
Sourcepub fn is_constant(self) -> bool
pub fn is_constant(self) -> bool
True if it is Literal::TOP
or Literal::BOTTOM
.
§Examples
use rate_common::literal::Literal;
assert!(Literal::TOP.is_constant());
assert!(!Literal::new(-3).is_constant());
Sourcepub fn all(maxvar: Variable) -> impl Iterator<Item = Literal>
pub fn all(maxvar: Variable) -> impl Iterator<Item = Literal>
Produce all literals from 1 and -1 up to the given variable.
§Examples
use rate_common::literal::{Literal, Variable};
assert_eq!(Literal::all(Variable(2)).collect::<Vec<_>>(),
vec!(Literal::new(1), Literal::new(-1), Literal::new(2), Literal::new(-2)));
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Literal
impl<'de> Deserialize<'de> for Literal
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for Literal
§Examples
use rate_common::literal::Literal;
assert_eq!(format!("{}", Literal::TOP), "+0");
assert_eq!(format!("{}", Literal::BOTTOM), "-0");
assert_eq!(format!("{}", Literal::new(11)), "11");
impl Display for Literal
§Examples
use rate_common::literal::Literal;
assert_eq!(format!("{}", Literal::TOP), "+0");
assert_eq!(format!("{}", Literal::BOTTOM), "-0");
assert_eq!(format!("{}", Literal::new(11)), "11");
Source§impl Index<Literal> for Assignment
impl Index<Literal> for Assignment
Source§impl Neg for Literal
Negate a literal with operator -
.
impl Neg for Literal
Negate a literal with operator -
.
§Examples
use rate_common::literal::Literal;
assert!(-Literal::TOP == Literal::BOTTOM);
Source§impl Ord for Literal
impl Ord for Literal
Source§impl PartialOrd for Literal
impl PartialOrd for Literal
impl Copy for Literal
impl Eq for Literal
impl StructuralPartialEq for Literal
Auto Trait Implementations§
impl Freeze for Literal
impl RefUnwindSafe for Literal
impl Send for Literal
impl Sync for Literal
impl Unpin for Literal
impl UnwindSafe for Literal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> HeapSpace for Twhere
T: Copy,
impl<T> HeapSpace for Twhere
T: Copy,
Source§fn heap_space(&self) -> usize
fn heap_space(&self) -> usize
The number of bytes allocated on the heap that this owns.