13
0
geforkt von Mirrors/Paper

fixes for chunks

Dieser Commit ist enthalten in:
Tahg 2011-02-10 14:33:41 -05:00
Ursprung 524f966ef3
Commit 89232b826b
2 geänderte Dateien mit 120 neuen und 99 gelöschten Zeilen

Datei anzeigen

@ -1,16 +1,7 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.minecraft.server; package net.minecraft.server;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
/**
*
* @author Nathan
*/
public class LongHashset<V> extends LongHash<V> { public class LongHashset<V> extends LongHash<V> {
long values[][][] = new long[256][][]; long values[][][] = new long[256][][];
int count = 0; int count = 0;
@ -19,39 +10,43 @@ public class LongHashset<V> extends LongHash<V> {
return count == 0; return count == 0;
} }
public void add(long key, V value) { public void add(int msw, int lsw) {
int idx1 = (int) (key & 255); add(toLong(msw, lsw));
int idx2 = (int) ((key >> 32) & 255); }
long obj1[][] = values[idx1], obj2[];
if(obj1 == null) values[idx1] = obj1 = new long[256][]; public void add(long key) {
obj2 = obj1[idx2]; int mainIdx = (int) (key & 255);
if(obj2 == null) { int outerIdx = (int) ((key >> 32) & 255);
obj1[idx2] = obj2 = new long[1]; long outer[][] = values[mainIdx], inner[];
obj2[0] = key; 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++; count++;
} }
else { else {
int i; int i;
for(i = 0; i < obj2.length; i++) { for(i = 0; i < inner.length; i++) {
if(obj2[i] == key) { if(inner[i] == key) {
return; return;
} }
} }
obj2 = Arrays.copyOf(obj2, i+1); outer[0] = inner = Arrays.copyOf(inner, i+1);
obj2[i] = key; inner[i] = key;
count++; count++;
} }
} }
public boolean containsKey(long key) { public boolean containsKey(long key) {
int idx1 = (int) (key & 255); int mainIdx = (int) (key & 255);
int idx2 = (int) ((key >> 32) & 255); int outerIdx = (int) ((key >> 32) & 255);
long obj1[][] = values[idx1], obj2[]; long outer[][] = values[mainIdx], inner[];
if(obj1 == null) return false; if(outer == null) return false;
obj2 = obj1[idx2]; inner = outer[outerIdx];
if(obj2 == null) return false; if(inner == null) return false;
else { else {
for(long entry : obj2) { for(long entry : inner) {
if(entry == key) return true; if(entry == key) return true;
} }
return false; return false;
@ -59,22 +54,21 @@ public class LongHashset<V> extends LongHash<V> {
} }
public void remove(long key) { public void remove(long key) {
int idx1 = (int) (key & 255); long[][] outer = this.values[(int) (key & 255)];
int idx2 = (int) ((key >> 32) & 255); if (outer == null) return;
long obj1[][] = values[idx1], obj2[];
if(obj1 == null) return; long[] inner = outer[(int) ((key >> 32) & 255)];
obj2 = obj1[idx2]; if (inner == null) return;
if(obj2 == null) return;
else { int max = inner.length - 1;
int max = obj2.length - 1; for(int i = 0; i <= max; i++) {
for(int i = 0; i <= max; i++) { if(inner[i] == key) {
if(obj2[i] == key) { count--;
count--; if(i != max) {
if(i != max) { inner[i] = inner[max];
obj2[i] = obj2[max];
}
obj2 = Arrays.copyOf(obj2, max);
} }
outer[(int) ((key >> 32) & 255)] = (max == 0 ? null : Arrays.copyOf(inner, max));
return;
} }
} }
} }
@ -82,10 +76,12 @@ public class LongHashset<V> extends LongHash<V> {
public long popFirst() { public long popFirst() {
for(long[][] outer : values) { for(long[][] outer : values) {
if(outer == null) continue; if(outer == null) continue;
for(long[] inner : outer) { for(int i = 0; i < outer.length ; i++) {
long[] inner = outer[i];
if(inner == null) continue; if(inner == null) continue;
count--;
long ret = inner[inner.length - 1]; long ret = inner[inner.length - 1];
inner = Arrays.copyOf(inner, inner.length - 1); outer[i] = Arrays.copyOf(inner, inner.length - 1);
return ret; return ret;
} }
} }

Datei anzeigen

@ -1,17 +1,10 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.minecraft.server; package net.minecraft.server;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
/** public class LongHashtable<V> extends LongHash
* {
* @author Nathan
*/
public class LongHashtable<V> extends LongHash {
Object values[][][] = new Object[256][][]; Object values[][][] = new Object[256][][];
Entry cache = null; Entry cache = null;
@ -24,25 +17,25 @@ public class LongHashtable<V> extends LongHash {
} }
public void put(long key, V value) { public void put(long key, V value) {
int idx1 = (int) (key & 255); int mainIdx = (int) (key & 255);
int idx2 = (int) ((key >> 32) & 255); int outerIdx = (int) ((key >> 32) & 255);
Object obj1[][] = values[idx1], obj2[]; Object outer[][] = this.values[mainIdx], inner[];
if(obj1 == null) values[idx1] = obj1 = new Object[256][]; if (outer == null)
obj2 = obj1[idx2]; this.values[mainIdx] = outer = new Object[256][];
if(obj2 == null) { inner = outer[outerIdx];
obj1[idx2] = obj2 = new Object[5]; if (inner == null) {
obj2[0] = cache = new Entry(key, value); outer[outerIdx] = inner = new Object[5];
} inner[0] = cache = new Entry(key, value);
else { } else {
int i; int i;
for(i = 0; i < obj2.length; i++) { for (i = 0; i < inner.length; i++) {
if(obj2[i] == null || ((Entry)obj2[i]).key == key) { if (inner[i] == null || ((Entry) inner[i]).key == key) {
obj2[i] = cache = new Entry(key, value); inner[i] = cache = new Entry(key, value);
return; return;
} }
} }
obj2 = Arrays.copyOf(obj2, i+i); outer[outerIdx] = inner = Arrays.copyOf(inner, i + i);
obj2[i] = new Entry(key, value); inner[i] = new Entry(key, value);
} }
} }
@ -51,18 +44,22 @@ public class LongHashtable<V> extends LongHash {
} }
public boolean containsKey(long key) { public boolean containsKey(long key) {
if(cache != null && cache.key == key) return true; if (cache != null && cache.key == key)
int idx1 = (int) (key & 255); return true;
int idx2 = (int) ((key >> 32) & 255); int mainIdx = (int) (key & 255);
Object obj1[][] = values[idx1], obj2[]; int outerIdx = (int) ((key >> 32) & 255);
if(obj1 == null) return false; Object outer[][] = this.values[mainIdx], inner[];
obj2 = obj1[idx2]; if (outer == null)
if(obj2 == null) return false; return false;
inner = outer[outerIdx];
if (inner == null)
return false;
else { else {
for(int i = 0; i < obj2.length; i++) { for (int i = 0; i < inner.length; i++) {
Entry e = (Entry)obj2[i]; Entry e = (Entry) inner[i];
if(e == null) return false; if (e == null)
else if(e.key == key) { return false;
else if (e.key == key) {
cache = e; cache = e;
return true; return true;
} }
@ -72,26 +69,54 @@ public class LongHashtable<V> extends LongHash {
} }
public void remove(long key) { 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() { public ArrayList<V> values() {
ArrayList<V> ret = new ArrayList<V>(); ArrayList<V> ret = new ArrayList<V>();
for(Object[][] outer : values) { for (Object[][] outer : this.values) {
if(outer == null) continue; if (outer == null)
for(Object[] inner : outer) { continue;
if(inner == null) continue; for (Object[] inner : outer) {
for(Object entry : inner) { if (inner == null)
if(entry == null) break; continue;
ret.add((V)((Entry)entry).value); for (Object entry : inner) {
if (entry == null)
break;
ret.add((V) ((Entry) entry).value);
} }
} }
} }
return ret; return ret;
} }
private class Entry { private class Entry
{
long key; long key;
Object value; Object value;
Entry(long k, Object v) { Entry(long k, Object v) {
key = k; key = k;
value = v; value = v;