Synchronized and moved Hash classes

This commit is contained in:
FrozenCow 2011-03-01 19:19:50 +01:00 committed by Tahg
parent 13fb0e07ce
commit 9832ce06f1
5 changed files with 15 additions and 15 deletions

View file

@ -12,6 +12,8 @@ import java.util.Set;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.craftbukkit.CraftChunk; import org.bukkit.craftbukkit.CraftChunk;
import org.bukkit.craftbukkit.CraftServer; 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.Event.Type;
import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.event.world.ChunkUnloadEvent;

View file

@ -8,7 +8,6 @@ import net.minecraft.server.ItemInWorldManager;
import net.minecraft.server.Packet; import net.minecraft.server.Packet;
import net.minecraft.server.Packet3Chat; import net.minecraft.server.Packet3Chat;
import net.minecraft.server.Packet6SpawnPosition; import net.minecraft.server.Packet6SpawnPosition;
import net.minecraft.server.Packet9Respawn;
import net.minecraft.server.ServerConfigurationManager; import net.minecraft.server.ServerConfigurationManager;
import net.minecraft.server.WorldServer; import net.minecraft.server.WorldServer;
import org.bukkit.Location; import org.bukkit.Location;

View file

@ -3,13 +3,13 @@
* and open the template in the editor. * and open the template in the editor.
*/ */
package net.minecraft.server; package org.bukkit.craftbukkit.util;
/** /**
* *
* @author Nathan * @author Nathan
*/ */
public abstract class LongHash<V> { public abstract class LongHash {
static long toLong(int msw, int lsw) { static long toLong(int msw, int lsw) {
return ((long)msw << 32) + lsw - Integer.MIN_VALUE; return ((long)msw << 32) + lsw - Integer.MIN_VALUE;
} }

View file

@ -1,8 +1,7 @@
package net.minecraft.server; package org.bukkit.craftbukkit.util;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
public class LongHashset<V> extends LongHash<V> { public class LongHashset extends LongHash {
long values[][][] = new long[256][][]; long values[][][] = new long[256][][];
int count = 0; int count = 0;

View file

@ -1,7 +1,9 @@
package net.minecraft.server; package org.bukkit.craftbukkit.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import net.minecraft.server.Chunk;
import net.minecraft.server.MinecraftServer;
public class LongHashtable<V> extends LongHash public class LongHashtable<V> extends LongHash
{ {
@ -35,7 +37,7 @@ public class LongHashtable<V> extends LongHash
return value; return value;
} }
public void put(long key, V value) { public synchronized void put(long key, V value) {
int mainIdx = (int) (key & 255); int mainIdx = (int) (key & 255);
int outerIdx = (int) ((key >> 32) & 255); int outerIdx = (int) ((key >> 32) & 255);
Object outer[][] = this.values[mainIdx], inner[]; Object outer[][] = this.values[mainIdx], inner[];
@ -58,13 +60,11 @@ public class LongHashtable<V> extends LongHash
} }
} }
public V get(long key) { public synchronized V get(long key) {
synchronized(this) {
return containsKey(key) ? (V) cache.value : null; return containsKey(key) ? (V) cache.value : null;
} }
}
public boolean containsKey(long key) { public synchronized boolean containsKey(long key) {
if (cache != null && cache.key == key) if (cache != null && cache.key == key)
return true; return true;
int mainIdx = (int) (key & 255); int mainIdx = (int) (key & 255);
@ -89,7 +89,7 @@ public class LongHashtable<V> extends LongHash
} }
} }
public void remove(long key) { public synchronized void remove(long key) {
Object[][] outer = this.values[(int) (key & 255)]; Object[][] outer = this.values[(int) (key & 255)];
if (outer == null) return; if (outer == null) return;
@ -115,7 +115,7 @@ public class LongHashtable<V> extends LongHash
} }
} }
public ArrayList<V> values() { public synchronized ArrayList<V> values() {
ArrayList<V> ret = new ArrayList<V>(); ArrayList<V> ret = new ArrayList<V>();
for (Object[][] outer : this.values) { for (Object[][] outer : this.values) {
if (outer == null) if (outer == null)