Skip to content

Commit

Permalink
Remove unnecessary variables
Browse files Browse the repository at this point in the history
  • Loading branch information
europeanplaice committed Mar 20, 2022
1 parent feef8ad commit 2e1e6e0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subset_sum"
version = "0.17.2"
version = "0.17.3"
edition = "2018"
authors = ["Tomohiro Endo <[email protected]>"]
description = "Solves subset sum problem and returns a set of decomposed integers. It also can match corresponding numbers from two vectors and be used for Account reconciliation."
Expand Down
26 changes: 11 additions & 15 deletions src/dp_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ pub mod dp {
}
answer2.sort();
answer2.dedup();
// answer2.sort_by_key(|x| sequence_matcher_sort(x.to_vec()));
if answer2.len() == 0 {
println!("Can't find any combination.");
}
Expand Down Expand Up @@ -472,40 +471,37 @@ pub mod dp {
combs: combs,
};
mc.par_bridge().for_each(|i| {
let keys2 = keys.clone();
let targets2 = targets.clone();
let group2 = group.clone();
let mut sum_key = 0;
let mut vec_key = vec![];
for j in i.iter() {
sum_key += keys2[*j];
vec_key.push(keys2[*j].clone());
sum_key += keys[*j];
vec_key.push(keys[*j].clone());
}
vec_key.sort();
if sum_key > targets2.iter().sum() {
if sum_key > targets.iter().sum() {
return;
}
if sum_key < *targets2.iter().min().unwrap() {
if sum_key < *targets.iter().min().unwrap() {
return;
}
if targets2.iter().max().unwrap() == &0 {
if targets.iter().max().unwrap() == &0 {
return;
}
let mut set_ = match hashmap_fs.try_lock() {
Ok(mut v) => {v.entry((targets2.clone(), sum_key))
.or_insert(find_subset(targets2.clone(), sum_key, max_target_length))
Ok(mut v) => {v.entry((targets.clone(), sum_key))
.or_insert(find_subset(targets.clone(), sum_key, max_target_length))
.clone()},
Err(_) => {find_subset(targets2.clone(), sum_key, max_target_length)}
Err(_) => {find_subset(targets.clone(), sum_key, max_target_length)}
};
if set_.len() == 0 {
return;
}
set_.sort();
set_.dedup();
set_.par_iter().for_each(|set| {
let mut keys3 = keys2.clone();
let mut targets3 = targets2.clone();
let mut group3 = group2.clone();
let mut keys3 = keys.clone();
let mut targets3 = targets.clone();
let mut group3 = group.clone();
group3.push((vec_key.clone(), set.clone()));
for j in set.clone() {
vec_remove(&mut targets3, j);
Expand Down

0 comments on commit 2e1e6e0

Please sign in to comment.