<p>(forgot to Cc the list.)</p>
<div class="gmail_quote">---------- Videresendt besked ----------<br>Fra: "Erik Søe Sørensen" <<a href="mailto:eriksoe@gmail.com">eriksoe@gmail.com</a>><br>Dato: 02/07/2012 23.50<br>Emne: Re: [erlang-questions] How would you do it?<br>
Til: "Max Bourinov" <<a href="mailto:bourinov@gmail.com">bourinov@gmail.com</a>><br><br type="attribution"><p>I think I'd do this...:<br>
0) Not include the profile info if the score messages unless it really does change that often.<br>
1) Keep two ets tables: one with player-id as key and current score as a column (and possibly other columns, for profile info etc., but for this I'd only fetch the score column).<br>
2) And the other ets table would have {Score,PlayerID} as key. No other columns needed for the tasks you mention.<br>
3) The first table would be a normal set, the second a sorted set. This means that player rows can be found and updated in constant time, and the score table row updated in logarithmic time (using the old score from the first table). Top 100, and neighbouring scores, can be found using ets iterators, in log time.</p>
<p>The performance of this should be quite adequate. There is at least one advantage of using ets tables over in-heap data structures for this, namely that it keeps the heap size down, so there's less work for the GC.</p>
<p>Happy hacking, whichever approach you settle on.</p>
<p>/Erik<br>
(Reminds me, I ought to add mention of two-table approaches to AGttES soonish. It can be quite handy to have your data indexed in several ways.)</p>
<p>/Erik</p>
<div class="gmail_quote">Den 02/07/2012 12.30 skrev "Max Bourinov" <<a href="mailto:bourinov@gmail.com" target="_blank">bourinov@gmail.com</a>>:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="elided-text">
Hi Erlangers,<div><br></div><div>I need to build a ranking system for online game.</div><div><br></div><div>I think I will have a ranking gen_server that will accept cast messages like this: {score, Player :: profile(), Score :: integer()}.</div>
<div><br></div><div>So, the question is what would be most appropriate data structure if:</div><div><ol><li>I have to rank about 50 000 - 100 000 different players.</li><li>On each score message I have to re-sort whole ranking table.</li>
<li>It must be very cheap to get:</li><ol><li>top 100 players</li><li>player's rating +/- 10 players about current player</li></ol><li>I expect about 20-50 score messages per seconds</li><li>Size of score message is about 4KB (profile takes most of the space).</li>
</ol><div><br></div></div><div>Any ideas or suggestions are welcome!</div><div><br></div><div><div>Best regards,</div><div>Max</div><br><br>
</div>
<br></div><div class="quoted-text">_______________________________________________<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" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></div></blockquote></div>
</div>