Skip to content

Commit 1073259

Browse files
authored
Merge pull request #441 from cuviper/equal
Use a simpler `equal` closure for `Q = K`
2 parents 5c7e7cb + 4da89f3 commit 1073259

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/inner.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ fn get_hash<K, V>(entries: &[Bucket<K, V>]) -> impl Fn(&usize) -> u64 + use<'_,
3838
move |&i| entries[i].hash.get()
3939
}
4040

41+
#[inline]
42+
fn equal<'a, K: Eq, V>(
43+
key: &'a K,
44+
entries: &'a [Bucket<K, V>],
45+
) -> impl Fn(&usize) -> bool + use<'a, K, V> {
46+
move |&i| K::eq(key, &entries[i].key)
47+
}
48+
4149
#[inline]
4250
fn equivalent<'a, K, V, Q: ?Sized + Equivalent<K>>(
4351
key: &'a Q,
@@ -327,7 +335,7 @@ impl<K, V> Core<K, V> {
327335
where
328336
K: Eq,
329337
{
330-
let eq = equivalent(&key, &self.entries);
338+
let eq = equal(&key, &self.entries);
331339
let hasher = get_hash(&self.entries);
332340
match self.indices.entry(hash.get(), eq, hasher) {
333341
hash_table::Entry::Occupied(entry) => {
@@ -354,7 +362,7 @@ impl<K, V> Core<K, V> {
354362
where
355363
K: Eq,
356364
{
357-
let eq = equivalent(&key, &self.entries);
365+
let eq = equal(&key, &self.entries);
358366
let hasher = get_hash(&self.entries);
359367
match self.indices.entry(hash.get(), eq, hasher) {
360368
hash_table::Entry::Occupied(entry) => {

src/inner/entry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{Bucket, Core, equivalent, get_hash};
1+
use super::{Bucket, Core, equal, get_hash};
22
use crate::HashValue;
33
use crate::map::{Entry, IndexedEntry};
44
use core::cmp::Ordering;
@@ -9,7 +9,7 @@ impl<'a, K, V> Entry<'a, K, V> {
99
where
1010
K: Eq,
1111
{
12-
let eq = equivalent(&key, &map.entries);
12+
let eq = equal(&key, &map.entries);
1313
match map.indices.find_entry(hash.get(), eq) {
1414
Ok(entry) => Entry::Occupied(OccupiedEntry {
1515
bucket: entry.bucket_index(),

0 commit comments

Comments
 (0)