I was writing some code that used immutable and mutable maps, and looking at Belt I thought I’d ask for clarification. From my understanding looking at the docs:
Map: Immutable map
HashMap: Mutable map, could be called MutableMap
MutableMap: Mutable sorted map, could be called MutableSortedMap
Looking at the collections, I see the same situation with Set, where Hash* means unordered mutable data structure, and Mutable* means sorted mutable data structure.
Is my intuition right or am I making a mess in my head?
MutableMap is just the mutable version of Map, backed by an AVL tree (with very clean output; log it yourself to learn about data structures!), whereas hash map uses… a hash. There are finer-grained situation on when to use what depending on requirements. If you’re unclear of them right now, start with Js.Dict or Map I’d say.
Thanks for clarifying. I guess part of the confusion is that on the sidebar of the docs, there is a section “MUTABLE COLLECTIONS”, but all of the Hash{Map,Set}* collections are also mutable but are mixed with the other immutable versions.
For learnability, I’d recommend changing the structure of the sidebar a bit:
either doing a top level separation between immutable and mutable data structures, and under it group them by Set/Map/Others
or remove the explicit “Mutable collections” section and merge the map ones to the Map section and the set ones to the Set section, and make a new section “Others” for the stack, queue, etc.
Is this something that would be interesting to do? Is this a good venue for these kind of discussion or is it better to do this somewhere else?