Skip to content

Commit 3b136f1

Browse files
committed
Use the bucket API from hashbrown v0.16.1
This is similar to indexmap-rs/indexmap#424, simplify a lot of code by using a bucket index in `OccupiedEntry` rather than having to split references. The effects are a little more pronounced here because our `RefMut` needed **3** references, due to the extra offset tracking, so with that gone, now *every* `*Entry` type is reduced in size.
1 parent 36c5486 commit 3b136f1

File tree

6 files changed

+326
-422
lines changed

6 files changed

+326
-422
lines changed

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ bench = false
1515

1616
[dependencies]
1717
equivalent = { version = "1.0", default-features = false }
18+
hashbrown = { version = "0.16.1", default-features = false }
1819

1920
arbitrary = { version = "1.0", optional = true, default-features = false }
2021
quickcheck = { version = "1.0", optional = true, default-features = false }
@@ -23,10 +24,6 @@ borsh = { version = "1.2", optional = true, default-features = false }
2324
rayon = { version = "1.9", optional = true }
2425
sval = { version = "2", optional = true, default-features = false }
2526

26-
[dependencies.hashbrown]
27-
version = "0.16.0"
28-
default-features = false
29-
3027
# serde v1.0.220 is the first version that released with `serde_core`.
3128
# This is required to avoid conflict with other `serde` users which may require an older version.
3229
[target.'cfg(any())'.dependencies]

src/map.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ where
760760
/// Computes in **O(1)** time (amortized average).
761761
pub fn entry(&mut self, key: K) -> Entry<'_, K, V> {
762762
let hash = self.hash(&key);
763-
self.core.entry(hash, key)
763+
Entry::new(&mut self.core, hash, key)
764764
}
765765

766766
/// Creates a splicing iterator that replaces the specified range in the map
@@ -1564,10 +1564,7 @@ impl<K, V, S> RingMap<K, V, S> {
15641564
///
15651565
/// Computes in **O(1)** time.
15661566
pub fn get_index_entry(&mut self, index: usize) -> Option<IndexedEntry<'_, K, V>> {
1567-
if index >= self.len() {
1568-
return None;
1569-
}
1570-
Some(IndexedEntry::new(&mut self.core, index))
1567+
IndexedEntry::new(&mut self.core, index)
15711568
}
15721569

15731570
/// Get an array of `N` key-value pairs by `N` indices

0 commit comments

Comments
 (0)