Hash-table-based dict/map structures provide O(1)
lookup time. Yet I keep seeing implications that in Elixir, finding a matching function head is faster than looking up something in a map.
For instance, Elixir's String.Unicode
compiles a list of unicode characters into many function heads, so that asking "what's the upcase version of é" is answered by finding the function head for upcase
that expects "é".
I don't know why this would be faster or more memory efficient than having a single upcase
function head that looks up "é" in a map.
Similarly, when showing how to build an I18n library in "Metaprogramming Elixir", Chris McCord gives each translation key its own function head, and says:
“By generating function heads for each translation mapping, we again let the Virtual Machine take over for fast lookup.”
Do maps in Elixir not provide O(1) lookup? Is finding a matching function head O(1)? Why opt for compiling a static list to many function heads instead of just storing it in a map?