<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 13 Aug 2019 at 19:18, Oliver Bollmann <<a href="mailto:oliver.bollmann@t-online.de">oliver.bollmann@t-online.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<p>Hi,<br>
</p>
<p>i guess <b>we</b> do all the same,</p>
<p>1) processes with propery Y, i have about 1-10 million processes<br>
2) gen_server to manage these processes in maps,dict,lists for
example a pool with in,out,leave,delete<br>
3) monitoring these processes<br>
</p>
<p>Dilemma: <br>
</p>
<p>If process P died i have to delete it from data structure using
in 2)<br>
<br>
- maps, dict very fast; <br>
lists -> List -- [Item] slow!<br>
OK, i could use a sorted list and and the subtract would be
faster, but insert is then slower!<br>
And subtract need an algorithm!<br>
<br>
- i do not want a special process, only one random or the first
one from data structure using in 2)<br>
here is the place where i need <b>first_from_data_structure</b><br>
<b> </b>lists very fast: first defines it itself ->
[First|Rest] = List,<br>
but using maps or dict there is not first, at all!</p></div></blockquote><div>Have you considered gb_trees[1]? Sure, for common use cases or large (enough) data sets they're slower than maps, but they're pretty fast notwithstanding, especially if your key types are cheap to compare. <br>And since it's an ordered data type, you can then simply take the smallest pair when implementing those sort of melded-pool-and-monitor patterns.<br><br>[1]: <a href="http://erlang.org/doc/man/gb_trees.html">http://erlang.org/doc/man/gb_trees.html</a></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div text="#000000" bgcolor="#FFFFFF">
<p>The question is: How can i get a random or first item from maps
or dict?</p>
<p>Hope that helps!</p>
<p>Oliver <br>
</p>
<p><br>
</p>
<div class="m_6076240000830732759moz-cite-prefix">On 13.08.19 15:41, Lukas Larsson wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr"><br>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, Aug 13, 2019 at 3:34
PM Oliver Bollmann <<a href="mailto:oliver.bollmann@t-online.de" target="_blank">oliver.bollmann@t-online.de</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF">
<p>I often need <a class="m_6076240000830732759gmail-m_-4002335776611155796moz-txt-link-freetext">maps:first(Map)</a>, is there
plan for it?</p>
</div>
</blockquote>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>What do you use <a class="m_6076240000830732759moz-txt-link-freetext">maps:first</a> for?</div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF">
<p>My current implementation is: </p>
<pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:Menlo">first(<span style="color:rgb(102,14,122)">Map</span>) ->
<span style="color:rgb(0,0,128);font-weight:bold">case </span><a class="m_6076240000830732759gmail-m_-4002335776611155796moz-txt-link-freetext">maps:next(maps:iterator(</a><span style="color:rgb(102,14,122)">Map</span>)) <span style="color:rgb(0,0,128);font-weight:bold">of
</span><span style="color:rgb(0,0,128);font-weight:bold"> </span>{<span style="color:rgb(102,14,122)">Key</span>,<span style="color:rgb(102,14,122)">Val</span>,<span style="color:rgb(102,14,122)">_</span>} -> {<span style="color:rgb(102,14,122)">Key</span>,<span style="color:rgb(102,14,122)">Val</span>};
none -> none
<span style="color:rgb(0,0,128);font-weight:bold">end.
Create </span><span style="color:rgb(0,0,128);font-weight:bold"><span style="color:rgb(0,0,128);font-weight:bold">the iterator</span> always a new map?
</span></pre>
<pre class="m_6076240000830732759gmail-m_-4002335776611155796moz-signature" cols="72">--
Grüße
Oliver Bollmann</pre>
</div>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote>
</div>
</div>
</blockquote>
<pre class="m_6076240000830732759moz-signature" cols="72">--
Grüße
Oliver Bollmann</pre>
</div>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Guilherme<br></div></div></div></div></div></div></div>