3

Could anybody please explain me a few things about Elixir data types:

1) What are the sets and when should I use them?

2) What is the difference between HashSet and MapSet?

3) What is HashDict and when should I use it?

NoDisplayName
  • 15,246
  • 12
  • 62
  • 98

1 Answers1

1
  1. use sets when you need to strictly enforce that every element can appear only once. They are quite rare and I would not bother with them until you run into a specific problem where they are useful.

  2. the difference is the underlying implementation. With the latest Erlang VM R18, MapSet is faster: https://gist.github.com/lexmag/32977ce8fd7cb44ddefa

  3. HashDict is deprecated and should not be used in new projects, also see What is the benefit of Keyword Lists?

Community
  • 1
  • 1
Patrick Oscity
  • 53,604
  • 17
  • 144
  • 168
  • HashDict should be used instead of Map if you are using Erlang 17 for some reason and need more than a few dozen entries. Elixir 1.1 supports both Erlang 17 and 18, and libraries should not assume 18 only. If you know for sure that only Erlang 18 will be used, use Maps. – Fred the Magic Wonder Dog Sep 27 '15 at 16:51