Skip to content

Commit c964fbc

Browse files
capickettfacebook-github-bot
authored andcommitted
Migrate off of RawTable APIs
Summary: The `RawTable` APIs are removed in latest `hashbrown` upgrade (coming in D68793000). rust-lang/hashbrown#546 The PR notes that users should migrate to the `HashTable` APIs instead. - `HashTable`: https://docs.rs/hashbrown/latest/hashbrown/struct.HashTable.html - `RawTable`: https://docs.rs/hashbrown/0.14.5/hashbrown/raw/struct.RawTable.html Reviewed By: dtolnay Differential Revision: D69195912 fbshipit-source-id: b5c4d0cc33a977d9ceb247ffedcf49d7be0b01ec
1 parent 8b542d7 commit c964fbc

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

hphp/hack/src/utils/intern/src/sharded_set.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use std::collections::hash_map::RandomState;
1010
use std::fmt;
1111
use std::hash::BuildHasher;
1212
use std::hash::Hash;
13-
use std::hash::Hasher;
1413

15-
use hashbrown::raw::RawTable;
14+
use hashbrown::HashTable;
1615
use parking_lot::RwLock;
1716
use parking_lot::RwLockWriteGuard;
1817

@@ -21,7 +20,7 @@ const SHARDS: usize = 1 << SHARD_SHIFT;
2120

2221
pub struct ShardedSet<T, S = RandomState> {
2322
build_hasher: S,
24-
shards: [RwLock<RawTable<T>>; SHARDS],
23+
shards: [RwLock<HashTable<T>>; SHARDS],
2524
}
2625

2726
impl<T, S> fmt::Debug for ShardedSet<T, S> {
@@ -111,15 +110,13 @@ impl<T, S: BuildHasher> ShardedSet<T, S> {
111110
}
112111

113112
fn hash_one<B: BuildHasher, T: Hash>(build_hasher: &B, x: T) -> u64 {
114-
let mut hasher = build_hasher.build_hasher();
115-
x.hash(&mut hasher);
116-
hasher.finish()
113+
build_hasher.hash_one(&x)
117114
}
118115

119116
pub struct InsertLock<'a, T, S = RandomState> {
120117
build_hasher: &'a S,
121118
hash: u64,
122-
shard: RwLockWriteGuard<'a, RawTable<T>>,
119+
shard: RwLockWriteGuard<'a, HashTable<T>>,
123120
}
124121

125122
impl<'a, T, S> fmt::Debug for InsertLock<'a, T, S> {
@@ -133,7 +130,7 @@ impl<T: Eq + Hash, S: BuildHasher> ShardedSet<T, S> {
133130
/// hashbrown uses the upper 7 bits for disambiguation and the lower bits
134131
/// for bucket indexing, we take the bits just above the top 7.
135132
#[inline(always)]
136-
fn hash_and_shard<Q>(&self, q: &Q) -> (u64, &RwLock<RawTable<T>>)
133+
fn hash_and_shard<Q>(&self, q: &Q) -> (u64, &RwLock<HashTable<T>>)
137134
where
138135
T: Borrow<Q>,
139136
Q: ?Sized + Hash,
@@ -159,7 +156,7 @@ impl<T: Eq + Hash, S: BuildHasher> ShardedSet<T, S> {
159156
write_lock
160157
} else {
161158
// Write contention. Try reading first to see if the entry already exists.
162-
if let Some(t) = shard.read().get(hash, |other| q == other.borrow()) {
159+
if let Some(t) = shard.read().find(hash, |other| q == other.borrow()) {
163160
// Already exists.
164161
return Ok(t.clone());
165162
}
@@ -170,7 +167,7 @@ impl<T: Eq + Hash, S: BuildHasher> ShardedSet<T, S> {
170167
// checked in the write contention case above. We don't use an
171168
// upgradable read lock because those are exclusive from one another
172169
// just like write locks.
173-
if let Some(t) = shard.get(hash, |other| q == other.borrow()) {
170+
if let Some(t) = shard.find(hash, |other| q == other.borrow()) {
174171
return Ok(t.clone());
175172
}
176173
Err(InsertLock {
@@ -189,15 +186,17 @@ impl<T: Eq + Hash, S: BuildHasher> ShardedSet<T, S> {
189186
let (hash, shard) = self.hash_and_shard(q);
190187
shard
191188
.read()
192-
.get(hash, |other| q == other.borrow())
193-
.map(Clone::clone)
189+
.find(hash, |other| q == other.borrow())
190+
.cloned()
194191
}
195192

196193
/// Unconditionally insert `t` without checking if it's in the set.
197194
pub fn unchecked_insert(&self, t: T) {
198195
let build_hasher = &self.build_hasher;
199196
let (hash, shard) = self.hash_and_shard(&t);
200-
shard.write().insert(hash, t, |v| hash_one(build_hasher, v));
197+
shard
198+
.write()
199+
.insert_unique(hash, t, |v| hash_one(build_hasher, v));
201200
}
202201
}
203202

@@ -207,6 +206,6 @@ impl<T: Sized + Hash, S: BuildHasher> InsertLock<'_, T, S> {
207206
pub fn insert<Q: Into<T>>(&mut self, q: Q) {
208207
let build_hasher = self.build_hasher;
209208
self.shard
210-
.insert(self.hash, q.into(), |v| hash_one(build_hasher, v));
209+
.insert_unique(self.hash, q.into(), |v| hash_one(build_hasher, v));
211210
}
212211
}

0 commit comments

Comments
 (0)