Skip to content

Commit f2de794

Browse files
committed
Auto merge of #123 - goffrie:raw-entry-no-build-hasher, r=Amanieu
Remove BuildHasher requirement from raw entry APIs. This makes it possible to use HashMap with `S=()`, which forces the user to always supply hashes manually. This is an alternative to making the key type unhashable. I'm not sure if this change is desirable but I'm putting it up for discussion anyway :)
2 parents b67c4ad + 3777125 commit f2de794

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

src/map.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -958,10 +958,7 @@ where
958958
}
959959
}
960960

961-
impl<K, V, S> HashMap<K, V, S>
962-
where
963-
S: BuildHasher,
964-
{
961+
impl<K, V, S> HashMap<K, V, S> {
965962
/// Creates a raw entry builder for the HashMap.
966963
///
967964
/// Raw entries provide the lowest level of control for searching and
@@ -1047,7 +1044,6 @@ impl<K, V, S> Debug for HashMap<K, V, S>
10471044
where
10481045
K: Debug,
10491046
V: Debug,
1050-
S: BuildHasher,
10511047
{
10521048
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10531049
f.debug_map().entries(self.iter()).finish()
@@ -1056,7 +1052,7 @@ where
10561052

10571053
impl<K, V, S> Default for HashMap<K, V, S>
10581054
where
1059-
S: BuildHasher + Default,
1055+
S: Default,
10601056
{
10611057
/// Creates an empty `HashMap<K, V, S>`, with the `Default` value for the hasher.
10621058
#[cfg_attr(feature = "inline-more", inline)]
@@ -1318,15 +1314,13 @@ pub struct RawEntryBuilder<'a, K, V, S> {
13181314
map: &'a HashMap<K, V, S>,
13191315
}
13201316

1321-
impl<'a, K, V, S> RawEntryBuilderMut<'a, K, V, S>
1322-
where
1323-
S: BuildHasher,
1324-
{
1317+
impl<'a, K, V, S> RawEntryBuilderMut<'a, K, V, S> {
13251318
/// Creates a `RawEntryMut` from the given key.
13261319
#[cfg_attr(feature = "inline-more", inline)]
13271320
#[allow(clippy::wrong_self_convention)]
13281321
pub fn from_key<Q: ?Sized>(self, k: &Q) -> RawEntryMut<'a, K, V, S>
13291322
where
1323+
S: BuildHasher,
13301324
K: Borrow<Q>,
13311325
Q: Hash + Eq,
13321326
{
@@ -1347,10 +1341,7 @@ where
13471341
}
13481342
}
13491343

1350-
impl<'a, K, V, S> RawEntryBuilderMut<'a, K, V, S>
1351-
where
1352-
S: BuildHasher,
1353-
{
1344+
impl<'a, K, V, S> RawEntryBuilderMut<'a, K, V, S> {
13541345
/// Creates a `RawEntryMut` from the given hash.
13551346
#[cfg_attr(feature = "inline-more", inline)]
13561347
#[allow(clippy::wrong_self_convention)]
@@ -1379,15 +1370,13 @@ where
13791370
}
13801371
}
13811372

1382-
impl<'a, K, V, S> RawEntryBuilder<'a, K, V, S>
1383-
where
1384-
S: BuildHasher,
1385-
{
1373+
impl<'a, K, V, S> RawEntryBuilder<'a, K, V, S> {
13861374
/// Access an entry by key.
13871375
#[cfg_attr(feature = "inline-more", inline)]
13881376
#[allow(clippy::wrong_self_convention)]
13891377
pub fn from_key<Q: ?Sized>(self, k: &Q) -> Option<(&'a K, &'a V)>
13901378
where
1379+
S: BuildHasher,
13911380
K: Borrow<Q>,
13921381
Q: Hash + Eq,
13931382
{
@@ -1692,7 +1681,6 @@ impl<'a, K, V, S> RawVacantEntryMut<'a, K, V, S> {
16921681
hasher: H,
16931682
) -> (&'a mut K, &'a mut V)
16941683
where
1695-
S: BuildHasher,
16961684
H: Fn(&K) -> u64,
16971685
{
16981686
unsafe {
@@ -3636,7 +3624,7 @@ mod test_map {
36363624
#[derive(Debug)]
36373625
struct IntWrapper(u64);
36383626

3639-
let mut m: HashMap<IntWrapper, ()> = HashMap::new();
3627+
let mut m: HashMap<IntWrapper, (), ()> = HashMap::default();
36403628
{
36413629
assert!(m.raw_entry().from_hash(0, |k| k.0 == 0).is_none());
36423630
}

0 commit comments

Comments
 (0)