[erlang-questions] maps:first
dmkolesnikov@REDACTED
dmkolesnikov@REDACTED
Tue Aug 13 21:24:37 CEST 2019
Hello,
May be my comment is not extremely relevant to this discussion but
I would wish that Erlang data structures supports zipper trait. It make easy to iterate them back and force.
Dmitry
> On 13 Aug 2019, at 21.18, Oliver Bollmann <oliver.bollmann@REDACTED> wrote:
>
> Hi,
>
> i guess we do all the same,
>
> 1) processes with propery Y, i have about 1-10 million processes
> 2) gen_server to manage these processes in maps,dict,lists for example a pool with in,out,leave,delete
> 3) monitoring these processes
>
> Dilemma:
>
> If process P died i have to delete it from data structure using in 2)
>
> - maps, dict very fast;
> lists -> List -- [Item] slow!
> OK, i could use a sorted list and and the subtract would be faster, but insert is then slower!
> And subtract need an algorithm!
>
> - i do not want a special process, only one random or the first one from data structure using in 2)
> here is the place where i need first_from_data_structure
> lists very fast: first defines it itself -> [First|Rest] = List,
> but using maps or dict there is not first, at all!
>
> The question is: How can i get a random or first item from maps or dict?
>
> Hope that helps!
>
> Oliver
>
>
>
>> On 13.08.19 15:41, Lukas Larsson wrote:
>>
>>
>>> On Tue, Aug 13, 2019 at 3:34 PM Oliver Bollmann <oliver.bollmann@REDACTED> wrote:
>>> I often need maps:first(Map), is there plan for it?
>>>
>>
>> No, there is currently no plan for it, as I cannot think of a use case when it would be useful, but that might just be poor imagination on my part.
>>
>> What do you use maps:first for?
>>
>>> My current implementation is:
>>>
>>> first(Map) ->
>>> case maps:next(maps:iterator(Map)) of
>>> {Key,Val,_} -> {Key,Val};
>>> none -> none
>>> end.
>>>
>>> Create the iterator always a new map?
>>> --
>>> Grüße
>>> Oliver Bollmann
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://erlang.org/mailman/listinfo/erlang-questions
> --
> Grüße
> Oliver Bollmann
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190813/3e1a2cbe/attachment.htm>
More information about the erlang-questions
mailing list