Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Ockajak committed Jul 14, 2024
1 parent 58f2f8f commit c5a81f1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
8 changes: 4 additions & 4 deletions src/extensions/collectible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ pub trait Collectible<Item>: IntoIterator<Item = Item> {
Self: IntoIterator<Item = Item> + Default + Extend<Item>,
{
let iterator = self.into_iter();
let mut result: HashMap<K, Self> = HashMap::with_capacity(iterator.size_hint().0);
let mut result = HashMap::<K, Self>::with_capacity(iterator.size_hint().0);
for item in iterator {
result.entry(to_key(&item)).or_default().extend(iter::once(item));
}
Expand Down Expand Up @@ -723,7 +723,7 @@ pub trait Collectible<Item>: IntoIterator<Item = Item> {
Self: Sized,
{
let iterator = self.into_iter();
let mut result: HashMap<K, B> = HashMap::with_capacity(iterator.size_hint().0);
let mut result = HashMap::with_capacity(iterator.size_hint().0);
for item in iterator {
let key = to_key(&item);
let new_value = if let Some(value) = result.remove(&key) {
Expand Down Expand Up @@ -767,7 +767,7 @@ pub trait Collectible<Item>: IntoIterator<Item = Item> {
Self: IntoIterator<Item = Item> + Sized,
{
let iterator = self.into_iter();
let mut result: HashMap<K, Item> = HashMap::with_capacity(iterator.size_hint().0);
let mut result = HashMap::with_capacity(iterator.size_hint().0);
for item in iterator {
let key = to_key(&item);
let new_value = if let Some(value) = result.remove(&key) { function(value, item) } else { item };
Expand Down Expand Up @@ -1244,7 +1244,7 @@ pub trait Collectible<Item>: IntoIterator<Item = Item> {
Self: IntoIterator<Item = Item> + FromIterator<Item>,
{
let elements_iterator = elements.iterator();
let mut replaced_items: HashMap<&Item, LinkedList<Item>> = HashMap::with_capacity(elements_iterator.size_hint().0);
let mut replaced_items = HashMap::<&Item, LinkedList<Item>>::with_capacity(elements_iterator.size_hint().0);
for (item, replacement) in elements_iterator.zip(replacements.into_iter()) {
replaced_items.entry(item).or_default().push_back(replacement);
}
Expand Down
40 changes: 20 additions & 20 deletions src/extensions/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub trait Map<Key, Value> {
/// (2, "b"),
/// (3, "c"),
/// ]);
/// let e: HashMap<i32, &str> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// assert!(a.all(|(&k, &v)| k > 0 && v.len() > 0));
/// assert!(e.all(|(&k, _)| k > 0));
Expand Down Expand Up @@ -156,7 +156,7 @@ pub trait Map<Key, Value> {
/// (2, "b"),
/// (3, "c"),
/// ]);
/// let e: HashMap<i32, &str> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// assert!(a.any(|(&k, &v)| k > 0 && v.len() > 0));
///
Expand Down Expand Up @@ -208,7 +208,7 @@ pub trait Map<Key, Value> {
/// (2, "a"),
/// (3, "a"),
/// ]);
/// let e: HashMap<i32, &str> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// assert_eq!(a.count_unique(), 3);
/// assert_eq!(b.count_unique(), 1);
Expand All @@ -234,7 +234,7 @@ pub trait Map<Key, Value> {
/// (2, "b"),
/// (3, "c"),
/// ]);
/// let e: HashMap<i32, &str> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// assert_eq!(a.delete(&2), HashMap::from([
/// (1, "a"),
Expand Down Expand Up @@ -922,7 +922,7 @@ pub trait Map<Key, Value> {
/// (2, "b"),
/// (3, "c"),
/// ]);
/// let e: HashMap<i32, &str> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// let intersection = a.intersect(&vec![(4, "x"), (2, "b"), (3, "y"), (4, "x")]);
///
Expand Down Expand Up @@ -1167,7 +1167,7 @@ pub trait Map<Key, Value> {
/// (3, "b"),
/// (-3, "c"),
/// ]);
/// let e: HashMap<i32, &str> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// assert_eq!(a.max_by(|x, y| x.0.cmp(y.0)), Some((&3, &"b")));
///
Expand All @@ -1192,7 +1192,7 @@ pub trait Map<Key, Value> {
/// (3, "b"),
/// (-5, "c"),
/// ]);
/// let e: HashMap<i32, &str> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// assert_eq!(a.max_by_key(|(k, _)| k.abs()), Some((&-5, &"c")));
///
Expand All @@ -1216,7 +1216,7 @@ pub trait Map<Key, Value> {
/// (1, 2),
/// (2, 3),
/// ]);
/// let e: HashMap<i32, i32> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// assert_eq!(a.max_item(), Some((&2, &3)));
///
Expand Down Expand Up @@ -1248,7 +1248,7 @@ pub trait Map<Key, Value> {
/// (3, "b"),
/// (-5, "c"),
/// ]);
/// let e: HashMap<i32, i32> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// assert_eq!(a.min_by(|x, y| x.0.cmp(y.0)), Some((&-5, &"c")));
///
Expand All @@ -1273,7 +1273,7 @@ pub trait Map<Key, Value> {
/// (3, "b"),
/// (-5, "c"),
/// ]);
/// let e: HashMap<i32, &str> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// assert_eq!(a.min_by_key(|(k, _)| k.abs()), Some((&0, &"a")));
///
Expand All @@ -1297,7 +1297,7 @@ pub trait Map<Key, Value> {
/// (1, 2),
/// (2, 3),
/// ]);
/// let e: HashMap<i32, i32> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// assert_eq!(a.min_item(), Some((&0, &1)));
///
Expand Down Expand Up @@ -1330,7 +1330,7 @@ pub trait Map<Key, Value> {
/// (3, "b"),
/// (-5, "c"),
/// ]);
/// let e: HashMap<i32, &str> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// assert_eq!(a.minmax_by(|x, y| x.0.cmp(y.0)), Some(((&-5, &"c"), (&3, &"b"))));
///
Expand Down Expand Up @@ -1358,7 +1358,7 @@ pub trait Map<Key, Value> {
/// (3, "b"),
/// (-5, "c"),
/// ]);
/// let e: HashMap<i32, &str> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// assert_eq!(a.minmax_by_key(|(k, _)| k.abs()), Some(((&0, &"a"), (&-5, &"c"))));
/// assert_eq!(e.minmax_by_key(|(k, _)| k.abs()), None);
Expand All @@ -1382,7 +1382,7 @@ pub trait Map<Key, Value> {
/// (1, 2),
/// (2, 3),
/// ]);
/// let e: HashMap<i32, i32> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// assert_eq!(a.minmax_item(), Some(((&0, &1), (&2, &3))));
///
Expand Down Expand Up @@ -1550,7 +1550,7 @@ pub trait Map<Key, Value> {
/// (2, 3),
/// (3, 4),
/// ]);
/// let e: HashMap<i32, i32> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// let product = a.product_keys();
///
Expand Down Expand Up @@ -1592,7 +1592,7 @@ pub trait Map<Key, Value> {
/// (2, 3),
/// (3, 4),
/// ]);
/// let e: HashMap<i32, i32> = HashMap::new();
/// let e = HashMap::<i32, i32>::new();
///
/// let product = a.product_values();
///
Expand Down Expand Up @@ -1721,7 +1721,7 @@ pub trait Map<Key, Value> {
/// (2, "b"),
/// (3, "c"),
/// ]);
/// let e: HashMap<i32, &str> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// assert!(a.subset(&vec![4, 3, 2, 2, 1]));
/// assert!(e.subset(&vec![1]));
Expand Down Expand Up @@ -1816,7 +1816,7 @@ pub trait Map<Key, Value> {
/// (2, "b"),
/// (3, "c"),
/// ]);
/// let e: HashMap<i32, &str> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// assert!(a.superset(&vec![3, 1]));
/// assert!(a.superset(&vec![]));
Expand Down Expand Up @@ -1857,7 +1857,7 @@ pub trait Map<Key, Value> {
/// (2, 3),
/// (3, 4),
/// ]);
/// let e: HashMap<i32, i32> = HashMap::new();
/// let e = HashMap::<i32, &str>::new();
///
/// let sum = a.sum_keys();
///
Expand Down Expand Up @@ -1900,7 +1900,7 @@ pub trait Map<Key, Value> {
/// (2, 3),
/// (3, 4),
/// ]);
/// let e: HashMap<i32, i32> = HashMap::new();
/// let e = HashMap::<i32, i32>::new();
///
/// let sum = a.sum_values();
///
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/ordered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ pub(crate) fn equivalent<'a, Item: Eq + Hash + 'a>(
iterator: impl Iterator<Item = &'a Item>, elements: &'a impl Iterable<Item<'a> = &'a Item>,
) -> bool {
let elements_iterator = elements.iterator();
let mut excluded: HashMap<&Item, usize> = HashMap::with_capacity(iterator.size_hint().0);
let mut excluded = HashMap::<&Item, usize>::with_capacity(iterator.size_hint().0);
let mut remaining = 0_usize;
for item in elements_iterator {
*excluded.entry(item).or_default() += 1;
Expand Down
18 changes: 9 additions & 9 deletions src/extensions/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ pub trait Sequence<Item> {
Self: IntoIterator<Item = Item> + FromIterator<Item>,
{
let iterator = self.into_iter();
let mut values: HashSet<Item> = HashSet::with_capacity(iterator.size_hint().0);
let mut duplicates: HashSet<Item> = HashSet::with_capacity(iterator.size_hint().0);
let mut values = HashSet::with_capacity(iterator.size_hint().0);
let mut duplicates = HashSet::with_capacity(iterator.size_hint().0);
iterator
.flat_map(|item| {
if !duplicates.contains(&item) {
Expand Down Expand Up @@ -480,8 +480,8 @@ pub trait Sequence<Item> {
Self: IntoIterator<Item = Item> + FromIterator<Item>,
{
let iterator = self.into_iter();
let mut values: HashMap<K, Item> = HashMap::with_capacity(iterator.size_hint().0);
let mut duplicates: HashSet<K> = HashSet::with_capacity(iterator.size_hint().0);
let mut values = HashMap::with_capacity(iterator.size_hint().0);
let mut duplicates = HashSet::with_capacity(iterator.size_hint().0);
iterator
.flat_map(|item| {
let key = to_key(&item);
Expand Down Expand Up @@ -1828,7 +1828,7 @@ pub trait Sequence<Item> {
Self: IntoIterator<Item = Item> + FromIterator<Item>,
{
let iterator = self.into_iter();
let mut occurred: HashSet<Item> = HashSet::with_capacity(iterator.size_hint().0);
let mut occurred = HashSet::with_capacity(iterator.size_hint().0);
iterator
.flat_map(|item| {
if !occurred.contains(&item) {
Expand Down Expand Up @@ -1863,7 +1863,7 @@ pub trait Sequence<Item> {
Self: IntoIterator<Item = Item> + FromIterator<Item>,
{
let iterator = self.into_iter();
let mut occurred: HashSet<K> = HashSet::with_capacity(iterator.size_hint().0);
let mut occurred = HashSet::with_capacity(iterator.size_hint().0);
iterator
.filter(|item| {
let key = to_key(item);
Expand Down Expand Up @@ -2238,7 +2238,7 @@ pub(crate) fn windowed<'a, Item: Clone + 'a, Collection: FromIterator<Item>, Res
) -> Result {
assert_ne!(size, 0, "window size must be non-zero");
assert_ne!(step, 0, "step must be non-zero");
let mut window: LinkedList<Item> = LinkedList::new();
let mut window = LinkedList::<Item>::new();
iterator
.flat_map(|item| {
window.push_back(item.clone());
Expand All @@ -2263,8 +2263,8 @@ where
{
assert_ne!(size, 0, "window size must be non-zero");
assert_ne!(step, 0, "step must be non-zero");
let mut window: LinkedList<Item> = LinkedList::new();
let mut init: LinkedList<Item> = LinkedList::new();
let mut window = LinkedList::<Item>::new();
let mut init = LinkedList::<Item>::new();
unfold(|| {
while window.len() < size {
if let Some(item) = iterator.next() {
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/traversable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ pub(crate) fn group_fold<'a, Item: 'a, K: Eq + Hash, B: Clone>(
iterator: impl Iterator<Item = &'a Item>, mut to_key: impl FnMut(&Item) -> K, initial_value: B,
mut function: impl FnMut(B, &Item) -> B,
) -> HashMap<K, B> {
let mut result: HashMap<K, B> = HashMap::with_capacity(iterator.size_hint().0);
let mut result = HashMap::with_capacity(iterator.size_hint().0);
for item in iterator {
let key = to_key(item);
let new_value = match result.remove(&key) {
Expand All @@ -698,7 +698,7 @@ pub(crate) fn group_reduce<'a, Item: Clone + 'a, K: Eq + Hash>(
iterator: impl Iterator<Item = &'a Item>, mut to_key: impl FnMut(&Item) -> K,
mut function: impl FnMut(&Item, &Item) -> Item,
) -> HashMap<K, Item> {
let mut result: HashMap<K, Item> = HashMap::with_capacity(iterator.size_hint().0);
let mut result = HashMap::with_capacity(iterator.size_hint().0);
for item in iterator {
let key = to_key(item);
let new_value = match result.remove(&key) {
Expand Down

0 comments on commit c5a81f1

Please sign in to comment.