What Data structure should I use?


#1

I have a poly variant like this:

type field = [ |`name |`password ]:

I need a kind of map that store value with key has type field and value of each field.

Currently, I’m using a list((field, option(string)))` for storing values. But it’s quite inefficient for both set and get values. I need to optimizes for get if that’s matter.

1 data structure I can think of is Js.Dict (which is a hashmap). But it doesn’t allow key to be non-string.


#2

Since it’s a UI thing (confirmed in Discord that it’s ~10 fields), use either array((field, option(string)) or list like you’re already doing. Otherwise, use Set. Below a few dozen fields, no need to use the more elaborate immutable data structures (no perf/ergonomics/memory wins).


#3

Thank you. I’ll take note about the size of fields next time