[erlang-questions] maps:first

Oliver Bollmann oliver.bollmann@REDACTED
Tue Aug 13 20:18:22 CEST 2019


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


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!


On 13.08.19 15:41, Lukas Larsson wrote:
> On Tue, Aug 13, 2019 at 3:34 PM Oliver Bollmann 
> <oliver.bollmann@REDACTED <mailto: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 <mailto:erlang-questions@REDACTED>
>     http://erlang.org/mailman/listinfo/erlang-questions
Oliver Bollmann

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190813/f35c0a89/attachment.htm>

More information about the erlang-questions mailing list