diff --git a/src/main/java/me/jellysquid/mods/hydrogen/common/dedup/DeduplicationCache.java b/src/main/java/me/jellysquid/mods/hydrogen/common/dedup/DeduplicationCache.java index f764ac7..c4ebb3c 100644 --- a/src/main/java/me/jellysquid/mods/hydrogen/common/dedup/DeduplicationCache.java +++ b/src/main/java/me/jellysquid/mods/hydrogen/common/dedup/DeduplicationCache.java @@ -6,16 +6,17 @@ import java.util.Objects; public class DeduplicationCache { - private final ObjectOpenCustomHashSet cache; + private final ObjectOpenCustomHashSet pool; private int attemptedInsertions = 0; + private int deduplicated = 0; public DeduplicationCache(Hash.Strategy strategy) { - this.cache = new ObjectOpenCustomHashSet<>(strategy); + this.pool = new ObjectOpenCustomHashSet<>(strategy); } public DeduplicationCache() { - this.cache = new ObjectOpenCustomHashSet<>(new Hash.Strategy() { + this.pool = new ObjectOpenCustomHashSet<>(new Hash.Strategy() { @Override public int hashCode(T o) { return Objects.hashCode(o); @@ -31,26 +32,25 @@ public boolean equals(T a, T b) { public synchronized T deduplicate(T item) { this.attemptedInsertions++; - return this.cache.addOrGet(item); - } + T result = this.pool.addOrGet(item); - public synchronized void clearCache() { - this.attemptedInsertions = 0; + if (result != item) { + this.deduplicated++; + } - this.cache.clear(); + return result; } - public synchronized int getSize() { - return this.cache.size(); - } + public synchronized void clearCache() { + this.attemptedInsertions = 0; + this.deduplicated = 0; - public synchronized int getDeduplicatedCount() { - return this.attemptedInsertions - this.cache.size(); + this.pool.clear(); } @Override public synchronized String toString() { - return String.format("DeduplicationCache ( %d de-duplicated, %d entries )", - this.getDeduplicatedCount(), this.getSize()); + return String.format("DeduplicationCache ( %d/%d de-duplicated, %d pooled )", + this.deduplicated, this.attemptedInsertions, this.pool.size()); } }