1

I need to create a highscore system for all players in a game and keep a track of sorted scores for each player. Players have their own UUIDs assigned, and their score must be stored in long values (it varies from small numbers to billions).

Currently, my implementation would sort the map every time a new score is entered (old scores are overridden by same user) and saves into a LinkedHashMap. Is there a more efficient way to handle this?

2 Answers2

0

You could use a TreeSet, it maintains a sorting by itself and has a low overhead when sorting after each insert.

Alternatively you could utilize a database management system like MySQL or PostgreSQL, and retrieve the top 10 entries after every insert.

Valerij Dobler
  • 1,848
  • 15
  • 25
0

You can use a PriorityQueue Or a TreeSet with custom comparator for the same.

user699848
  • 109
  • 7