Skip to content

Commit

Permalink
lit: Cleanup and missing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jix committed Oct 4, 2024
1 parent ed3e5e9 commit b90267e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
2 changes: 1 addition & 1 deletion ir/src/var.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
//! Numeric identifiers for variables and Boolean literals
pub use imctk_lit::{lit::Lit, pol::Pol, var::Var};
pub use imctk_lit::{Lit, Pol, Var};
10 changes: 6 additions & 4 deletions lit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Numeric identifiers for variables and Boolean literals
#![allow(missing_docs, dead_code)] // FIXME prototyping
mod lit;
mod pol;
mod var;

pub mod lit;
pub mod pol;
pub mod var;
pub use lit::Lit;
pub use pol::{Negate, NegateInPlace, Pol};
pub use var::Var;
28 changes: 6 additions & 22 deletions lit/src/pol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,33 +156,23 @@ impl ops::Not for &'_ Pol {
}
}

/// Subtrait of `ops::Not` and `ops::BitXor<Pol>` for types that support Boolean negation.
///
/// Types that implement `Negate` and `Clone` should also implement `Negate` for references.
pub trait Negate:
Sized
+ ops::Not<Output = <Self as Negate>::Negated>
+ ops::BitXor<Pol, Output = <Self as Negate>::Negated>
{
// Not called Output as that's ambiguous with the supertrait's Output
/// The common output type when invoking the `!` or `^` operator.
type Negated;

#[inline(always)]
fn negate(self) -> <Self as Negate>::Negated
where
Self: Sized,
{
!self
}

#[inline(always)]
fn apply_pol(self, pol: Pol) -> <Self as Negate>::Negated {
self ^ pol
}
}

/// Subtrait of `Negate` and `ops::BitXorAssign<Pol>` for types that support in-place Boolean negation.
pub trait NegateInPlace: Negate<Negated = Self> + ops::BitXorAssign<Pol> {
/// Performs `ops::Not::not` in-place.
fn negate_in_place(&mut self);
fn apply_pol_in_place(&mut self, pol: Pol) {
*self ^= pol;
}
}

impl ops::BitXorAssign<Pol> for u64 {
Expand All @@ -196,15 +186,9 @@ impl Negate for u64 {
}

impl NegateInPlace for u64 {
#[inline(always)]
fn negate_in_place(&mut self) {
*self = !*self;
}

#[inline(always)]
fn apply_pol_in_place(&mut self, pol: Pol) {
*self ^= 0 ^ pol;
}
}

impl Negate for &u64 {
Expand Down

0 comments on commit b90267e

Please sign in to comment.