I think you can do this very efficiently using a combination of order statistics tree and hash table.
The order statistics tree is an extended binary search tree that, in addition to storing items in a sorted order, allows you to search for items by their index in the tree. That is, the structure supports O (lg n) insertion, deletion and search of values ββby their key, as well as O (lg n) search for an element taking into account its index. If you store ratings in this structure, you can easily insert or update new ratings, as well as track the rank of each item in the tree.
To associate users with their ratings, you can combine this structure with an auxiliary mapping of the hash table from user identifiers into nodes in the order statistics tree containing the rating for this user. This will give you O (1) access to the playerβs account in addition to finding a zero rating of O (lg n).
Hope this helps!
source share