Class SkipListLeaderboard

java.lang.Object
fo.nya.leaderboard.implementation.SkipListLeaderboard
All Implemented Interfaces:
Leaderboard

public class SkipListLeaderboard extends Object implements Leaderboard
Created by 0da on 12.06.2023 15:20; (ノ◕ヮ◕)ノ*:・゚✧
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 Details

    • SkipListLeaderboard

      public SkipListLeaderboard()
  • Method Details

    • size

      public int size()
      Method returns current amounts of entries un that leaderboard.
      Specified by:
      size in interface Leaderboard
      Returns:
      current amounts of entries un that leaderboard.
    • slice

      public List<LeaderboardRow> slice(int from, int limit, boolean desc)
      Method calculates and returns slice of current situation in leaderboard.
      Specified by:
      slice in interface Leaderboard
      Parameters:
      from - place that will be start of slice inclusive. Minimal meaningful value is 1, because minimal value of LeaderboardRow.place() is 1.
      limit - maximum amount of entries in result.
      desc - this flags determinants 'direction' of a slice. If this value is true then 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 limit and first value (if not empty) with place from.
    • around

      public List<LeaderboardRow> around(long target, int up, int down, boolean desc)
      Method takes slice around position of a specific target.
      Specified by:
      around in interface Leaderboard
      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 is true then 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

      public Optional<LeaderboardRow> find(long target)
      Method finds entry row of specified target.
      Specified by:
      find in interface Leaderboard
      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:
      update in interface Leaderboard
      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:
      remove in interface Leaderboard
      Parameters:
      target - target which must be removed.