I'm using ets via elixir as a simple in-memory persistence layer to store and retrieve keys and also for the occasional foldl which involves reducing many duplicate keys that have different values. I am using the bag option.
Is there a simple, perhaps O(1) way to retrieve a list of just the current keys without having to do a more involved table traversal or match or foldl?
Erlang or Elixir syntax responses welcome.
:ets.new(:cache, [:bag, :named_table, :protected])
I have a static map of atom keys indexed by integer I am using to assist with insertions. But not all the keys are used..
chunk_key_map = %{2 => :chunk_key_2, ..... 28 => :chunk_key_28}
If there's no quick way, I am aware I can do an ets:lookup trying each of my static atom key values and testing for != [] and generating my own list, but wanted to see if ets supports such a feature.
Thanks
match
,match_object
andselect
is that it allows you to be more specific in what elements are copied, testing can be done while the element data is still "in the table". – Provincial