Essentially, you just need a couple of balanced search trees that let O (lg n) insert, delete, and getRecord operations. The trick is that instead of storing the actual data in the trees, you will store pointers to a set of record objects, where each record object will contain 5 fields:
- Username
- point value
- Rating
- pointer back to a node in the name tree that references the object
- Pointer back to the node in the point tree that references the object.
The name tree only changes when new entries are added and when entries are deleted. The point tree is modified for insertions and deletions, as well as for updates, where the corresponding record is found, the pointer to the point tree is deleted, the point counter is updated, and then a new pointer to the point tree is added.
As you mentioned, you can use a hash table instead of a name tree if you want. The key point here is that you simply maintain separate sorted indexes as a set of unordered records that themselves contain pointers to their index nodes.
The point tree will be some variation in the order statistics tree , which, instead of being a specific data structure, is a general term for a binary search tree whose operations are modified to maintain an invariant that makes the requested rank related operations more efficient than walking in a tree . The details of how invariants are supported depend on the balanced search tree used (red-black tree, avl tree, etc.).
source share