Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Fischer committed Dec 13, 2024
1 parent cae12ee commit d9347c8
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions src/multiset_permutations.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use std::iter::FromIterator;

/// TODO!
/// An iterator adaptor that iterates through all the unique multiset permutations of the iterator.
/// The supplied iterator is fully consumed, so it must be finite.
///
/// See [`.multiset_permutations()`](crate::Itertools::multiset_permutations) for
/// more information.
#[derive(Debug, Clone)]
pub struct MultisetPermutations<I> {
buffer: Vec<I>,
Expand Down Expand Up @@ -98,33 +102,20 @@ mod tests {
#[test]
fn test3() {
use rand::Rng;
use std::time::Instant;

let n = 12;
let mut rng = rand::thread_rng();
let vec: Vec<i32> = (0..n).map(|_| rng.gen_range(0, 10)).collect();

println!("{:?}", vec);

let now = Instant::now();
let mut permutations1 = vec
.clone()
.into_iter()
.permutations(n)
.unique()
.collect_vec();
println!("permutations: {:.2?}", now.elapsed());

let now = Instant::now();
let mut permutations2 = vec.into_iter().multiset_permutations().collect_vec();
println!("multiset_permutations: {:.2?}", now.elapsed());

permutations1.sort();
permutations2.sort();
// println!("{:?}", permutations1);

// println!("{:?}", permutations2);

assert_eq!(permutations1, permutations2);
}

Expand Down Expand Up @@ -156,18 +147,4 @@ mod tests {
assert_eq!(iter.next(), Some(vec![]));
assert_eq!(iter.next(), None);
}

#[test]
fn timing() {
use std::time::Instant;
let now = Instant::now();

let iter = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0]
.iter()
.multiset_permutations();
let count = iter.count();

let elapsed = now.elapsed();
println!("Elapsed: {:.2?} {count}", elapsed);
}
}

0 comments on commit d9347c8

Please sign in to comment.