Skip to content

Commit

Permalink
Merge pull request #5 from est31/improvements
Browse files Browse the repository at this point in the history
Misc minor improvements and updates
  • Loading branch information
oli-obk committed May 4, 2023
2 parents 084d9d4 + 549eaca commit 14fc7a7
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 43 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: ci

on: [push, pull_request]

env:
RUSTFLAGS: -D warnings

jobs:
build:

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
toolchain: [stable, beta, nightly]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@master
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
override: true
- name: Run cargo check
run: |
cargo check --all
- name: Run cargo clippy
run: |
cargo clippy --all
- name: Compile the tests
run: |
cargo test --all --all-targets --no-run --release
- name: Run cargo doc
run: |
cargo doc --all --all-features --release
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
[workspace]
members = ["testing"]

[package]
name = "quine-mc_cluskey"
version = "0.2.4"
authors = ["Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>"]
description = "Rust implementation of the Quine-McCluskey algorithm and Petrick's method"
license = "MIT"
repository = "https://github.com/oli-obk/quine-mc_cluskey"
documentation = "https://oli-obk.github.io/quine-mc_cluskey"
documentation = "https://docs.rs/quine-mc_cluskey"
edition = "2021"

[dependencies]
quickcheck = { version = "0.3.1", optional = true }
45 changes: 25 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl quickcheck::Arbitrary for Bool {
let mut terms = 0;
arbitrary_bool(g, 10, &mut terms)
}
fn shrink(&self) -> Box<Iterator<Item=Self>> {
fn shrink(&self) -> Box<dyn Iterator<Item=Self>> {
match *self {
Bool::And(ref v) => Box::new(v.shrink().filter(|v| v.len() > 2).map(Bool::And)),
Bool::Or(ref v) => Box::new(v.shrink().filter(|v| v.len() > 2).map(Bool::Or)),
Expand Down Expand Up @@ -77,7 +77,7 @@ impl PartialEq for Bool {
(&True, &True) |
(&False, &False) => true,
(&Term(a), &Term(b)) => a == b,
(&Not(ref a), &Not(ref b)) => a == b,
(Not(a), Not(b)) => a == b,
(&And(ref a), &And(ref b)) |
(&Or(ref a), &Or(ref b)) => {
if a.len() != b.len() {
Expand Down Expand Up @@ -240,18 +240,18 @@ impl std::fmt::Debug for Bool {
And(ref a) => {
for a in a {
match *a {
And(_) | Or(_) => try!(write!(fmt, "({:?})", a)),
_ => try!(write!(fmt, "{:?}", a)),
And(_) | Or(_) => write!(fmt, "({:?})", a)?,
_ => write!(fmt, "{:?}", a)?,
}
}
Ok(())
},
Or(ref a) => {
try!(write!(fmt, "{:?}", a[0]));
write!(fmt, "{:?}", a[0])?;
for a in &a[1..] {
match *a {
Or(_) => try!(write!(fmt, " + ({:?})", a)),
_ => try!(write!(fmt, " + {:?}", a)),
Or(_) => write!(fmt, " + ({:?})", a)?,
_ => write!(fmt, " + {:?}", a)?,
}
}
Ok(())
Expand Down Expand Up @@ -342,7 +342,7 @@ impl Essentials {
}
}

#[derive(Clone, Eq, Ord)]
#[derive(Clone, Eq)]
pub struct Term {
dontcare: u32,
term: u32,
Expand All @@ -360,14 +360,19 @@ impl quickcheck::Arbitrary for Term {

impl std::cmp::PartialOrd for Term {
fn partial_cmp(&self, rhs: &Self) -> Option<std::cmp::Ordering> {
use std::cmp::Ordering::*;
match self.dontcare.partial_cmp(&rhs.dontcare) {
Some(Equal) => {},
Some(self.cmp(rhs))
}
}

impl std::cmp::Ord for Term {
fn cmp(&self, rhs: &Self) -> std::cmp::Ordering {
match self.dontcare.cmp(&rhs.dontcare) {
std::cmp::Ordering::Equal => {},
other => return other,
}
let l = self.term & !self.dontcare;
let r = rhs.term & !rhs.dontcare;
l.partial_cmp(&r)
l.cmp(&r)
}
}

Expand All @@ -376,12 +381,12 @@ impl std::fmt::Debug for Term {
for i in (0..32).rev() {
if (self.dontcare & (1 << i)) == 0 {
if (self.term & (1 << i)) == 0 {
try!(write!(fmt, "0"));
write!(fmt, "0")?;
} else {
try!(write!(fmt, "1"));
write!(fmt, "1")?;
}
} else {
try!(write!(fmt, "-"));
write!(fmt, "-")?;
}
}
Ok(())
Expand Down Expand Up @@ -429,8 +434,8 @@ impl Term {

pub fn with_dontcare(term: u32, dontcare: u32) -> Self {
Term {
dontcare: dontcare,
term: term,
dontcare,
term,
}
}

Expand Down Expand Up @@ -480,7 +485,7 @@ pub fn essential_minterms(mut minterms: Vec<Term>) -> Essentials {
let mut terms = minterms.clone();
let mut essentials: Vec<Term> = Vec::new();
while !terms.is_empty() {
let old = std::mem::replace(&mut terms, Vec::new());
let old = std::mem::take(&mut terms);
let mut combined_terms = std::collections::BTreeSet::new();
for (i, term) in old.iter().enumerate() {
for (other_i, other) in old[i..].iter().enumerate() {
Expand All @@ -498,7 +503,7 @@ pub fn essential_minterms(mut minterms: Vec<Term>) -> Essentials {
terms.dedup();
}
Essentials {
minterms: minterms,
essentials: essentials,
minterms,
essentials,
}
}
2 changes: 1 addition & 1 deletion testing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "testing"
version = "0.1.0"
authors = ["Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>"]
build = "build.rs"
edition = "2018"

[dev-dependencies]
quine-mc_cluskey = { path = "..", features = ["quickcheck"] }
Expand Down
7 changes: 1 addition & 6 deletions testing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
}
}
// the lib.rs file is intentionally empty. The tests can be found in the tests/ directory

0 comments on commit 14fc7a7

Please sign in to comment.