fix: bugs with enumeration of vars

This commit is contained in:
Shunsuke Shibayama 2023-03-06 19:44:49 +09:00
parent b1a9f7bf40
commit fa2919e824
15 changed files with 107 additions and 94 deletions

View file

@ -205,11 +205,20 @@ impl<K: Hash + Eq, V> Dict<K, V> {
self.dict.remove(k)
}
/// NOTE: This method does not consider pairing with values and keys. That is, a value may be paired with a different key (can be considered equal).
/// If you need to consider the pairing of the keys and values, use `guaranteed_extend` instead.
#[inline]
pub fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I) {
self.dict.extend(iter);
}
#[inline]
pub fn guaranteed_extend<I: IntoIterator<Item = (K, V)>>(&mut self, other: I) {
for (k, v) in other {
self.dict.entry(k).or_insert(v);
}
}
#[inline]
pub fn merge(&mut self, other: Self) {
self.dict.extend(other.dict);
@ -222,9 +231,9 @@ impl<K: Hash + Eq, V> Dict<K, V> {
}
#[inline]
pub fn diff(mut self, other: Self) -> Self {
for (k, _) in other.dict {
self.dict.remove(&k);
pub fn diff(mut self, other: &Self) -> Self {
for k in other.dict.keys() {
self.dict.remove(k);
}
self
}

View file

@ -40,7 +40,7 @@ pub fn levenshtein(a: &str, b: &str, limit: usize) -> Option<usize> {
(dcol[m] <= limit).then_some(dcol[m])
}
pub fn get_similar_name<'a, S: ?Sized, I: Iterator<Item = &'a S> + Clone>(
pub fn get_similar_name<'a, S: ?Sized, I: Iterator<Item = &'a S>>(
candidates: I,
name: &str,
) -> Option<&'a S>
@ -58,7 +58,7 @@ where
}
}
pub fn get_similar_name_and_some<'a, S: ?Sized, T, I: Iterator<Item = (&'a T, &'a S)> + Clone>(
pub fn get_similar_name_and_some<'a, S: ?Sized, T, I: Iterator<Item = (&'a T, &'a S)>>(
candidates: I,
name: &str,
) -> Option<(&'a T, &'a S)>