pub struct Lit { /* private fields */ }Expand description
Type representing literals, possibly negated boolean variables.
§Representation in Memory
Literal representation is idx << 1 with the last bit representing
whether the literal is negated or not. This way the literal can directly
be used to index data structures with the two literals of a variable
being close together.
Implementations§
Source§impl Lit
impl Lit
Sourcepub fn new_with_error(idx: u32, negated: bool) -> Result<Lit, TypeError>
pub fn new_with_error(idx: u32, negated: bool) -> Result<Lit, TypeError>
Creates a new (negated or not) literal with a given index.
§Errors
TypeError::IdxTooHigh(idx, Var::MAX_IDX) if idx > Var::MAX_IDX.
Sourcepub const unsafe fn new_unchecked(idx: u32, negated: bool) -> Lit
pub const unsafe fn new_unchecked(idx: u32, negated: bool) -> Lit
Creates a new (negated or not) literal with a given index.
Does not perform any check on the index, therefore might produce an inconsistent variable.
Only use this for performance reasons if you are sure that idx <= Var::MAX_IDX.
§Safety
idx must be guaranteed to be not higher than Var::MAX_IDX
Sourcepub const fn positive(idx: u32) -> Lit
pub const fn positive(idx: u32) -> Lit
Creates a new positive literal with a given index.
Panics if idx > Var::MAX_IDX.
Sourcepub const fn negative(idx: u32) -> Lit
pub const fn negative(idx: u32) -> Lit
Creates a new negated literal with a given index.
Panics if idx > Var::MAX_IDX.
Sourcepub const unsafe fn positive_unchecked(idx: u32) -> Lit
pub const unsafe fn positive_unchecked(idx: u32) -> Lit
Creates a new positive literal with a given index.
Does not perform any check on the index, therefore might produce an inconsistent variable.
Only use this for performance reasons if you are sure that idx <= Var::MAX_IDX.
§Safety
idx must be guaranteed to be not higher than Var::MAX_IDX
Sourcepub const unsafe fn negative_unchecked(idx: u32) -> Lit
pub const unsafe fn negative_unchecked(idx: u32) -> Lit
Creates a new negated literal with a given index.
Does not perform any check on the index, therefore might produce an inconsistent variable.
Only use this for performance reasons if you are sure that idx <= Var::MAX_IDX.
§Safety
idx must be guaranteed to be not higher than Var::MAX_IDX
Sourcepub fn var(self) -> Var
pub fn var(self) -> Var
Gets the variables that the literal corresponds to.
§Examples
let var = Var::new(5);
let lit = Lit::negative(5);
assert_eq!(var, lit.var());Sourcepub fn to_ipasir(self) -> c_int
pub fn to_ipasir(self) -> c_int
Converts the literal to an integer as accepted by
IPASIR and the
DIMACS file format. The
IPASIR literal will have idx+1 and be negative if the literal is negated. Panics if the
literal does not fit into a c_int.
§Panics
If the variable index does not fit in c_int. As c_int will almost always be
i32, this is only the case on very
esoteric platforms.
Sourcepub fn to_ipasir_with_error(self) -> Result<c_int, TypeError>
pub fn to_ipasir_with_error(self) -> Result<c_int, TypeError>
Converts the literal to an integer as accepted by
IPASIR and the DIMACS file
format. The IPASIR literal
will have idx+1 and be negative if the literal is negated.
§Errors
TypeError::IdxTooHigh(_, _) if the literal does not fit into a c_int. As c_int
will almost always be i32, it is
mostly safe to simply use Self::to_ipasir instead.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Lit
impl<'de> Deserialize<'de> for Lit
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>,
Source§impl<const N: usize, Sub> Extend<Lit> for Bimander<N, Sub>
impl<const N: usize, Sub> Extend<Lit> for Bimander<N, Sub>
Source§fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Extend<Lit> for Bitwise
impl Extend<Lit> for Bitwise
Source§fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Extend<Lit> for Clause
impl Extend<Lit> for Clause
Source§fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<const N: usize, Sub> Extend<Lit> for Commander<N, Sub>
impl<const N: usize, Sub> Extend<Lit> for Commander<N, Sub>
Source§fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<UBE, LBE> Extend<Lit> for Double<UBE, LBE>
impl<UBE, LBE> Extend<Lit> for Double<UBE, LBE>
Source§fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<CE> Extend<Lit> for Inverted<CE>
impl<CE> Extend<Lit> for Inverted<CE>
Source§fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Extend<Lit> for Ladder
impl Extend<Lit> for Ladder
Source§fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Extend<Lit> for Pairwise
impl Extend<Lit> for Pairwise
Source§fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Extend<Lit> for Totalizer
impl Extend<Lit> for Totalizer
Source§fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Lit>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl FromIterator<Lit> for Assignment
impl FromIterator<Lit> for Assignment
Source§impl FromIterator<Lit> for Bitwise
impl FromIterator<Lit> for Bitwise
Source§impl FromIterator<Lit> for Clause
impl FromIterator<Lit> for Clause
Source§impl<UBE, LBE> FromIterator<Lit> for Double<UBE, LBE>
impl<UBE, LBE> FromIterator<Lit> for Double<UBE, LBE>
Source§impl<CE> FromIterator<Lit> for Inverted<CE>
impl<CE> FromIterator<Lit> for Inverted<CE>
Source§impl FromIterator<Lit> for Ladder
impl FromIterator<Lit> for Ladder
Source§impl FromIterator<Lit> for Pairwise
impl FromIterator<Lit> for Pairwise
Source§impl FromIterator<Lit> for Totalizer
impl FromIterator<Lit> for Totalizer
Source§impl Neg for Lit
Trait implementation allowing for negating literals with the unary - operator.
impl Neg for Lit
Trait implementation allowing for negating literals with the unary - operator.
Source§impl Ord for Lit
impl Ord for Lit
Source§impl PartialOrd for Lit
impl PartialOrd for Lit
impl Copy for Lit
impl Eq for Lit
impl StructuralPartialEq for Lit
Auto Trait Implementations§
impl Freeze for Lit
impl RefUnwindSafe for Lit
impl Send for Lit
impl Sync for Lit
impl Unpin for Lit
impl UnwindSafe for Lit
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more