Skip to content

Commit

Permalink
Move SortedEncoder cache into the struct and remove cached dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekker1 committed Oct 3, 2024
1 parent bc5c8e3 commit 253ba80
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 148 deletions.
1 change: 0 additions & 1 deletion crates/pindakaas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ keywords.workspace = true
repository.workspace = true

[dependencies]
cached = "0.53"
iset = "0.3"
itertools = "0.13"
rustc-hash = "2.0"
Expand Down
68 changes: 30 additions & 38 deletions crates/pindakaas/src/cardinality/sorting_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ pub struct SortingNetworkEncoder {

impl Default for SortingNetworkEncoder {
fn default() -> Self {
Self {
sorted_encoder: SortedEncoder {
overwrite_direct_cmp: None,
overwrite_recursive_cmp: None,
..SortedEncoder::default()
},
}
let mut sorted_encoder = SortedEncoder::default();
let _ = sorted_encoder
.with_overwrite_direct_cmp(None)
.with_overwrite_recursive_cmp(None);
Self { sorted_encoder }
}
}

Expand Down Expand Up @@ -150,12 +148,11 @@ mod tests {
sorted_card_test_suite!(
{
let mut e = SortingNetworkEncoder::default();
let f = SortedEncoder {
strategy: SortedStrategy::Recursive,
overwrite_direct_cmp: None,
overwrite_recursive_cmp: None,
..SortedEncoder::default()
};
let mut f = SortedEncoder::default();
let _ = f
.with_strategy(SortedStrategy::Recursive)
.with_overwrite_direct_cmp(None)
.with_overwrite_recursive_cmp(None);
let _ = e.set_sorted_encoder(f);
e
},
Expand All @@ -167,13 +164,11 @@ mod tests {
sorted_card_test_suite!(
{
let mut e = SortingNetworkEncoder::default();
let mut f = SortedEncoder {
strategy: SortedStrategy::Recursive,
overwrite_direct_cmp: None,
overwrite_recursive_cmp: None,
..SortedEncoder::default()
};
let _ = f.set_strategy(SortedStrategy::Recursive);
let mut f = SortedEncoder::default();
let _ = f
.with_strategy(SortedStrategy::Recursive)
.with_overwrite_direct_cmp(None)
.with_overwrite_recursive_cmp(None);
let _ = e.set_sorted_encoder(f);
e
},
Expand All @@ -185,12 +180,11 @@ mod tests {
sorted_card_test_suite!(
{
let mut e = SortingNetworkEncoder::default();
let f = SortedEncoder {
strategy: SortedStrategy::Direct,
overwrite_direct_cmp: None,
overwrite_recursive_cmp: None,
..SortedEncoder::default()
};
let mut f = SortedEncoder::default();
let _ = f
.with_strategy(SortedStrategy::Direct)
.with_overwrite_direct_cmp(None)
.with_overwrite_recursive_cmp(None);
let _ = e.set_sorted_encoder(f);
e
},
Expand All @@ -202,12 +196,11 @@ mod tests {
sorted_card_test_suite!(
{
let mut e = SortingNetworkEncoder::default();
let f = SortedEncoder {
strategy: SortedStrategy::Direct,
overwrite_direct_cmp: None,
overwrite_recursive_cmp: None,
..SortedEncoder::default()
};
let mut f = SortedEncoder::default();
let _ = f
.with_strategy(SortedStrategy::Direct)
.with_overwrite_direct_cmp(None)
.with_overwrite_recursive_cmp(None);
let _ = e.set_sorted_encoder(f);
e
},
Expand All @@ -219,12 +212,11 @@ mod tests {
sorted_card_test_suite!(
{
let mut e = SortingNetworkEncoder::default();
let f = SortedEncoder {
strategy: SortedStrategy::Mixed(2),
overwrite_direct_cmp: None,
overwrite_recursive_cmp: None,
..SortedEncoder::default()
};
let mut f = SortedEncoder::default();
let _ = f
.with_strategy(SortedStrategy::Mixed(2))
.with_overwrite_direct_cmp(None)
.with_overwrite_recursive_cmp(None);
let _ = e.set_sorted_encoder(f);
e
},
Expand Down
2 changes: 1 addition & 1 deletion crates/pindakaas/src/linear/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
Linear, LinearConstraint, Lit, Result, Unsatisfiable,
};

#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct LinearAggregator {
sorted_encoder: SortedEncoder,
sort_same_coefficients: usize,
Expand Down
Loading

0 comments on commit 253ba80

Please sign in to comment.