Class SkipListLeaderboard
java.lang.Object
fo.nya.leaderboard.implementation.SkipListLeaderboard
- All Implemented Interfaces:
Leaderboard
Created by 0da on 12.06.2023 15:20; (ノ◕ヮ◕)ノ*:・゚✧
Implementation of leaderboard over
Implementation of leaderboard over
ConcurrentSkipListSet and ConcurrentHashMap for specific entry lookup.
Insertion or update at average requires same time as inserting in HashMap + remove from SkipListSet + insertion in SkipListSet.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaround(long target, int up, int down, boolean desc) Method takes slice around position of a specific target.find(long target) Method finds entry row of specified target.voidremove(long target) Method removes entry with specified target from leaderboard.intsize()Method returns current amounts of entries un that leaderboard.slice(int from, int limit, boolean desc) Method calculates and returns slice of current situation in leaderboard.voidupdate(long target, long score) Method to update (or insert new) score for specified target in that leaderboard.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface fo.nya.leaderboard.Leaderboard
slice, updateAll
-
Constructor Details
-
SkipListLeaderboard
public SkipListLeaderboard()
-
-
Method Details
-
size
public int size()Method returns current amounts of entries un that leaderboard.- Specified by:
sizein interfaceLeaderboard- Returns:
- current amounts of entries un that leaderboard.
-
slice
Method calculates and returns slice of current situation in leaderboard.- Specified by:
slicein interfaceLeaderboard- Parameters:
from- place that will be start of slice inclusive. Minimal meaningful value is1, because minimal value ofLeaderboardRow.place()is 1.limit- maximum amount of entries in result.desc- this flags determinants 'direction' of a slice. If this value istruethen result will contain values in descending order[from, f - 1, f - 2, ...], else[f, f + 1, from + 2, ...].- Returns:
- new list with result for specified arguments, maximum length is
limitand first value (if not empty) with placefrom.
-
around
Method takes slice around position of a specific target.- Specified by:
aroundin interfaceLeaderboard- Parameters:
target- id of the target around which slice will be made.up- amount of entries that will be taken before target.down- amount of entries that will be taken after target.desc- this flags determinants 'direction' of a slice. If this value istruethen result will contain values in descending order[..., t + 1, t + 2, target, t - 1, t - 2, ...], else[..., t - 1, t - 2, target, t + 1, t + 2, ...].- Returns:
- new list with result for specified arguments.
-
find
Method finds entry row of specified target.- Specified by:
findin interfaceLeaderboard- Parameters:
target- id of target that you need to acquire.- Returns:
- valid row of a target if that target is present into that leaderboard.
-
update
public void update(long target, long score) Method to update (or insert new) score for specified target in that leaderboard.- Specified by:
updatein interfaceLeaderboard- Parameters:
target- id of a target to update.score- new score to associate with that target.- See Also:
-
remove
public void remove(long target) Method removes entry with specified target from leaderboard. All entries after removed must adjust their positions.- Specified by:
removein interfaceLeaderboard- Parameters:
target- target which must be removed.
-