use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
pub trait FxHashWithCapacity {
fn with_capacity(capacity: usize) -> Self;
}
#[allow(clippy::implicit_hasher)]
impl<K, V> FxHashWithCapacity for FxHashMap<K, V> {
#[inline]
fn with_capacity(capacity: usize) -> Self {
Self::with_capacity_and_hasher(capacity, FxBuildHasher)
}
}
#[allow(clippy::implicit_hasher)]
impl<V> FxHashWithCapacity for FxHashSet<V> {
fn with_capacity(capacity: usize) -> Self {
Self::with_capacity_and_hasher(capacity, FxBuildHasher)
}
}
#[cfg(test)]
mod tests {
use rustc_hash::{FxHashMap, FxHashSet};
use super::FxHashWithCapacity;
#[test]
fn fxhashmap_fxhashwithcapacity() {
let input = 8;
let expected = 8;
let output = FxHashMap::<u8, u8>::with_capacity(input).capacity();
assert!(expected <= output, "\n input: {input:?}");
}
#[test]
fn fxhashset_fxhashwithcapacity() {
let input = 8;
let expected = 8;
let output = FxHashSet::<u8>::with_capacity(input).capacity();
assert!(expected <= output, "\n input: {input:?}");
}
}