Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions crates/iddqd/src/id_hash_map/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::{
map_hash::MapHash,
},
};
use alloc::collections::BTreeSet;
use core::{
fmt,
hash::{BuildHasher, Hash},
Expand Down Expand Up @@ -1508,8 +1507,6 @@ impl<T: IdHashItem, S: Clone + BuildHasher, A: Allocator> IdHashMap<T, S, A> {
&mut self,
value: T,
) -> Result<ItemIndex, DuplicateItem<T, &T>> {
let mut duplicates = BTreeSet::new();

// Check for duplicates *before* inserting the new item, because we
// don't want to partially insert the new item and then have to roll
// back.
Expand All @@ -1522,21 +1519,17 @@ impl<T: IdHashItem, S: Clone + BuildHasher, A: Allocator> IdHashMap<T, S, A> {
.entry(state, key, |index| self.items[index].key())
{
hash_table::Entry::Occupied(slot) => {
duplicates.insert(slot.get());
None
let index = slot.get();
return Err(DuplicateItem::__internal_new(
value,
vec![&self.items[index]],
));
}
hash_table::Entry::Vacant(slot) => Some(slot),
hash_table::Entry::Vacant(slot) => slot,
};

if !duplicates.is_empty() {
return Err(DuplicateItem::__internal_new(
value,
duplicates.iter().map(|ix| &self.items[*ix]).collect(),
));
}

let next_index = self.items.assert_can_grow().insert(value);
entry.unwrap().insert(next_index);
entry.insert(next_index);

Ok(next_index)
}
Expand Down
9 changes: 1 addition & 8 deletions crates/iddqd/src/id_ord_map/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::{
map_hash::MapHash,
},
};
use alloc::collections::BTreeSet;
use core::{
fmt,
hash::{BuildHasher, Hash},
Expand Down Expand Up @@ -1468,8 +1467,6 @@ impl<T: IdOrdItem> IdOrdMap<T> {
&mut self,
value: T,
) -> Result<ItemIndex, DuplicateItem<T, &T>> {
let mut duplicates = BTreeSet::new();

// Check for duplicates *before* inserting the new item, because we
// don't want to partially insert the new item and then have to roll
// back.
Expand All @@ -1482,14 +1479,10 @@ impl<T: IdOrdItem> IdOrdMap<T> {
.key_to_item
.find_index(&key, |index| self.items[index].key())
{
duplicates.insert(index);
}

if !duplicates.is_empty() {
drop(key);
return Err(DuplicateItem::__internal_new(
value,
duplicates.iter().map(|ix| &self.items[*ix]).collect(),
vec![&self.items[index]],
));
}
}
Expand Down
Loading