Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3b6d04b

Browse files
authored
Merge pull request#425 from cuviper/inner-core
Move `crate::map::core` to `crate::inner`
2 parentscfad758 +eb30eb1 commit3b6d04b

File tree

10 files changed

+403
-347
lines changed

10 files changed

+403
-347
lines changed

‎src/map/core.rs‎renamed to ‎src/inner.rs‎

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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.
@@ -10,8 +10,6 @@
1010
mod entry;
1111
mod extract;
1212

13-
pubmod raw_entry_v1;
14-
1513
use alloc::vec::{self,Vec};
1614
use core::mem;
1715
use core::ops::RangeBounds;
@@ -23,12 +21,12 @@ use crate::{Bucket, Equivalent, HashValue, TryReserveError};
2321
typeIndices = hash_table::HashTable<usize>;
2422
typeEntries<K,V> =Vec<Bucket<K,V>>;
2523

26-
pubuse entry::{Entry,IndexedEntry,OccupiedEntry,VacantEntry};
24+
pubuse entry::{OccupiedEntry,VacantEntry};
2725
pub(crate)use extract::ExtractCore;
2826

2927
/// Core of the map that does not depend on S
30-
#[derive(Debug)]
31-
pub(crate)structIndexMapCore<K,V>{
28+
#[cfg_attr(feature ="test_debug",derive(Debug))]
29+
pub(crate)structCore<K,V>{
3230
/// indices mapping from the entry hash to its index.
3331
indices: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>CloneforIndexMapCore<K,V>
77+
impl<K,V>CloneforCore<K,V>
8078
where
8179
K:Clone,
8280
V: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`.
103101
constMAX_ENTRIES_CAPACITY:usize =(isize::MAXasusize) /size_of::<Bucket<K,V>>();
104102

105103
#[inline]
106104
pub(crate)constfnnew() ->Self{
107-
IndexMapCore{
105+
Core{
108106
indices:Indices::new(),
109107
entries:Vec::new(),
110108
}
111109
}
112110

113111
#[inline]
114112
pub(crate)fnwith_capacity(n:usize) ->Self{
115-
IndexMapCore{
113+
Core{
116114
indices:Indices::with_capacity(n),
117115
entries:Vec::with_capacity(n),
118116
}
@@ -305,6 +303,15 @@ impl<K, V> IndexMapCore<K, V> {
305303
self.indices.find(hash.get(), eq).copied()
306304
}
307305

306+
/// Return the index in `entries` where an equivalent key can be found
307+
pub(crate)fnget_index_of_raw<F>(&self,hash:HashValue,mutis_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.
310317
fnpush_entry(&mutself,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-
fnshift_insert_unique(&mutself,index:usize,hash:HashValue,key:K,value:V){
519+
pub(crate)fnshift_insert_unique(
520+
&mutself,
521+
index:usize,
522+
hash:HashValue,
523+
key:K,
524+
value:V,
525+
) ->&mutBucket<K,V>{
513526
let end =self.indices.len();
514527
assert!(index <= end);
515528
// Increment others first so we don't have duplicate indices.
@@ -527,6 +540,7 @@ impl<K, V> IndexMapCore<K, V> {
527540
self.reserve_entries(1);
528541
}
529542
self.entries.insert(index,Bucket{ hash, key, value});
543+
&mutself.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]
681695
fnassert_send_sync(){
682696
fnassert_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
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp