Properly handle duplicates in IBH from_iter
This commit is contained in:
parent
5fbb9de2dc
commit
ed1bd67b86
1 changed files with 6 additions and 2 deletions
|
@ -124,8 +124,12 @@ impl<D: Hash + Eq + Clone + Send + Sync, P: PartialOrd + Clone + Send + Sync> Fr
|
|||
fn from_iter<T: IntoIterator<Item = (D, P)>>(iter: T) -> Self {
|
||||
let mut this = Self::new();
|
||||
for (i, (data, priority)) in iter.into_iter().enumerate() {
|
||||
this.indices.insert(data.clone(), i);
|
||||
this.data.push(Pair::new(data, priority));
|
||||
if let Some(prev) = this.indices.insert(data.clone(), i) {
|
||||
this.indices.insert(data.clone(), prev).unwrap();
|
||||
this.data[prev] = Pair::new(data, priority);
|
||||
} else {
|
||||
this.data.push(Pair::new(data, priority));
|
||||
}
|
||||
}
|
||||
for i in (0..=(this.data.len() / 2)).rev() {
|
||||
this.sift_down(i).expect("Index error during heapify");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue