summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/LongHashMap.java
diff options
context:
space:
mode:
authorErik Broes <erikbroes@grum.nl>2012-01-12 23:10:13 +0100
committerErik Broes <erikbroes@grum.nl>2012-01-12 23:10:13 +0100
commit7219d4dd858b405f34ea66c67f8ab7d4c07fb4ee (patch)
treea1ca024b03aadf4b687f442b33bf713aecd511f7 /src/main/java/net/minecraft/server/LongHashMap.java
parentdd5ef8725c699e0b2946dc0f6d523ca482404043 (diff)
downloadcraftbukkit-7219d4dd858b405f34ea66c67f8ab7d4c07fb4ee.tar
craftbukkit-7219d4dd858b405f34ea66c67f8ab7d4c07fb4ee.tar.gz
craftbukkit-7219d4dd858b405f34ea66c67f8ab7d4c07fb4ee.tar.lz
craftbukkit-7219d4dd858b405f34ea66c67f8ab7d4c07fb4ee.tar.xz
craftbukkit-7219d4dd858b405f34ea66c67f8ab7d4c07fb4ee.zip
Updated to Minecraft 1.1
Diffstat (limited to 'src/main/java/net/minecraft/server/LongHashMap.java')
-rw-r--r--src/main/java/net/minecraft/server/LongHashMap.java157
1 files changed, 157 insertions, 0 deletions
diff --git a/src/main/java/net/minecraft/server/LongHashMap.java b/src/main/java/net/minecraft/server/LongHashMap.java
new file mode 100644
index 00000000..0e856131
--- /dev/null
+++ b/src/main/java/net/minecraft/server/LongHashMap.java
@@ -0,0 +1,157 @@
+package net.minecraft.server;
+
+public class LongHashMap {
+
+ private transient LongHashMapEntry[] entries = new LongHashMapEntry[16];
+ private transient int count;
+ private int c = 12;
+ private final float d = 0.75F;
+ private transient volatile int e;
+
+ public LongHashMap() {}
+
+ private static int g(long i) {
+ return a((int) (i ^ i >>> 32));
+ }
+
+ private static int a(int i) {
+ i ^= i >>> 20 ^ i >>> 12;
+ return i ^ i >>> 7 ^ i >>> 4;
+ }
+
+ private static int a(int i, int j) {
+ return i & j - 1;
+ }
+
+ public int count() {
+ return this.count;
+ }
+
+ public Object getEntry(long i) {
+ int j = g(i);
+
+ for (LongHashMapEntry longhashmapentry = this.entries[a(j, this.entries.length)]; longhashmapentry != null; longhashmapentry = longhashmapentry.c) {
+ if (longhashmapentry.a == i) {
+ return longhashmapentry.b;
+ }
+ }
+
+ return null;
+ }
+
+ public boolean contains(long i) {
+ return this.c(i) != null;
+ }
+
+ final LongHashMapEntry c(long i) {
+ int j = g(i);
+
+ for (LongHashMapEntry longhashmapentry = this.entries[a(j, this.entries.length)]; longhashmapentry != null; longhashmapentry = longhashmapentry.c) {
+ if (longhashmapentry.a == i) {
+ return longhashmapentry;
+ }
+ }
+
+ return null;
+ }
+
+ public void put(long i, Object object) {
+ int j = g(i);
+ int k = a(j, this.entries.length);
+
+ for (LongHashMapEntry longhashmapentry = this.entries[k]; longhashmapentry != null; longhashmapentry = longhashmapentry.c) {
+ if (longhashmapentry.a == i) {
+ longhashmapentry.b = object;
+ }
+ }
+
+ ++this.e;
+ this.a(j, i, object, k);
+ }
+
+ private void b(int i) {
+ LongHashMapEntry[] alonghashmapentry = this.entries;
+ int j = alonghashmapentry.length;
+
+ if (j == 1073741824) {
+ this.c = Integer.MAX_VALUE;
+ } else {
+ LongHashMapEntry[] alonghashmapentry1 = new LongHashMapEntry[i];
+
+ this.a(alonghashmapentry1);
+ this.entries = alonghashmapentry1;
+ this.c = (int) ((float) i * this.d);
+ }
+ }
+
+ private void a(LongHashMapEntry[] alonghashmapentry) {
+ LongHashMapEntry[] alonghashmapentry1 = this.entries;
+ int i = alonghashmapentry.length;
+
+ for (int j = 0; j < alonghashmapentry1.length; ++j) {
+ LongHashMapEntry longhashmapentry = alonghashmapentry1[j];
+
+ if (longhashmapentry != null) {
+ alonghashmapentry1[j] = null;
+
+ LongHashMapEntry longhashmapentry1;
+
+ do {
+ longhashmapentry1 = longhashmapentry.c;
+ int k = a(longhashmapentry.d, i);
+
+ longhashmapentry.c = alonghashmapentry[k];
+ alonghashmapentry[k] = longhashmapentry;
+ longhashmapentry = longhashmapentry1;
+ } while (longhashmapentry1 != null);
+ }
+ }
+ }
+
+ public Object remove(long i) {
+ LongHashMapEntry longhashmapentry = this.e(i);
+
+ return longhashmapentry == null ? null : longhashmapentry.b;
+ }
+
+ final LongHashMapEntry e(long i) {
+ int j = g(i);
+ int k = a(j, this.entries.length);
+ LongHashMapEntry longhashmapentry = this.entries[k];
+
+ LongHashMapEntry longhashmapentry1;
+ LongHashMapEntry longhashmapentry2;
+
+ for (longhashmapentry1 = longhashmapentry; longhashmapentry1 != null; longhashmapentry1 = longhashmapentry2) {
+ longhashmapentry2 = longhashmapentry1.c;
+ if (longhashmapentry1.a == i) {
+ ++this.e;
+ --this.count;
+ if (longhashmapentry == longhashmapentry1) {
+ this.entries[k] = longhashmapentry2;
+ } else {
+ longhashmapentry.c = longhashmapentry2;
+ }
+
+ return longhashmapentry1;
+ }
+
+ longhashmapentry = longhashmapentry1;
+ }
+
+ return longhashmapentry1;
+ }
+
+ private void a(int i, long j, Object object, int k) {
+ LongHashMapEntry longhashmapentry = this.entries[k];
+
+ this.entries[k] = new LongHashMapEntry(i, j, object, longhashmapentry);
+ if (this.count++ >= this.c) {
+ this.b(2 * this.entries.length);
+ }
+ }
+
+ static int f(long i) {
+ return g(i);
+ }
+}