mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-29 12:37:42 +01:00
Rename AutoIncrementMap
This commit is contained in:
parent
8d7175af73
commit
bfa2dbd3f7
@ -2,7 +2,7 @@ package net.minestom.server.tag;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.utils.collection.IndexMap;
|
||||
import net.minestom.server.utils.collection.AutoIncrementMap;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -30,7 +30,7 @@ import java.util.function.UnaryOperator;
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
public class Tag<T> {
|
||||
private static final IndexMap<String> INDEX_MAP = new IndexMap<>();
|
||||
private static final AutoIncrementMap<String> INDEX_MAP = new AutoIncrementMap<>();
|
||||
|
||||
record PathEntry(String name, int index) {
|
||||
}
|
||||
|
@ -6,13 +6,14 @@ import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public final class IndexMap<K> {
|
||||
public final class AutoIncrementMap<K> {
|
||||
private final Object2IntOpenHashMap<K> write = new Object2IntOpenHashMap<>();
|
||||
private Object2IntOpenHashMap<K> read = copy();
|
||||
private Object2IntOpenHashMap<K> read;
|
||||
private int lastIndex;
|
||||
|
||||
public IndexMap() {
|
||||
write.defaultReturnValue(-1);
|
||||
public AutoIncrementMap() {
|
||||
this.write.defaultReturnValue(-1);
|
||||
this.read = write.clone();
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@ -24,16 +25,10 @@ public final class IndexMap<K> {
|
||||
index = write.getInt(key);
|
||||
if (index == -1) {
|
||||
write.put(key, (index = lastIndex++));
|
||||
read = copy();
|
||||
read = write.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
private Object2IntOpenHashMap<K> copy() {
|
||||
var map = new Object2IntOpenHashMap<>(write);
|
||||
map.defaultReturnValue(-1);
|
||||
return map;
|
||||
}
|
||||
}
|
@ -4,10 +4,10 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class IndexMapTest {
|
||||
public class AutoIncrementMapTest {
|
||||
@Test
|
||||
public void test() {
|
||||
IndexMap<String> map = new IndexMap<>();
|
||||
AutoIncrementMap<String> map = new AutoIncrementMap<>();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
assertEquals(i, map.get("test" + i));
|
||||
for (int j = 0; j < i; j++) {
|
Loading…
Reference in New Issue
Block a user