diff options
author | FrozenCow <frozencow@gmail.com> | 2011-03-01 19:19:50 +0100 |
---|---|---|
committer | Tahg <tahgtahv@gmail.com> | 2011-03-01 16:37:19 -0500 |
commit | 9832ce06f11f17d5b8ca80079392958284c00738 (patch) | |
tree | 7365c8d9bf0812ffc76da6cfbca964f0b5d72cbc /src/main/java/net/minecraft/server | |
parent | 13fb0e07ce5c8220c83757aa4db7e9c2d70d4206 (diff) | |
download | craftbukkit-9832ce06f11f17d5b8ca80079392958284c00738.tar craftbukkit-9832ce06f11f17d5b8ca80079392958284c00738.tar.gz craftbukkit-9832ce06f11f17d5b8ca80079392958284c00738.tar.lz craftbukkit-9832ce06f11f17d5b8ca80079392958284c00738.tar.xz craftbukkit-9832ce06f11f17d5b8ca80079392958284c00738.zip |
Synchronized and moved Hash classes
Diffstat (limited to 'src/main/java/net/minecraft/server')
4 files changed, 2 insertions, 288 deletions
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java index 4ff1ffa6..5d54c2cd 100644 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -12,6 +12,8 @@ import java.util.Set; import org.bukkit.Server; import org.bukkit.craftbukkit.CraftChunk; import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.util.LongHashset; +import org.bukkit.craftbukkit.util.LongHashtable; import org.bukkit.event.Event.Type; import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkUnloadEvent; diff --git a/src/main/java/net/minecraft/server/LongHash.java b/src/main/java/net/minecraft/server/LongHash.java deleted file mode 100644 index 06da49ab..00000000 --- a/src/main/java/net/minecraft/server/LongHash.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package net.minecraft.server; - -/** - * - * @author Nathan - */ -public abstract class LongHash<V> { - static long toLong(int msw, int lsw) { - return ((long)msw << 32) + lsw - Integer.MIN_VALUE; - } - - static int msw(long l) { - return (int) (l >> 32); - } - - static int lsw(long l) { - return (int) (l & 0xFFFFFFFF) + Integer.MIN_VALUE; - } - - public boolean containsKey(int msw, int lsw) { - return containsKey(toLong(msw, lsw)); - } - - public void remove(int msw, int lsw) { - remove(toLong(msw, lsw)); - } - - public abstract boolean containsKey(long key); - - public abstract void remove(long key); -} diff --git a/src/main/java/net/minecraft/server/LongHashset.java b/src/main/java/net/minecraft/server/LongHashset.java deleted file mode 100644 index 6e65a351..00000000 --- a/src/main/java/net/minecraft/server/LongHashset.java +++ /dev/null @@ -1,106 +0,0 @@ -package net.minecraft.server; -import java.util.ArrayList; -import java.util.Arrays; - -public class LongHashset<V> extends LongHash<V> { - long values[][][] = new long[256][][]; - int count = 0; - - public boolean isEmpty() { - return count == 0; - } - - public void add(int msw, int lsw) { - add(toLong(msw, lsw)); - } - - public void add(long key) { - int mainIdx = (int) (key & 255); - int outerIdx = (int) ((key >> 32) & 255); - long outer[][] = values[mainIdx], inner[]; - if(outer == null) values[mainIdx] = outer = new long[256][]; - inner = outer[outerIdx]; - if(inner == null) { - outer[outerIdx] = inner = new long[1]; - inner[0] = key; - count++; - } - else { - int i; - for(i = 0; i < inner.length; i++) { - if(inner[i] == key) { - return; - } - } - outer[outerIdx] = inner = Arrays.copyOf(inner, i+1); - inner[i] = key; - count++; - } - } - - public boolean containsKey(long key) { - int mainIdx = (int) (key & 255); - int outerIdx = (int) ((key >> 32) & 255); - long outer[][] = values[mainIdx], inner[]; - if(outer == null) return false; - inner = outer[outerIdx]; - if(inner == null) return false; - else { - for(long entry : inner) { - if(entry == key) return true; - } - return false; - } - } - - public void remove(long key) { - long[][] outer = this.values[(int) (key & 255)]; - if (outer == null) return; - - long[] inner = outer[(int) ((key >> 32) & 255)]; - if (inner == null) return; - - int max = inner.length - 1; - for(int i = 0; i <= max; i++) { - if(inner[i] == key) { - count--; - if(i != max) { - inner[i] = inner[max]; - } - outer[(int) ((key >> 32) & 255)] = (max == 0 ? null : Arrays.copyOf(inner, max)); - return; - } - } - } - - public long popFirst() { - for(long[][] outer : values) { - if(outer == null) continue; - for(int i = 0; i < outer.length ; i++) { - long[] inner = outer[i]; - if(inner == null || inner.length == 0) continue; - count--; - long ret = inner[inner.length - 1]; - outer[i] = Arrays.copyOf(inner, inner.length - 1); - return ret; - - } - } - return 0; - } - - public long[] keys() { - int index = 0; - long ret[] = new long[count]; - for(long[][] outer : values) { - if(outer == null) continue; - for(long[] inner : outer) { - if(inner == null) continue; - for(long entry : inner) { - ret[index++] = entry; - } - } - } - return ret; - } -}
\ No newline at end of file diff --git a/src/main/java/net/minecraft/server/LongHashtable.java b/src/main/java/net/minecraft/server/LongHashtable.java deleted file mode 100644 index b9dc00e1..00000000 --- a/src/main/java/net/minecraft/server/LongHashtable.java +++ /dev/null @@ -1,146 +0,0 @@ -package net.minecraft.server; - -import java.util.ArrayList; -import java.util.Arrays; - -public class LongHashtable<V> extends LongHash -{ - Object values[][][] = new Object[256][][]; - Entry cache = null; - - public void put(int msw, int lsw, V value) { - put(toLong(msw, lsw), value); - if(value instanceof Chunk) { - Chunk c = (Chunk)value; - if(msw != c.j || lsw != c.k) { - MinecraftServer.a.info("Chunk (" + c.j + ", " + c.k +") stored at (" + msw + ", " + lsw + ")"); - Throwable x = new Throwable(); - x.fillInStackTrace(); - x.printStackTrace(); - } - } - } - - public V get(int msw, int lsw) { - V value = get(toLong(msw, lsw)); - if(value instanceof Chunk) { - Chunk c = (Chunk)value; - if(msw != c.j || lsw != c.k) { - MinecraftServer.a.info("Chunk (" + c.j + ", " + c.k +") stored at (" + msw + ", " + lsw + ")"); - Throwable x = new Throwable(); - x.fillInStackTrace(); - x.printStackTrace(); - } - } - return value; - } - - public void put(long key, V value) { - int mainIdx = (int) (key & 255); - int outerIdx = (int) ((key >> 32) & 255); - Object outer[][] = this.values[mainIdx], inner[]; - if (outer == null) - this.values[mainIdx] = outer = new Object[256][]; - inner = outer[outerIdx]; - if (inner == null) { - outer[outerIdx] = inner = new Object[5]; - inner[0] = cache = new Entry(key, value); - } else { - int i; - for (i = 0; i < inner.length; i++) { - if (inner[i] == null || ((Entry) inner[i]).key == key) { - inner[i] = cache = new Entry(key, value); - return; - } - } - outer[outerIdx] = inner = Arrays.copyOf(inner, i + i); - inner[i] = new Entry(key, value); - } - } - - public V get(long key) { - synchronized(this) { - return containsKey(key) ? (V) cache.value : null; - } - } - - public boolean containsKey(long key) { - if (cache != null && cache.key == key) - return true; - int mainIdx = (int) (key & 255); - int outerIdx = (int) ((key >> 32) & 255); - Object outer[][] = this.values[mainIdx], inner[]; - if (outer == null) - return false; - inner = outer[outerIdx]; - if (inner == null) - return false; - else { - for (int i = 0; i < inner.length; i++) { - Entry e = (Entry) inner[i]; - if (e == null) - return false; - else if (e.key == key) { - cache = e; - return true; - } - } - return false; - } - } - - public void remove(long key) { - Object[][] outer = this.values[(int) (key & 255)]; - if (outer == null) return; - - Object[] inner = outer[(int) ((key >> 32) & 255)]; - if (inner == null) return; - - for (int i = 0; i < inner.length; i++) { - // No more data! bail - if (inner[i] == null) continue; - - // Found our key -- purge it - if (((Entry) inner[i]).key == key) { - - // Move all the elements down - for (i++; i < inner.length; i++) { - if (inner[i] == null) break; - inner[i-1] = inner[i]; - } - inner[i-1] = null; - cache = null; - return; - } - } - } - - public ArrayList<V> values() { - ArrayList<V> ret = new ArrayList<V>(); - for (Object[][] outer : this.values) { - if (outer == null) - continue; - for (Object[] inner : outer) { - if (inner == null) - continue; - for (Object entry : inner) { - if (entry == null) - break; - ret.add((V) ((Entry) entry).value); - } - } - } - return ret; - } - - private class Entry - { - long key; - Object value; - - Entry(long k, Object v) { - key = k; - value = v; - } - } -}
\ No newline at end of file |