May 2019
Intermediate to advanced
698 pages
17h 21m
English
The Robin Hood hashing strategy already describes a large portion of the insert mechanism: hash the key value, look for an empty bucket, and reorder elements along the way according to their probing distance:
pub fn insert(&mut self, k: K, v: V) -> Option<V> { let hash = self.make_hash(&k); self.reserve(1); self.insert_hashed_nocheck(hash, k, v)}
This function only does the first step and expands the basic data structure—if needed. The insert_hashed_nocheck() function provides the next step by searching for the hash in the existing table, and returning the appropriate bucket for it. The element is responsible for inserting itself into the right spot. The steps necessary to do that depend on whether the bucket is full or empty, which ...
Read now
Unlock full access