Skip to content

Commit

Permalink
feat: Extend<&Clause> for solvers
Browse files Browse the repository at this point in the history
  • Loading branch information
chrjabs committed Apr 15, 2024
1 parent 887cae1 commit f5921f4
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 1 deletion.
9 changes: 9 additions & 0 deletions cadical/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ impl Extend<Clause> for CaDiCaL<'_, '_> {
}
}

impl<'a> Extend<&'a Clause> for CaDiCaL<'_, '_> {
fn extend<T: IntoIterator<Item = &'a Clause>>(&mut self, iter: T) {
iter.into_iter().for_each(|cl| {
self.add_clause_ref(cl)
.expect("Error adding clause in extend")
})
}
}

impl Solve for CaDiCaL<'_, '_> {
fn signature(&self) -> &'static str {
let c_chars = unsafe { ffi::ccadical_signature() };
Expand Down
9 changes: 9 additions & 0 deletions glucose/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ impl Extend<Clause> for Glucose {
}
}

impl<'a> Extend<&'a Clause> for Glucose {
fn extend<T: IntoIterator<Item = &'a Clause>>(&mut self, iter: T) {
iter.into_iter().for_each(|cl| {
self.add_clause_ref(cl)
.expect("Error adding clause in extend")
})
}
}

impl Solve for Glucose {
fn signature(&self) -> &'static str {
let c_chars = unsafe { ffi::cglucose4_signature() };
Expand Down
9 changes: 9 additions & 0 deletions glucose/src/simp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ impl Extend<Clause> for Glucose {
}
}

impl<'a> Extend<&'a Clause> for Glucose {
fn extend<T: IntoIterator<Item = &'a Clause>>(&mut self, iter: T) {
iter.into_iter().for_each(|cl| {
self.add_clause_ref(cl)
.expect("Error adding clause in extend")
})
}
}

impl Solve for Glucose {
fn signature(&self) -> &'static str {
let c_chars = unsafe { ffi::cglucose4_signature() };
Expand Down
9 changes: 9 additions & 0 deletions ipasir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,15 @@ impl Extend<Clause> for IpasirSolver<'_, '_> {
}
}

impl<'a> Extend<&'a Clause> for IpasirSolver<'_, '_> {
fn extend<T: IntoIterator<Item = &'a Clause>>(&mut self, iter: T) {
iter.into_iter().for_each(|cl| {
self.add_clause_ref(cl)
.expect("Error adding clause in extend")
})
}
}

/// cbindgen:ignore
mod ffi {
use super::{LearnCallbackPtr, TermCallbackPtr};
Expand Down
9 changes: 9 additions & 0 deletions kissat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ impl Extend<Clause> for Kissat<'_> {
}
}

impl<'a> Extend<&'a Clause> for Kissat<'_> {
fn extend<T: IntoIterator<Item = &'a Clause>>(&mut self, iter: T) {
iter.into_iter().for_each(|cl| {
self.add_clause_ref(cl)
.expect("Error adding clause in extend")
})
}
}

impl Solve for Kissat<'_> {
fn signature(&self) -> &'static str {
let c_chars = unsafe { ffi::kissat_signature() };
Expand Down
9 changes: 9 additions & 0 deletions minisat/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ impl Extend<Clause> for Minisat {
}
}

impl<'a> Extend<&'a Clause> for Minisat {
fn extend<T: IntoIterator<Item = &'a Clause>>(&mut self, iter: T) {
iter.into_iter().for_each(|cl| {
self.add_clause_ref(cl)
.expect("Error adding clause in extend")
})
}
}

impl Solve for Minisat {
fn signature(&self) -> &'static str {
let c_chars = unsafe { ffi::cminisat_signature() };
Expand Down
9 changes: 9 additions & 0 deletions minisat/src/simp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ impl Extend<Clause> for Minisat {
}
}

impl<'a> Extend<&'a Clause> for Minisat {
fn extend<T: IntoIterator<Item = &'a Clause>>(&mut self, iter: T) {
iter.into_iter().for_each(|cl| {
self.add_clause_ref(cl)
.expect("Error adding clause in extend")
})
}
}

impl Solve for Minisat {
fn signature(&self) -> &'static str {
let c_chars = unsafe { ffi::cminisat_signature() };
Expand Down
2 changes: 1 addition & 1 deletion rustsat/src/solvers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ use thiserror::Error;
/// Trait for all SAT solvers in this library.
/// Solvers outside of this library can also implement this trait to be able to
/// use them with this library.
pub trait Solve: Extend<Clause> {
pub trait Solve: Extend<Clause> + for<'a> Extend<&'a Clause> {
/// Gets a signature of the solver implementation
fn signature(&self) -> &'static str;
/// Reserves memory in the solver until a maximum variables, if the solver
Expand Down

0 comments on commit f5921f4

Please sign in to comment.