This is a library for managing the storage of players with the ability to add or update, delete, get a rank, and roll back.
This library contains the thread-safe class PlayerStorage which implements Storage interface.
Class PlayerStorage implements the following methods.
Adds a player with a rating or updates a player rating, if one has been already added.
@Synchronized
fun registerPlayerResult(playerName: String, playerRating: Int): BooleanNote: This method is marked as @Synchronized.
Deletes the player from the storage.
@Synchronized
fun unregisterPlayer(playerName: String): BooleanNote: This method is marked as @Synchronized.
Returns player rank. Rank is a position in the rating table.
fun getPlayerRank(playerName: String): Int?Rolls the last [step] registerPlayerResult or unregisterPlayer invocations back.
@Synchronized
fun rollback(step: Int): BooleanNote: This method is marked as @Synchronized.
The library published to JitPack repository.
Step 1. Add the JitPack repository to your build file.
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>Step 2. Add the dependency.
<dependency>
<groupId>com.github.akifev</groupId>
<artifactId>player-storage</artifactId>
<version>2.0</version>
</dependency>Step 1. Add the JitPack repository to your build file.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}Step 2. Add the dependency.
dependencies {
implementation 'com.github.akifev:player-storage:2.0'
}Here is the relation of average operation execution time to the quantity of players added to the storage.
| Quantity of players | 14 | 62 | 1022 | 8190 | 65534 | |
|---|---|---|---|---|---|---|
| registerPlayerResult | 307 | 510 | 1079 | 1984 | 4156 | ns/op |
| unregisterPlayer | 313 | 585 | 1123 | 1974 | 4385 | ns/op |
| getPlayerRank | 135 | 239 | 544 | 1104 | 2328 | ns/op |
| rollback | 58 | 50 | 59 | 31 | 9 | ns/op |