From 0ed847a47f9970a085e7948f00003a110045c05c Mon Sep 17 00:00:00 2001 From: TheMode Date: Mon, 13 Dec 2021 12:54:27 +0100 Subject: [PATCH] Use RoaringBitmap Signed-off-by: TheMode --- build.gradle | 4 ++-- .../java/net/minestom/server/utils/ViewEngine.java | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 47a8ca34f..7fcaedc50 100644 --- a/build.gradle +++ b/build.gradle @@ -128,8 +128,8 @@ dependencies { implementation 'com.github.ben-manes.caffeine:caffeine:3.0.4' - // https://mvnrepository.com/artifact/com.zaxxer/SparseBitSet - implementation group: 'com.zaxxer', name: 'SparseBitSet', version: '1.2' + // https://mvnrepository.com/artifact/org.roaringbitmap/RoaringBitmap + implementation group: 'org.roaringbitmap', name: 'RoaringBitmap', version: '0.9.23' // https://mvnrepository.com/artifact/org.jctools/jctools-core implementation group: 'org.jctools', name: 'jctools-core', version: '3.3.0' diff --git a/src/main/java/net/minestom/server/utils/ViewEngine.java b/src/main/java/net/minestom/server/utils/ViewEngine.java index 21004ef6b..cc707a8c6 100644 --- a/src/main/java/net/minestom/server/utils/ViewEngine.java +++ b/src/main/java/net/minestom/server/utils/ViewEngine.java @@ -1,6 +1,5 @@ package net.minestom.server.utils; -import com.zaxxer.sparsebits.SparseBitSet; import it.unimi.dsi.fastutil.objects.ObjectArraySet; import net.minestom.server.coordinate.Point; import net.minestom.server.entity.Entity; @@ -9,6 +8,7 @@ import net.minestom.server.instance.EntityTracker; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.roaringbitmap.RoaringBitmap; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; @@ -125,7 +125,7 @@ public final class ViewEngine { // The consumers to be called when an entity is added/removed. public final Consumer addition, removal; // Contains all the entity ids that are viewable by this option. - public final SparseBitSet bitSet = new SparseBitSet(); + public final RoaringBitmap bitSet = new RoaringBitmap(); // 1 if auto, 0 if manual private volatile int auto = 1; // References from the entity trackers. @@ -149,15 +149,15 @@ public final class ViewEngine { } public boolean isRegistered(T entity) { - return bitSet.get(entity.getEntityId()); + return bitSet.contains(entity.getEntityId()); } public void register(T entity) { - this.bitSet.set(entity.getEntityId()); + this.bitSet.add(entity.getEntityId()); } public void unregister(T entity) { - this.bitSet.clear(entity.getEntityId()); + this.bitSet.remove(entity.getEntityId()); } public void updateAuto(boolean autoViewable) { @@ -221,7 +221,7 @@ public final class ViewEngine { public int size() { synchronized (mutex) { int size = manualViewers.size(); - if (entity != null) return size + viewableOption.bitSet.cardinality(); + if (entity != null) return size + viewableOption.bitSet.getCardinality(); // Non-entity fallback final List> auto = ViewEngine.this.viewableOption.references; if (auto != null) {