Anytime you write HashMap<K,V> you actually get HashMap<K,V,RandomState>, which then assures collision resistance in the type system. Weâd need some new AttackableState: BuildHasher, which works exactly like RandomState but uses a faster hasher, like:
pub struct AttackableState(RandomState);
impl BuildHasher for AttackableState {
type Hasher = AttackableHasher;
fn build_hasher(&self) -> AttackableHasher {
AttackableHasher(FxHasher::new_with_keys(self.0.k0, self.0.k1))
}
}
type AttackableHashMap<K,V> = HashMap<K,V,AttackableState>;
type AttackableHashSet<K> = HashSet<K,AttackableState>;
or whatever color gets selected.
If I understand, youâre proposing to distinguish between these types with inherent methods, like:
impl HashMap<K,V,RandomState> {
pub new_secure() -> HashMap<K,V,AttackableState> { HashMap::new() }
}
impl HashMap<K,V,AttackableState> {
pub new_attackable() -> HashMap<K,V,AttackableState> { HashMap::new() }
}