1use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
2
3pub trait FxHashWithCapacity {
5 fn with_capacity(capacity: usize) -> Self;
7}
8
9#[allow(clippy::implicit_hasher)]
10impl<K, V> FxHashWithCapacity for FxHashMap<K, V> {
11 #[inline]
12 fn with_capacity(capacity: usize) -> Self {
13 Self::with_capacity_and_hasher(capacity, FxBuildHasher)
14 }
15}
16
17#[allow(clippy::implicit_hasher)]
18impl<V> FxHashWithCapacity for FxHashSet<V> {
19 fn with_capacity(capacity: usize) -> Self {
20 Self::with_capacity_and_hasher(capacity, FxBuildHasher)
21 }
22}
23
24#[cfg(test)]
25mod tests {
26 use rustc_hash::{FxHashMap, FxHashSet};
27
28 use super::FxHashWithCapacity;
29
30 #[test]
31 fn fxhashmap_fxhashwithcapacity() {
32 let input = 8;
33 let expected = 8;
34 let output = FxHashMap::<u8, u8>::with_capacity(input).capacity();
35 assert!(expected <= output, "\n input: {input:?}");
36 }
37
38 #[test]
39 fn fxhashset_fxhashwithcapacity() {
40 let input = 8;
41 let expected = 8;
42 let output = FxHashSet::<u8>::with_capacity(input).capacity();
43 assert!(expected <= output, "\n input: {input:?}");
44 }
45}