- var arr = _array
-
- # Fisrt step: look in the last indexed elt
- if k == _last_accessed_key then return _last_accessed_index
-
- # Compute the base position of the key
- var base = k.hash % _capacity
- if base < 0 then base = - base
-
- # Look for the key in the array
- var cur = base
- while true do
- var c = arr[cur]
- if c == null or c.key == k then # REAL equals
- _last_accessed_index = cur
- _last_accessed_key = k
- return cur
+ var i = k.hash % _capacity
+ if i < 0 then i = - i
+ return i
+ end
+
+ # Return the node assosiated with the key
+ fun node_at(k: K): nullable N
+ do
+ # cache: `is' is used instead of `==' because it is a faster filter (even if not exact)
+ if k is _last_accessed_key then return _last_accessed_node
+
+ var res = node_at_idx(index_at(k), k)
+ _last_accessed_key = k
+ _last_accessed_node = res
+ return res
+ end
+
+ # Return the node assosiated with the key (but with the index already known)
+ fun node_at_idx(i: Int, k: K): nullable N
+ do
+ var c = _array[i]
+ while c != null do
+ var ck = c._key
+ if ck is k or ck == k then # prefilter with `is' because the compiler is not smart enought yet
+ break