<div dir="ltr"><div dir="ltr">Am Di., 13. Aug. 2019 um 20:18 Uhr schrieb Oliver Bollmann <<a href="mailto:oliver.bollmann@t-online.de">oliver.bollmann@t-online.de</a>>:<br></div><div class="gmail_quote"><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>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><br></div><div>Are you sure a maps first is really what you want? Maps leys are not ordered (beyond MAP_SMALL_MAP_LIMIT, which is 32), but they are also not random.</div><div><br></div><div>As long as your map has less elements than MAP_SMALL_MAP_LIMIT it will behave like a ordered list, beyond that it will use a hash for ordering.</div><div>That means that for a given set of keys the ordering will be stable (but not sorted). So when you take the first element of a map and put it back again (based on key), it will be the new first element again.</div><div><br></div><div>IMHO the only use case for you maps:first function is something that tries to distribute new requests/elements across the elements of a map. Your maps:first function coupled with the constant ordering of map keys would lead to a distribution that is highly skewed towards a small number of keys (or even just one key).</div><div><br></div><div>Now, a maps:nth/2 function that works like list:nth/2 is another story. You could use</div><div><br></div><div> maps:nth(rand:uniform(maps:size(Map)), Map)</div><div><br></div><div>to get a somewhat evenly distributed key/element from a map.</div><div>Implementing this function currently requires you to convert the map to a list first. For large maps having a maps:nth/2 should yield better performance.</div><div><br></div><div>Regards</div><div>Andreas</div><div><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>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="gmail-m_-547880167734857521moz-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="gmail-m_-547880167734857521gmail-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="gmail-m_-547880167734857521moz-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="gmail-m_-547880167734857521gmail-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="gmail-m_-547880167734857521gmail-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="gmail-m_-547880167734857521moz-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"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><p><span style="font-family:verdana,geneva,sans-serif;font-size:10pt">Andreas Schultz</span></p>
<p><span style="font-family:verdana,geneva,sans-serif;font-size:10pt">-- </span></p>
<p><span style="font-family:verdana,geneva,sans-serif;font-size:8pt">Principal Engineer</span></p>
<p><span style="font-family:verdana,geneva,sans-serif;font-size:10.6667px"> t: +49 391 819099-224 </span></p>
<p><span style="font-family:verdana,geneva,sans-serif;font-size:8pt"><span style="font-family:verdana,geneva,sans-serif;font-size:10.6667px"></span></span></p>
<p><span style="font-family:verdana,geneva,sans-serif;font-size:8pt">------------------------------- enabling your networks -----------------------------</span></p>
<table style="height:142px;width:550px">
<tbody>
<tr style="height:30px">
<td style="width:146px;height:30px">
<p><span style="font-family:verdana,geneva,sans-serif;color:rgb(34,34,34);font-size:8pt">Travelping GmbH </span></p>
<p><span style="font-family:verdana,geneva,sans-serif;color:rgb(34,34,34);font-size:8pt">Roentgenstraße 13</span></p>
<p><span style="font-family:verdana,geneva,sans-serif;color:rgb(34,34,34);font-size:8pt">39108 Magdeburg</span></p>
<p><span style="font-family:verdana,geneva,sans-serif;color:rgb(34,34,34);font-size:8pt">Germany</span></p>
</td>
<td style="width:162px;height:30px">
<p style="color:rgb(34,34,34);font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:small;text-align:justify"><span style="font-family:verdana,geneva,sans-serif;font-size:8pt">t: +49 391 819099-0</span></p>
<p style="color:rgb(34,34,34);font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:small;text-align:justify"><span style="font-family:verdana,geneva,sans-serif;font-size:8pt">f: +49 391 819099-299</span></p>
<p style="color:rgb(34,34,34);font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:small;text-align:justify"><span style="font-family:verdana,geneva,sans-serif;font-size:8pt">e: <a href="mailto:info@travelping.com" target="_blank">info@travelping.com</a></span></p>
<p style="color:rgb(34,34,34);font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:small;text-align:justify"><span style="font-family:verdana,geneva,sans-serif;font-size:8pt">w: <a href="https://www.travelping.com/" target="_blank">https://www.travelping.com/</a></span></p>
</td>
</tr>
<tr style="height:16px">
<td style="width:146px;height:16px"> </td>
<td style="width:162px;height:16px"> </td>
</tr>
<tr style="height:17px">
<td style="width:146px;height:17px"><span style="font-size:8pt;font-family:verdana,geneva,sans-serif">Company registration: Amtsgericht Stendal </span></td>
<td style="width:162px;height:17px"><span style="font-size:8pt;font-family:verdana,geneva,sans-serif">Reg. No.: HRB 10578</span></td>
</tr>
<tr style="height:17px">
<td style="width:146px;height:17px"><span style="font-family:verdana,geneva,sans-serif;font-size:8pt">Geschaeftsfuehrer: Holger Winkelmann</span></td>
<td style="width:162px;height:17px"><span style="font-size:8pt;font-family:verdana,geneva,sans-serif">VAT ID: DE236673780</span></td>
</tr>
</tbody>
</table>
<p> </p></div></div>