From d9372f6967329045d89c5d11c60e54d3140c2fb2 Mon Sep 17 00:00:00 2001 From: europeanplaice Date: Sat, 19 Feb 2022 22:14:25 +0900 Subject: [PATCH] Convert VecDeque to Vec --- Cargo.lock | 2 +- Cargo.toml | 2 +- readme.md | 18 ++-- src/dp_module.rs | 265 +++++++++++++++++++---------------------------- src/main.rs | 2 + 5 files changed, 122 insertions(+), 167 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 361e415..2538727 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -498,7 +498,7 @@ dependencies = [ [[package]] name = "subset_sum" -version = "0.8.4" +version = "0.9.0" dependencies = [ "criterion", "rand", diff --git a/Cargo.toml b/Cargo.toml index c4341b7..a293c5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "subset_sum" -version = "0.8.4" +version = "0.9.0" edition = "2018" authors = ["Tomohiro Endo "] 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." diff --git a/readme.md b/readme.md index 95f483a..04e42aa 100644 --- a/readme.md +++ b/readme.md @@ -27,7 +27,7 @@ Call `subset_sum.exe num_set.txt 3` The executable's name `subset_sum.exe` would be different from your choice. Change this example along with your environment. In this example, the output is -`[[1, 2], [2, -3, 4], [1, -3, 5]]` +`[[2, 1], [4, -3, 2], [5, -3, 1]]` ### Sequence Matcher (One-to-Many) @@ -52,9 +52,9 @@ Call `subset_sum.exe key.txt targets.txt` In this example, the output is ``` -[([3], 3), ([5], 5), ([1, -3, 4, 5], 7)] -[([3], 3), ([1, 4], 5), ([-3, 5, 5], 7)] -[([1, -3, 5], 3), ([5], 5), ([4, 3], 7)] +[([3], 3), ([5], 5), ([5, 4, -3, 1], 7)] +[([3], 3), ([4, 1], 5), ([5, 5, -3], 7)] +[([5, -3, 1], 3), ([5], 5), ([3, 4], 7)] ``` ### Sequence Matcher (Many-to-Many) @@ -117,13 +117,13 @@ subset_sum = "0.8.0" use subset_sum::dp::find_subset; fn main() { - let result = sequence_matcher(&mut vec![3, 5, 7], &mut vec![1, 5, -3, 4, 5, 3]); + let result = find_subset(&mut vec![1, 2, 3, 4, 5], 6); println!("{:?}", result); } ``` Output ``` -[[-8, -10]] +[[3, 2, 1], [4, 2], [5, 1]] ``` ### Sequence Matcher (One-to-Many) `main.rs` @@ -138,9 +138,9 @@ fn main() { Output ``` [ - [([3], 3), ([5], 5), ([1, -3, 4, 5], 7)], - [([3], 3), ([1, 4], 5), ([-3, 5, 5], 7)], - [([1, -3, 5], 3), ([5], 5), ([4, 3], 7)] +[([3], 3), ([5], 5), ([5, 4, -3, 1], 7)] +[([3], 3), ([4, 1], 5), ([5, 5, -3], 7)] +[([5, -3, 1], 3), ([5], 5), ([3, 4], 7)] ] ``` ### Sequence Matcher (Many-to-Many) diff --git a/src/dp_module.rs b/src/dp_module.rs index 1e7af74..48967c8 100644 --- a/src/dp_module.rs +++ b/src/dp_module.rs @@ -1,6 +1,5 @@ pub mod dp { //! This is a module for dynamic programming. - use std::collections::VecDeque; fn gcd_multi(v: Vec) -> u32 { let mut result = v[0]; @@ -33,24 +32,24 @@ pub mod dp { /// /// # Example /// ``` - /// use std::collections::VecDeque; + /// /// use subset_sum::dp::find_subset; /// let a = vec![-1, -3, -2, 6, 12, 48]; /// let result = find_subset(&a, 0); - /// let route1: VecDeque = VecDeque::from(vec![-1, -3, -2, 6]); - /// let answer: Vec> = vec![route1]; + /// let route1: Vec = vec![6, -2, -3, -1]; + /// let answer: Vec> = vec![route1]; /// assert_eq!(result, answer); /// ``` /// /// # Return Value /// ``` - /// use std::collections::VecDeque; + /// /// use subset_sum::dp::find_subset; /// let result = find_subset(&vec![1, 2, 3, -4, 5], 1); /// println!("{:?}", result); /// ``` - /// output: `[[1], [-3, 4]]` - pub fn find_subset(a: &Vec, n: i32) -> Vec> { + /// output: `[[1], [4, -3]]` + pub fn find_subset(a: &Vec, n: i32) -> Vec> { use std::cmp::max; use std::cmp::min; // https://stackoverflow.com/questions/43078142/subset-sum-with-negative-values-in-c-or-c @@ -60,7 +59,7 @@ pub mod dp { for i in a { b.push((i + offset as i32) as u32); } - let mut answer: Vec> = Vec::new(); + let mut answer: Vec> = Vec::new(); // We will transform the array into a new array whose elements are all positive. // And check if the transformed sum of the result of the new array is equal to the target value. @@ -70,10 +69,10 @@ pub mod dp { find_subset_fast_only_positive(&b, (n + i as i32 * offset as i32) as usize); for res in result { let mut tempsum: i32 = 0; - let mut new_res: VecDeque = VecDeque::new(); + let mut new_res: Vec = Vec::new(); for el in res { tempsum += el as i32 - offset as i32; - new_res.push_back(el as i32 - offset as i32); + new_res.push(el as i32 - offset as i32); } if tempsum == n as i32 { answer.push(new_res); @@ -88,8 +87,8 @@ pub mod dp { a: &Vec, i: usize, j: usize, - route: &mut VecDeque, - answer: &mut Vec>, + route: &mut Vec, + answer: &mut Vec>, a_min: &u32, ) { // This code is mostly copied from https://drken1215.hatenablog.com/entry/2019/12/17/190300 @@ -109,10 +108,10 @@ pub mod dp { if j as i32 - a[i - 1] as i32 >= 0 && dp[i - 1][j - a[i - 1] as usize] != 0 { // Choose this element as a candidate for an answer. - route.push_front(a[i - 1]); + route.push(a[i - 1]); rec(dp, a, i - 1, j - a[i - 1] as usize, route, answer, a_min); // Remove this element after we reach i == 0 regardless of whether we reach j == 0. - route.pop_front(); + route.pop(); } } @@ -171,23 +170,23 @@ pub mod dp { /// /// # Example /// ``` - /// use std::collections::VecDeque; + /// /// use subset_sum::dp::find_subset_fast_only_positive; /// let result = find_subset_fast_only_positive(&vec![1, 2, 3], 3); - /// let route1: VecDeque = VecDeque::from(vec![1, 2]); - /// let route2: VecDeque = VecDeque::from(vec![3]); - /// let answer: Vec> = vec![route1, route2]; + /// let route1: Vec = vec![2, 1]; + /// let route2: Vec = vec![3]; + /// let answer: Vec> = vec![route1, route2]; /// assert_eq!(result, answer); /// ``` /// # Return Value /// ``` - /// use std::collections::VecDeque; + /// /// use subset_sum::dp::find_subset_fast_only_positive; /// let result = find_subset_fast_only_positive(&vec![1, 2, 3, 4, 5], 10); /// println!("{:?}", result); /// ``` - /// output: `[[2, 3, 5], [1, 4, 5], [1, 2, 3, 4]]` - pub fn find_subset_fast_only_positive(a: &Vec, n: usize) -> Vec> { + /// output: `[[5, 3, 2], [5, 4, 1], [4, 3, 2, 1]]` + pub fn find_subset_fast_only_positive(a: &Vec, n: usize) -> Vec> { // dp is a table that stores the information of subset sum. // dp[i][j] is the number of ways to make sum j with i element. // We follow from the start of this table. @@ -210,8 +209,8 @@ pub mod dp { } } let a_length: usize = a.len(); - let mut route: VecDeque = VecDeque::new(); - let mut answer: Vec> = Vec::new(); + let mut route: Vec = Vec::new(); + let mut answer: Vec> = Vec::new(); rec(&dp, &a, a_length, n, &mut route, &mut answer, &a_min); answer @@ -227,37 +226,37 @@ pub mod dp { /// Each integer of the `key` vector corresponds to the multiple integers of the `value` vector. /// # Example /// ``` - /// use std::collections::VecDeque; + /// /// use subset_sum::dp::sequence_matcher; /// let answer = sequence_matcher(&mut vec![3, 5, 7], &mut vec![1, 5, -3, 4, 5, 3]); /// assert_eq!(answer, vec![ /// vec![ - /// (VecDeque::from(vec![3]), 3), - /// (VecDeque::from(vec![5]), 5), - /// (VecDeque::from(vec![1, -3, 4, 5]), 7), + /// (vec![3], 3), + /// (vec![5], 5), + /// (vec![5, 4, -3, 1], 7), /// ], /// vec![ - /// (VecDeque::from(vec![3]), 3), - /// (VecDeque::from(vec![1, 4]), 5), - /// (VecDeque::from(vec![-3, 5, 5]), 7), + /// (vec![3], 3), + /// (vec![4, 1], 5), + /// (vec![5, 5, -3], 7), /// ], /// vec![ - /// (VecDeque::from(vec![1, -3, 5]), 3), - /// (VecDeque::from(vec![5]), 5), - /// (VecDeque::from(vec![4, 3]), 7), + /// (vec![5, -3, 1], 3), + /// (vec![5], 5), + /// (vec![3, 4], 7), /// ], /// ]); /// - /// let answer_unchanged: Vec, i32)>> = Vec::new(); + /// let answer_unchanged: Vec, i32)>> = Vec::new(); /// let answer = sequence_matcher(&mut vec![10, 20], &mut vec![9, 21]); /// assert_eq!(answer, answer_unchanged); /// ``` pub fn sequence_matcher( key: &mut Vec, targets: &mut Vec, - ) -> Vec, i32)>> { - let mut group: Vec<(VecDeque, i32)> = Vec::new(); - let mut answer: Vec, i32)>> = Vec::new(); + ) -> Vec, i32)>> { + let mut group: Vec<(Vec, i32)> = Vec::new(); + let mut answer: Vec, i32)>> = Vec::new(); sequence_matcher_core(key, targets, &mut group, &mut answer); answer } @@ -265,8 +264,8 @@ pub mod dp { fn sequence_matcher_core( key: &mut Vec, targets: &mut Vec, - group: &mut Vec<(VecDeque, i32)>, - answer: &mut Vec, i32)>>, + group: &mut Vec<(Vec, i32)>, + answer: &mut Vec, i32)>>, ) { if key.len() == 0 && targets.len() == 0 { answer.push(group.clone()); @@ -279,7 +278,7 @@ pub mod dp { return; } - let set_: Vec> = find_subset(&targets, key[0]); + let set_: Vec> = find_subset(&targets, key[0]); for set in set_ { group.push((set.clone(), key[0])); let i2 = key[0].clone(); @@ -304,36 +303,36 @@ pub mod dp { /// # Example /// /// ```rust - ///use std::collections::VecDeque; + /// ///use subset_sum::dp::sequence_matcher_m2m; ///let answer = sequence_matcher_m2m(&mut vec![1980, 2980, 3500, 4000, 1050], &mut vec![1950, 2900, 30, 80, 3300, 200, 3980, 1050, 20], 10); ///assert_eq!(answer[0], vec![ - /// (VecDeque::from(vec![20, 30, 1050, 2900]), - /// VecDeque::from(vec![4000])), + /// (vec![20, 30, 1050, 2900], + /// vec![4000]), /// - /// (VecDeque::from(vec![200, 3300]), - /// VecDeque::from(vec![3500])), + /// (vec![200, 3300], + /// vec![3500]), /// - /// (VecDeque::from(vec![80, 1950, 3980]), - /// VecDeque::from(vec![1050, 1980, 2980])), + /// (vec![80, 1950, 3980], + /// vec![1050, 1980, 2980]), /// /// /// ]); ///assert_eq!(answer[1], vec![ - /// (VecDeque::from(vec![20, 3980]), - /// VecDeque::from(vec![4000])), + /// (vec![20, 3980], + /// vec![4000]), /// - /// (VecDeque::from(vec![80, 2900]), - /// VecDeque::from(vec![2980])), + /// (vec![80, 2900], + /// vec![2980]), /// - /// (VecDeque::from(vec![30, 1950]), - /// VecDeque::from(vec![1980])), + /// (vec![30, 1950], + /// vec![1980]), /// - /// (VecDeque::from(vec![1050]), - /// VecDeque::from(vec![1050])), + /// (vec![1050], + /// vec![1050]), /// - /// (VecDeque::from(vec![200, 3300]), - /// VecDeque::from(vec![3500])), + /// (vec![200, 3300], + /// vec![3500]), /// /// ]); /// ``` @@ -341,11 +340,11 @@ pub mod dp { key: &mut Vec, targets: &mut Vec, n_max: usize, - ) -> Vec, VecDeque)>> { + ) -> Vec, Vec)>> { use rand::seq::SliceRandom; - let mut group: Vec<(VecDeque, VecDeque)> = Vec::new(); - let mut answer: Vec, VecDeque)>> = Vec::new(); + let mut group: Vec<(Vec, Vec)> = Vec::new(); + let mut answer: Vec, Vec)>> = Vec::new(); let mut rng: rand::rngs::StdRng = rand::SeedableRng::from_seed([13; 32]); for _i in 0..n_max { sequence_matcher_core_m2m(key, targets, &mut group, &mut answer, 1, &mut key.clone()); @@ -359,8 +358,8 @@ pub mod dp { fn sequence_matcher_core_m2m( key: &mut Vec, targets: &mut Vec, - group: &mut Vec<(VecDeque, VecDeque)>, - answer: &mut Vec, VecDeque)>>, + group: &mut Vec<(Vec, Vec)>, + answer: &mut Vec, Vec)>>, n_key: usize, key_orig: &mut Vec, ) { @@ -386,7 +385,7 @@ pub mod dp { sum_key += key[i]; vec_key.push(key[i].clone()) } - let set_: Vec> = find_subset(&targets, sum_key); + let set_: Vec> = find_subset(&targets, sum_key); if set_.len() == 0 { sequence_matcher_core_m2m(key, targets, group, answer, n_key + 1, key_orig); } @@ -395,7 +394,7 @@ pub mod dp { _set.sort(); let mut _vec_key = vec_key.clone(); _vec_key.sort(); - group.push((VecDeque::from(_set), VecDeque::from(_vec_key.clone()))); + group.push((_set, _vec_key.clone())); for el in set.clone() { vec_remove(targets, el); } @@ -416,25 +415,13 @@ pub mod dp { #[test] fn test_sequence_matcher() { let answer = sequence_matcher(&mut vec![1, 6], &mut vec![1, 3, 3]); - assert_eq!( - answer, - vec![vec![ - (VecDeque::from(vec![1]), 1), - (VecDeque::from(vec![3, 3]), 6) - ]] - ); + assert_eq!(answer, vec![vec![(vec![1], 1), (vec![3, 3], 6)]]); let answer = sequence_matcher(&mut vec![10, 20], &mut vec![-10, 20, 16, 4]); // let answer = transpose(answer); - assert_eq!( - answer, - vec![vec![ - (VecDeque::from(vec![-10, 20]), 10), - (VecDeque::from(vec![16, 4]), 20), - ],] - ); + assert_eq!(answer, vec![vec![(vec![20, -10], 10), (vec![4, 16], 20),],]); - let answer_unchanged: Vec, i32)>> = Vec::new(); + let answer_unchanged: Vec, i32)>> = Vec::new(); let answer = sequence_matcher(&mut vec![10, 20], &mut vec![10, 21]); assert_eq!(answer, answer_unchanged); @@ -443,21 +430,9 @@ pub mod dp { assert_eq!( answer, vec![ - vec![ - (VecDeque::from(vec![3]), 3), - (VecDeque::from(vec![5]), 5), - (VecDeque::from(vec![1, -3, 4, 5]), 7), - ], - vec![ - (VecDeque::from(vec![3]), 3), - (VecDeque::from(vec![1, 4]), 5), - (VecDeque::from(vec![-3, 5, 5]), 7), - ], - vec![ - (VecDeque::from(vec![1, -3, 5]), 3), - (VecDeque::from(vec![5]), 5), - (VecDeque::from(vec![4, 3]), 7), - ], + vec![(vec![3], 3), (vec![5], 5), (vec![5, 4, -3, 1], 7),], + vec![(vec![3], 3), (vec![4, 1], 5), (vec![5, 5, -3], 7),], + vec![(vec![5, -3, 1], 3), (vec![5], 5), (vec![3, 4], 7),], ] ); } @@ -468,10 +443,7 @@ pub mod dp { sequence_matcher_m2m(&mut vec![1, 2, 3, 4, 5], &mut vec![11, -8, 14, -7, 5], 10); assert_eq!( answer[0], - vec![ - (VecDeque::from(vec![-8, -7, 5, 11]), VecDeque::from(vec![1])), - (VecDeque::from(vec![14]), VecDeque::from(vec![2, 3, 4, 5])), - ] + vec![(vec![-8, -7, 5, 11], vec![1]), (vec![14], vec![2, 3, 4, 5]),] ); let answer = sequence_matcher_m2m( @@ -482,19 +454,13 @@ pub mod dp { assert_eq!( answer[0], vec![ - (VecDeque::from(vec![4, 11]), VecDeque::from(vec![5, 10])), - ( - VecDeque::from(vec![273, 2100]), - VecDeque::from(vec![123, 150, 1000, 1100]) - ), + (vec![4, 11], vec![5, 10]), + (vec![273, 2100], vec![123, 150, 1000, 1100]), ] ); assert_eq!( answer[1], - vec![( - VecDeque::from(vec![4, 11, 273, 2100]), - VecDeque::from(vec![5, 10, 123, 150, 1000, 1100]) - ),] + vec![(vec![4, 11, 273, 2100], vec![5, 10, 123, 150, 1000, 1100]),] ); let answer = sequence_matcher_m2m( @@ -505,13 +471,7 @@ pub mod dp { assert_eq!(answer.len(), 0); let answer = sequence_matcher_m2m(&mut vec![-950, 10000], &mut vec![5000, 4000, 50], 10); - assert_eq!( - answer[0], - vec![( - VecDeque::from(vec![50, 4000, 5000]), - VecDeque::from(vec![-950, 10000]) - ),] - ); + assert_eq!(answer[0], vec![(vec![50, 4000, 5000], vec![-950, 10000]),]); let answer = sequence_matcher_m2m( &mut vec![99, 68, -74, 72, -38, 22], @@ -521,14 +481,8 @@ pub mod dp { assert_eq!( answer[2], vec![ - ( - VecDeque::from(vec![-92, 36, 67, 88]), - VecDeque::from(vec![99]) - ), - ( - VecDeque::from(vec![-23, 73]), - VecDeque::from(vec![-74, -38, 22, 68, 72]) - ), + (vec![-92, 36, 67, 88], vec![99]), + (vec![-23, 73], vec![-74, -38, 22, 68, 72]), ] ); @@ -542,57 +496,56 @@ pub mod dp { mod tests { use super::*; - use std::collections::VecDeque; #[test] fn test_find_subset_fast_only_positive() { let result = dp::find_subset_fast_only_positive(&vec![1, 2, 3], 3); - let route1: VecDeque = VecDeque::from(vec![1, 2]); - let route2: VecDeque = VecDeque::from(vec![3]); - let answer: Vec> = vec![route1, route2]; + let route1: Vec = vec![2, 1]; + let route2: Vec = vec![3]; + let answer: Vec> = vec![route1, route2]; assert_eq!(result, answer); let result = dp::find_subset_fast_only_positive(&vec![0, 3, 5, 10], 3); - let route1: VecDeque = VecDeque::from(vec![3]); - let route2: VecDeque = VecDeque::from(vec![0, 3]); - let answer: Vec> = vec![route1, route2]; + let route1: Vec = vec![3]; + let route2: Vec = vec![3, 0]; + let answer: Vec> = vec![route1, route2]; assert_eq!(result, answer); let result = dp::find_subset_fast_only_positive(&vec![1, 2, 3, 0], 3); - let route1: VecDeque = VecDeque::from(vec![1, 2]); - let route2: VecDeque = VecDeque::from(vec![3]); - let route3: VecDeque = VecDeque::from(vec![1, 2, 0]); - let route4: VecDeque = VecDeque::from(vec![3, 0]); - let answer: Vec> = vec![route1, route2, route3, route4]; + let route1: Vec = vec![2, 1]; + let route2: Vec = vec![3]; + let route3: Vec = vec![0, 2, 1]; + let route4: Vec = vec![0, 3]; + let answer: Vec> = vec![route1, route2, route3, route4]; assert_eq!(result, answer); } #[test] fn test_find_test() { let result = dp::find_subset(&vec![1, 2, 3], 3); - let route1: VecDeque = VecDeque::from(vec![3]); - let route2: VecDeque = VecDeque::from(vec![1, 2]); - let answer: Vec> = vec![route1, route2]; + let route1: Vec = vec![3]; + let route2: Vec = vec![2, 1]; + let answer: Vec> = vec![route1, route2]; assert_eq!(result, answer); let result = dp::find_subset(&vec![1, 2, 3, 4, 5], 10); - let route1: VecDeque = VecDeque::from(vec![2, 3, 5]); - let route2: VecDeque = VecDeque::from(vec![1, 4, 5]); - let route3: VecDeque = VecDeque::from(vec![1, 2, 3, 4]); - let answer: Vec> = vec![route1, route2, route3]; + let route1: Vec = vec![5, 3, 2]; + let route2: Vec = vec![5, 4, 1]; + let route3: Vec = vec![4, 3, 2, 1]; + let answer: Vec> = vec![route1, route2, route3]; assert_eq!(result, answer); let a = vec![75, 467, 512, -835, 770, -69, 10]; let result = dp::find_subset(&a, 711); - let route1: VecDeque = VecDeque::from(vec![770, -69, 10]); - let answer: Vec> = vec![route1]; + let route1: Vec = vec![10, -69, 770]; + let answer: Vec> = vec![route1]; assert_eq!(result, answer); let a = vec![-3, 10, 56, -33, 65, -9, 8, 72, 63, 35]; let result = dp::find_subset(&a, 7); - let route1: VecDeque = VecDeque::from(vec![-3, 10]); - let route2: VecDeque = VecDeque::from(vec![-3, -33, 8, 35]); - let answer: Vec> = vec![route1, route2]; + let route1: Vec = vec![10, -3]; + let route2: Vec = vec![35, 8, -33, -3]; + let answer: Vec> = vec![route1, route2]; assert_eq!(result, answer); let a = vec![ @@ -600,32 +553,32 @@ mod tests { -776, -711, 45552, 86746, 84248, 66278, 37475, ]; let result = dp::find_subset(&a, 72782); - let route1: VecDeque = VecDeque::from(vec![73209, -628, 201]); - let answer: Vec> = vec![route1]; + let route1: Vec = vec![201, -628, 73209]; + let answer: Vec> = vec![route1]; assert_eq!(result, answer); let a = vec![-1, 2, 3]; let result = dp::find_subset(&a, -1); - let route1: VecDeque = VecDeque::from(vec![-1]); - let answer: Vec> = vec![route1]; + let route1: Vec = vec![-1]; + let answer: Vec> = vec![route1]; assert_eq!(result, answer); let a = vec![-10, 5, -2]; let result = dp::find_subset(&a, -5); - let route1: VecDeque = VecDeque::from(vec![-10, 5]); - let answer: Vec> = vec![route1]; + let route1: Vec = vec![5, -10]; + let answer: Vec> = vec![route1]; assert_eq!(result, answer); let a = vec![-3, -5, -7]; let result = dp::find_subset(&a, -15); - let route1: VecDeque = VecDeque::from(vec![-3, -5, -7]); - let answer: Vec> = vec![route1]; + let route1: Vec = vec![-7, -5, -3]; + let answer: Vec> = vec![route1]; assert_eq!(result, answer); let a = vec![-100, 10, 20]; let result = dp::find_subset(&a, -70); - let route1: VecDeque = VecDeque::from(vec![-100, 10, 20]); - let answer: Vec> = vec![route1]; + let route1: Vec = vec![20, 10, -100]; + let answer: Vec> = vec![route1]; assert_eq!(result, answer); } } diff --git a/src/main.rs b/src/main.rs index 9206254..962361b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,12 +13,14 @@ fn main() { if Path::new(&args[2]).exists(){ let mut key: Vec = Vec::new(); for line in lines{ + // Todo: skip an empty line key.push(line.unwrap().trim().parse::().unwrap()); } let file = File::open(args[2].clone()).unwrap(); let line2 = io::BufReader::new(file).lines(); let mut targets: Vec = Vec::new(); for line in line2{ + // Todo: skip an empty line targets.push(line.unwrap().trim().parse::().unwrap()); } if args.len() == 4 && args[3] == "m2m"{