O'Reilly logo

Programming Elixir by Dave Thomas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to Choose Between Maps, HashDicts, and Keywords

Ask yourself these questions (in this order):

  • Will I want more than one entry with the same key?

    If so, you’ll have to use the Keyword module.

  • Do I need to guarantee the elements are ordered?

    If so, again, use the Keyword module.

  • Do I want to pattern-match against the contents (for example, matching a dictionary that has a key of :name somewhere in it)?

    If so, use a map.

  • Will I be storing more than a few hundred entries in it?

    If so, use a HashDict. With R17 of the BEAM virtual machine (which runs Erlang), maps are slow, particularly when adding new items.[13] This should improve in R18.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required