我需要将 map
转换为 hash/md5
。
map1 = %{k1: "val1", k2: "val2"}
map2 = %{k2: "val2", k1: "val1"}
上面两个 map 相同,因为 map 中的顺序无关紧要。 如何从 map 创建散列,以便它们的散列也相同?
出于缓存目的,我需要这样做。
最佳答案
与 phash2/1
或 phash2/2
函数,我们可以散列任何 elixir/erlang 术语:
:erlang.phash2(map1) == :erlang.phash2(map2) # true
关于hash - 如何从 elixir 中的 map 创建 `hash` 或 `md5`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65568086/