Skip to content

Commit

Permalink
Removed GroupingMap::count and related tests, has been replaced by It…
Browse files Browse the repository at this point in the history
…ertools::counts in rust-itertools#468
  • Loading branch information
SkiFire13 committed Aug 20, 2020
1 parent 0e5dc21 commit 8be9300
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 47 deletions.
27 changes: 0 additions & 27 deletions src/grouping_map.rs
Expand Up @@ -215,33 +215,6 @@ impl<I, K, V> GroupingMap<I>
destination_map
}

/// Groups elements from the `GroupingMap` source by key and counts them.
///
/// Return a `HashMap` associating the key of each group with the number of that group's elements.
///
/// ```
/// use itertools::Itertools;
///
/// let lookup = "This is a string".chars()
/// .into_grouping_map_by(|&c| c)
/// .count();
///
/// assert_eq!(lookup[&'T'], 1);
/// assert_eq!(lookup[&'h'], 1);
/// assert_eq!(lookup[&'i'], 3);
/// assert_eq!(lookup[&'s'], 3);
/// assert_eq!(lookup[&' '], 3);
/// assert_eq!(lookup[&'a'], 1);
/// assert_eq!(lookup[&'t'], 1);
/// assert_eq!(lookup[&'r'], 1);
/// assert_eq!(lookup[&'n'], 1);
/// assert_eq!(lookup[&'g'], 1);
/// assert_eq!(lookup.len(), 10);
/// ```
pub fn count(self) -> HashMap<K, usize> {
self.fold(0, |acc, _, _| acc + 1)
}

/// Groups elements from the `GroupingMap` source by key and finds the maximum of each group.
///
/// If several elements are equally maximum, the last element is picked.
Expand Down
20 changes: 0 additions & 20 deletions tests/quick.rs
Expand Up @@ -1303,26 +1303,6 @@ quickcheck! {
assert_eq!(lookup_grouping_map, lookup_group_map);
}

fn correct_grouping_map_by_count_modulo_key(a: Vec<u8>, modulo: u8) -> () {
let modulo = if modulo == 0 { 1 } else { modulo }; // Avoid `% 0`
let count = a.len();
let lookup = a.iter().copied().into_grouping_map_by(|i| i % modulo).count();

let group_map_lookup = a.iter().copied()
.map(|i| (i % modulo, i))
.into_group_map()
.into_iter()
.map(|(key, vals)| (key, vals.len()))
.collect::<HashMap<_,_>>();
assert_eq!(lookup, group_map_lookup);

assert_eq!(lookup.values().sum::<usize>(), count);

for (&key, &count) in lookup.iter() {
assert_eq!(count, a.iter().filter(|&val| val % modulo == key).count());
}
}

fn correct_grouping_map_by_max_modulo_key(a: Vec<u8>, modulo: u8) -> () {
let modulo = if modulo == 0 { 1 } else { modulo }; // Avoid `% 0`
let lookup = a.iter().copied().into_grouping_map_by(|i| i % modulo).max();
Expand Down

0 comments on commit 8be9300

Please sign in to comment.