11//! This is the core implementation that doesn't depend on the hasher at all.
22//!
3- //! The methods of `IndexMapCore ` don't use any Hash properties of K.
3+ //! The methods of `Core ` don't use any Hash properties of K.
44//!
55//! It's cleaner to separate them out, then the compiler checks that we are not
66//! using Hash at all in these methods.
1010mod entry;
1111mod extract;
1212
13- pub mod raw_entry_v1;
14-
1513use alloc:: vec:: { self , Vec } ;
1614use core:: mem;
1715use core:: ops:: RangeBounds ;
@@ -23,12 +21,12 @@ use crate::{Bucket, Equivalent, HashValue, TryReserveError};
2321type Indices = hash_table:: HashTable < usize > ;
2422type Entries < K , V > =Vec < Bucket < K , V > > ;
2523
26- pub use entry:: { Entry , IndexedEntry , OccupiedEntry , VacantEntry } ;
24+ pub use entry:: { OccupiedEntry , VacantEntry } ;
2725pub ( crate ) use extract:: ExtractCore ;
2826
2927/// Core of the map that does not depend on S
30- #[ derive( Debug ) ]
31- pub ( crate ) struct IndexMapCore < K , V > {
28+ #[ cfg_attr ( feature = "test_debug" , derive( Debug ) ) ]
29+ pub ( crate ) struct Core < K , V > {
3230/// indices mapping from the entry hash to its index.
3331indices : Indices ,
3432/// entries is a dense vec maintaining entry order.
@@ -76,7 +74,7 @@ fn insert_bulk_no_grow<K, V>(indices: &mut Indices, entries: &[Bucket<K, V>]) {
7674}
7775}
7876
79- impl < K , V > Clone for IndexMapCore < K , V >
77+ impl < K , V > Clone for Core < K , V >
8078where
8179K : Clone ,
8280V : Clone ,
@@ -98,21 +96,21 @@ where
9896}
9997}
10098
101- impl < K , V > IndexMapCore < K , V > {
99+ impl < K , V > Core < K , V > {
102100/// The maximum capacity before the `entries` allocation would exceed `isize::MAX`.
103101const MAX_ENTRIES_CAPACITY : usize =( isize:: MAX as usize ) /size_of :: < Bucket < K , V > > ( ) ;
104102
105103#[ inline]
106104pub ( crate ) const fn new ( ) ->Self {
107- IndexMapCore {
105+ Core {
108106indices : Indices :: new ( ) ,
109107entries : Vec :: new ( ) ,
110108}
111109}
112110
113111#[ inline]
114112pub ( crate ) fn with_capacity ( n : usize ) ->Self {
115- IndexMapCore {
113+ Core {
116114indices : Indices :: with_capacity ( n) ,
117115entries : Vec :: with_capacity ( n) ,
118116}
@@ -305,6 +303,15 @@ impl<K, V> IndexMapCore<K, V> {
305303self . indices . find ( hash. get ( ) , eq) . copied ( )
306304}
307305
306+ /// Return the index in `entries` where an equivalent key can be found
307+ pub ( crate ) fn get_index_of_raw < F > ( & self , hash : HashValue , mut is_match : F ) ->Option < usize >
308+ where
309+ F : FnMut ( & K ) ->bool ,
310+ {
311+ let eq =move |& i: & usize |is_match ( & self . entries [ i] . key ) ;
312+ self . indices . find ( hash. get ( ) , eq) . copied ( )
313+ }
314+
308315/// Append a key-value pair to `entries`,
309316/// *without* checking whether it already exists.
310317fn push_entry ( & mut self , hash : HashValue , key : K , value : V ) {
@@ -509,7 +516,13 @@ impl<K, V> IndexMapCore<K, V> {
509516
510517/// Insert a key-value pair in `entries` at a particular index,
511518/// *without* checking whether it already exists.
512- fn shift_insert_unique ( & mut self , index : usize , hash : HashValue , key : K , value : V ) {
519+ pub ( crate ) fn shift_insert_unique (
520+ & mut self ,
521+ index : usize ,
522+ hash : HashValue ,
523+ key : K ,
524+ value : V ,
525+ ) ->& mut Bucket < K , V > {
513526let end =self . indices . len ( ) ;
514527assert ! ( index <= end) ;
515528// Increment others first so we don't have duplicate indices.
@@ -527,6 +540,7 @@ impl<K, V> IndexMapCore<K, V> {
527540self . reserve_entries ( 1 ) ;
528541}
529542self . entries . insert ( index, Bucket { hash, key, value} ) ;
543+ & mut self . entries [ index]
530544}
531545
532546/// Remove an entry by shifting all entries that follow it
@@ -680,8 +694,5 @@ impl<K, V> IndexMapCore<K, V> {
680694#[ test]
681695fn assert_send_sync ( ) {
682696fn assert_send_sync < T : Send +Sync > ( ) { }
683- assert_send_sync :: < IndexMapCore < i32 , i32 > > ( ) ;
684- assert_send_sync :: < Entry < ' _ , i32 , i32 > > ( ) ;
685- assert_send_sync :: < IndexedEntry < ' _ , i32 , i32 > > ( ) ;
686- assert_send_sync :: < raw_entry_v1:: RawEntryMut < ' _ , i32 , i32 , ( ) > > ( ) ;
697+ assert_send_sync :: < Core < i32 , i32 > > ( ) ;
687698}