Skip to content

Commit 643f11b

Browse files
committed
Move entry fully into the core
1 parent 62262ea commit 643f11b

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ mod mutable_keys;
7979
mod serde;
8080
mod util;
8181

82-
#[macro_use]
8382
mod map_core;
8483

8584
pub mod map;

src/map.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::cmp::Ordering;
2424
use std::fmt;
2525

2626
use equivalent::Equivalent;
27-
use map_core::{IndexMapCore, MakeEntry, ProbeAction, Size};
27+
use map_core::IndexMapCore;
2828
use util::third;
2929
use {Bucket, Entries, HashValue};
3030

@@ -203,27 +203,13 @@ impl<K, V, S> IndexMap<K, V, S> {
203203
pub fn capacity(&self) -> usize {
204204
self.core.capacity()
205205
}
206-
207-
#[inline]
208-
fn size_class_is_64bit(&self) -> bool {
209-
self.core.size_class_is_64bit()
210-
}
211206
}
212207

213208
impl<K, V, S> IndexMap<K, V, S>
214209
where
215210
K: Hash + Eq,
216211
S: BuildHasher,
217212
{
218-
fn insert_phase_1<'a, Sz, A>(&'a mut self, key: K, action: A) -> A::Output
219-
where
220-
Sz: Size,
221-
A: ProbeAction<'a, Sz, K, V>,
222-
{
223-
let hash = hash_elem_using(&self.hash_builder, &key);
224-
self.core.insert_phase_1::<Sz, A>(hash, key, action)
225-
}
226-
227213
/// Remove all key-value pairs in the map, while preserving its capacity.
228214
///
229215
/// Computes in **O(n)** time.
@@ -280,8 +266,8 @@ where
280266
///
281267
/// Computes in **O(1)** time (amortized average).
282268
pub fn entry(&mut self, key: K) -> Entry<K, V> {
283-
self.core.reserve_one();
284-
dispatch_32_vs_64!(self.insert_phase_1::<_>(key, MakeEntry))
269+
let hash = hash_elem_using(&self.hash_builder, &key);
270+
self.core.entry(hash, key)
285271
}
286272

287273
/// Return an iterator over the key-value pairs of the map, in their order

src/map_core.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use {Bucket, HashValue};
2323

2424
/// Trait for the "size class". Either u32 or u64 depending on the index
2525
/// size needed to address an entry's index in self.core.entries.
26-
pub(crate) trait Size {
26+
trait Size {
2727
fn is_64_bit() -> bool;
2828
fn is_same_size<T: Size>() -> bool {
2929
Self::is_64_bit() == T::is_64_bit()
@@ -392,14 +392,14 @@ impl<K, V> IndexMapCore<K, V> {
392392

393393
// Return whether we need 32 or 64 bits to specify a bucket or entry index
394394
#[cfg(not(feature = "test_low_transition_point"))]
395-
pub(crate) fn size_class_is_64bit(&self) -> bool {
395+
fn size_class_is_64bit(&self) -> bool {
396396
usize::max_value() > u32::max_value() as usize
397397
&& self.raw_capacity() >= u32::max_value() as usize
398398
}
399399

400400
// for testing
401401
#[cfg(feature = "test_low_transition_point")]
402-
pub(crate) fn size_class_is_64bit(&self) -> bool {
402+
fn size_class_is_64bit(&self) -> bool {
403403
self.raw_capacity() >= 64
404404
}
405405

@@ -444,7 +444,7 @@ impl<K, V> IndexMapCore<K, V> {
444444

445445
#[inline(never)]
446446
// `Sz` is *current* Size class, before grow
447-
pub(crate) fn double_capacity<Sz>(&mut self)
447+
fn double_capacity<Sz>(&mut self)
448448
where
449449
Sz: Size,
450450
{
@@ -523,7 +523,7 @@ impl<K, V> IndexMapCore<K, V> {
523523
Some(self.swap_remove_found(probe, found))
524524
}
525525

526-
pub(crate) fn insert_phase_1<'a, Sz, A>(&'a mut self, hash: HashValue, key: K, action: A) -> A::Output
526+
fn insert_phase_1<'a, Sz, A>(&'a mut self, hash: HashValue, key: K, action: A) -> A::Output
527527
where
528528
Sz: Size,
529529
K: Eq,
@@ -590,6 +590,14 @@ impl<K, V> IndexMapCore<K, V> {
590590
dispatch_32_vs_64!(self.insert_phase_1::<_>(hash, key, InsertValue(value)))
591591
}
592592

593+
pub(crate) fn entry(&mut self, hash: HashValue, key: K) -> Entry<K, V>
594+
where
595+
K: Eq,
596+
{
597+
self.reserve_one();
598+
dispatch_32_vs_64!(self.insert_phase_1::<_>(hash, key, MakeEntry))
599+
}
600+
593601
/// Return probe (indices) and position (entries)
594602
pub(crate) fn find_using<F>(&self, hash: HashValue, key_eq: F) -> Option<(usize, usize)>
595603
where
@@ -875,7 +883,7 @@ impl<K, V> IndexMapCore<K, V> {
875883
}
876884
}
877885

878-
pub(crate) trait ProbeAction<'a, Sz: Size, K, V>: Sized {
886+
trait ProbeAction<'a, Sz: Size, K, V>: Sized {
879887
type Output;
880888
// handle an occupied spot in the map
881889
fn hit(self, entry: OccupiedEntry<'a, K, V>) -> Self::Output;
@@ -914,7 +922,7 @@ impl<'a, Sz: Size, K, V> ProbeAction<'a, Sz, K, V> for InsertValue<V> {
914922
}
915923
}
916924

917-
pub(crate) struct MakeEntry;
925+
struct MakeEntry;
918926

919927
impl<'a, Sz: Size, K: 'a, V: 'a> ProbeAction<'a, Sz, K, V> for MakeEntry {
920928
type Output = Entry<'a, K, V>;

0 commit comments

Comments
 (0)