Elixir 中的哈希和映射有什么区别

What is the difference between a hash and a map in Elixir

为什么 Phoenix 框架中的 "params" 是映射而不是散列? 任何人都可以解释内部实现级别的详细信息。

来自getting started guide

Note: Maps were recently introduced into the Erlang VM with EEP 43. Erlang 17 provides a partial implementation of the EEP, where only “small maps” are supported. This means maps have good performance characteristics only when storing at maximum a couple of dozens keys. To fill in this gap, Elixir also provides the HashDict module which uses a hashing algorithm to provide a dictionary that supports hundreds of thousands keys with good performance.

地图的主要优势之一是部分模式匹配:

def edit(conn, %{"id" => id} = params)
...

以上将匹配任何包含字符串 id 作为键的映射。

在 OTP 18 中,地图的性能有所提高,您可以在 https://gist.github.com/BinaryMuse/bb9f2cbf692e6cfa4841. And it is likely that HashDict will be deprecated in the future 看到。

这个答案中有一些关于 Elixir 数据类型的重要信息:

Elixir 作为核心语言的一部分引入 hashes/dicts,Erlang VM 不支持散列。下面的哈希是在映射和关键字列表(成对元组列表)之上实现的。

HashDict 在顶层结构上实现,结构在顶层映射上实现。

令人困惑,elixir hashes/dicts 的未来版本将被弃用,那里只有 2 个数据结构映射和映射集。