Skip to content

Commit

Permalink
Remove redundant Iter
Browse files Browse the repository at this point in the history
  • Loading branch information
Maneren committed Feb 4, 2024
1 parent 23b4b72 commit 14650b7
Showing 1 changed file with 5 additions and 44 deletions.
49 changes: 5 additions & 44 deletions src/default_hashmap.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#![deny(missing_docs)]

use std::borrow::Borrow;
use std::collections::{
hash_map::{
Drain, Entry, IntoKeys, IntoValues, Iter, IterMut, Keys, RandomState, Values, ValuesMut,
},
HashMap,
use std::collections::hash_map::{
Drain, Entry, HashMap, IntoIter, IntoKeys, IntoValues, Iter, IterMut, Keys, RandomState,
Values, ValuesMut,
};
use std::default::Default;
use std::hash::{BuildHasher, Hash};
Expand Down Expand Up @@ -580,18 +578,10 @@ where
S: BuildHasher,
{
type Item = (K, V);
type IntoIter = DefaultHashMapIter<K, V, S>;
type IntoIter = IntoIter<K, V>;

fn into_iter(self) -> Self::IntoIter {
let mut keys: Vec<K> = vec![];
for k in self.keys() {
keys.push(k.to_owned());
}

DefaultHashMapIter {
_defaulthashmap: self,
keys,
}
self._inner.into_iter()
}
}

Expand Down Expand Up @@ -661,35 +651,6 @@ where
}
}

impl<K, V, S> Iterator for DefaultHashMapIter<K, V, S>
where
K: Eq + Hash,
V: Default,
S: BuildHasher,
{
type Item = (K, V);

fn next(&mut self) -> Option<Self::Item> {
match self.keys.pop() {
Some(key) => {
let val = self._defaulthashmap.remove(&key);
Option::Some((key, val))
}
None => Option::None,
}
}
}

pub struct DefaultHashMapIter<K, V, S>
where
K: Eq + Hash,
V: Default,
S: BuildHasher,
{
_defaulthashmap: DefaultHashMap<K, V, S>,
keys: Vec<K>,
}

#[macro_export]
/// A quick way to instantiate a HashMap.
///
Expand Down

0 comments on commit 14650b7

Please sign in to comment.