You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
ets:select_replace/2 can use match spec to do in place replacement with List, which is efficient. But it doesn’t support updating map in place.
For example, the change to a list works: ets:fun2ms(fun({K, L}) when is_list(L) → {K, [marker | L]} end).
Output: [{{‘$1’,‘$2’},[{is_list,‘$2’}],[{{‘$1’,[marker|‘$2’]}}]}]
But for something similar with map: ets:fun2ms(fun({K, Map}) when is_map(Map) → {K, Map#{marker => true}} end).
Output: Error: the language element map (in body) cannot be translated into match_spec {error,transform_error}
Is Erlang/OTP team considering adding support to map as well?
Describe the solution you'd like
ets:select_replace/2 can use match spec to efficiently in place add/remove key/values from a map.
Describe alternatives you've considered
Right now in order to update a map, it needs to read from ets, make the changes, then copy the new map back to ets, which is very inefficient for bigger map. Since Erlang/OTP already support select by key with match spec, it would be consistent to support modification as well.
Additional context
The text was updated successfully, but these errors were encountered:
Looks like it is pretty good. Thanks for this quick working solution!
I just wonder if maps:merge can be added as well. It can be mimic by using multiple maps_put, but not as convenient as have a merge that can update multiple keys at once with simpler syntax.
The problem with BIFs like maps:merge is they can take arbitrary long time to finish if the maps are large enough. In order to not starve other Erlang processes from executing such BIFs might yield execution to be resumed at a later time. The match spec execution engine does not have support for yielding.
Wanted to add more than a +1 for this feature, so added some thoughts here.
My use case is not with efficiency large maps, but with race conditions in a high-write-concurrency situation where multiple processes tend to want to update just specific values under different specific keys of a map. Being able to read and select_update overwrite just a single map key instead of the whole map would eliminate the major source of race conditions in what I'm working on.
Is your feature request related to a problem? Please describe.
ets:select_replace/2 can use match spec to do in place replacement with List, which is efficient. But it doesn’t support updating map in place.
For example, the change to a list works:
ets:fun2ms(fun({K, L}) when is_list(L) → {K, [marker | L]} end).
Output:
[{{‘$1’,‘$2’},[{is_list,‘$2’}],[{{‘$1’,[marker|‘$2’]}}]}]
But for something similar with map:
ets:fun2ms(fun({K, Map}) when is_map(Map) → {K, Map#{marker => true}} end).
Output:
Error: the language element map (in body) cannot be translated into match_spec {error,transform_error}
Is Erlang/OTP team considering adding support to map as well?
Describe the solution you'd like
ets:select_replace/2 can use match spec to efficiently in place add/remove key/values from a map.
Describe alternatives you've considered
Right now in order to update a map, it needs to read from ets, make the changes, then copy the new map back to ets, which is very inefficient for bigger map. Since Erlang/OTP already support select by key with match spec, it would be consistent to support modification as well.
Additional context
The text was updated successfully, but these errors were encountered: