AttackableHashMap is a short non-abbreviation that clearly captures the problem.
I think VulnerableHashMap and InsecueHashMap sound fine too. And the abbreviations NonCRHashMap works too.
WeakerHashMap works but communicates less. Fast is wrong word because collision resistance keeps the map fastish under DoS. Unsafe is wrong word because unsafe refers to memory unsafety.
IMHO, NonCRHashMap is very nice. It is short enough and still makes you wonder (go to the docs) what does that âNonâ prefix means in terms of missing functionality, and why would you choose something that lacks such property?
Itâd be great to bless the use of FxHashMap. Iâd suggest deprecating fn new(), replacing with fn new_secure() & fn new_fast(). Along with type aliases SecureHashMap & FastHashMap.
This way you state a preference and the constructor names clearly state the intended benefit. It answers the question âwhy would I not use âfastâ?â - because it isnât as secure, âwhy would I not use âsecureâ?â - because it isnât as fast.
Or just use HashMap::default() if you donât care.
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:
I like WeakHashMap, it is short enough, has clear negative connotation, can be explained as âweak hashâ + âmapâ, and re-uses Java name, so it will be immediately familiar to some. I donât think that similarity to WeakMap from JS is a big issue, and it certainly does not warrant long unwieldy names.
Iâm strongly of the opinion that any name involving âweakâ is a non-starter here, because âweakâ already refers to weak ownership in C++, Java, C#, Haskell, Kotlin, JavaScript, and Rust itself (and apparently D doesnât have this by any name). Javascript was merely following existing usage when they picked that name.
Yes, collision with rc::Weak will be unfortunate, but I think âweakâ is a too common word for reserving it just for this use-case. Other alternative could be VulnHashMap, it has the same length, and reading âvulnâ as âvulnarableâ shouldnât be an issue. We could use more explicit VulnarableHashMap, but itâs a bit too unwieldy for my taste.
As another example, in dotnet you almost always want SemaphoreSlim, not Semaphore, as the latter is actually an inter-process OS-level thing. I would absolutely expect that FastHashMap is what one should use by default, and the HashMap some legacy thing (perhaps because of API differences).
This is especially true as the edition release is likely to re-emphasize that we have a migration story for language features, but not for the library, so new things getting a name that implies you should use them over the other is absolutely something I'd expect for standard library evolution.
Maybe something like SimpleHashMap? Implying that âsimpleâ code is probably faster, but may lead folks to investigate the drawbacks (collision resistance).