Hacker News new | ask | show | jobs
by pygy_ 4011 days ago
I don't know Rust, and the only thing opaque to me in that line is the `'a` syntax. I suppose it is related to memory safety.

In plain English:

`search_entry_hashed` is a parametric function. It works in a type safe way on any kind of K and V. It takes as arguments a reference to a mutable hash table, a hash function and a key, and returns an `Entry` object whose precise type depends on the type of the parameters.

You could hardly express that more succinctly. You can't understand it by skimming it, but it is a complex definition.

2 comments

Your guess about 'a is correct. 'a is here used to signify that the return value can only be safely used while the value table exists and is not being concurrently modified. This implies that the value is not copied on return, but only a reference into the table is returned.
I'm surprised that RawTable isn't parametrized on the type of hash function. Something like this (possibly wrong way to express it, but you get the idea)

    fn search_entry_hashed<'a, K: Eq, V, H: SafeHash>(table: &'a mut RawTable<K,V,H>, hash: H, k: K)
        -> Entry<'a, K, V>
RawTable doesn't have to be because the hash function has already been computed at that point. The actual hash table is.
It could be inferred in some languages (notably MLs).
Including parametrization?
Yes.