mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-03 02:13:11 +00:00
fix: bugs with enumeration of vars
This commit is contained in:
parent
b1a9f7bf40
commit
fa2919e824
15 changed files with 107 additions and 94 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue