Naive HashMap
How else could we implement an associative array in Rust and how would it compare to standard library's HashMap? The standard library HashMap is clever, clearly, storing just enough information to reduce the total probes from ideal offsets by sharing information between modifications to the underlying table. In fact, the comments in the table module assert that the design we've just worked through is a lot faster than a table structured as Vec<Option<(u64, K, V)>>—where u64 is the key hash, but presumably still using Robin Hood hashing and linear probing. What if we went even simpler? We'll support only two operations—insert and lookup—to keep things straightforward for ourselves. We'll also keep more or less the same type constraints ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access