geforkt von Mirrors/Paper
fixes for chunks
Dieser Commit ist enthalten in:
Ursprung
524f966ef3
Commit
89232b826b
@ -1,16 +1,7 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package net.minecraft.server;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Nathan
|
||||
*/
|
||||
public class LongHashset<V> extends LongHash<V> {
|
||||
long values[][][] = new long[256][][];
|
||||
int count = 0;
|
||||
@ -19,39 +10,43 @@ public class LongHashset<V> extends LongHash<V> {
|
||||
return count == 0;
|
||||
}
|
||||
|
||||
public void add(long key, V value) {
|
||||
int idx1 = (int) (key & 255);
|
||||
int idx2 = (int) ((key >> 32) & 255);
|
||||
long obj1[][] = values[idx1], obj2[];
|
||||
if(obj1 == null) values[idx1] = obj1 = new long[256][];
|
||||
obj2 = obj1[idx2];
|
||||
if(obj2 == null) {
|
||||
obj1[idx2] = obj2 = new long[1];
|
||||
obj2[0] = key;
|
||||
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 < obj2.length; i++) {
|
||||
if(obj2[i] == key) {
|
||||
for(i = 0; i < inner.length; i++) {
|
||||
if(inner[i] == key) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
obj2 = Arrays.copyOf(obj2, i+1);
|
||||
obj2[i] = key;
|
||||
outer[0] = inner = Arrays.copyOf(inner, i+1);
|
||||
inner[i] = key;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsKey(long key) {
|
||||
int idx1 = (int) (key & 255);
|
||||
int idx2 = (int) ((key >> 32) & 255);
|
||||
long obj1[][] = values[idx1], obj2[];
|
||||
if(obj1 == null) return false;
|
||||
obj2 = obj1[idx2];
|
||||
if(obj2 == null) return false;
|
||||
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 : obj2) {
|
||||
for(long entry : inner) {
|
||||
if(entry == key) return true;
|
||||
}
|
||||
return false;
|
||||
@ -59,22 +54,21 @@ public class LongHashset<V> extends LongHash<V> {
|
||||
}
|
||||
|
||||
public void remove(long key) {
|
||||
int idx1 = (int) (key & 255);
|
||||
int idx2 = (int) ((key >> 32) & 255);
|
||||
long obj1[][] = values[idx1], obj2[];
|
||||
if(obj1 == null) return;
|
||||
obj2 = obj1[idx2];
|
||||
if(obj2 == null) return;
|
||||
else {
|
||||
int max = obj2.length - 1;
|
||||
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(obj2[i] == key) {
|
||||
if(inner[i] == key) {
|
||||
count--;
|
||||
if(i != max) {
|
||||
obj2[i] = obj2[max];
|
||||
}
|
||||
obj2 = Arrays.copyOf(obj2, max);
|
||||
inner[i] = inner[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() {
|
||||
for(long[][] outer : values) {
|
||||
if(outer == null) continue;
|
||||
for(long[] inner : outer) {
|
||||
for(int i = 0; i < outer.length ; i++) {
|
||||
long[] inner = outer[i];
|
||||
if(inner == null) continue;
|
||||
count--;
|
||||
long ret = inner[inner.length - 1];
|
||||
inner = Arrays.copyOf(inner, inner.length - 1);
|
||||
outer[i] = Arrays.copyOf(inner, inner.length - 1);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,10 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package net.minecraft.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Nathan
|
||||
*/
|
||||
public class LongHashtable<V> extends LongHash {
|
||||
public class LongHashtable<V> extends LongHash
|
||||
{
|
||||
Object values[][][] = new Object[256][][];
|
||||
Entry cache = null;
|
||||
|
||||
@ -24,25 +17,25 @@ public class LongHashtable<V> extends LongHash {
|
||||
}
|
||||
|
||||
public void put(long key, V value) {
|
||||
int idx1 = (int) (key & 255);
|
||||
int idx2 = (int) ((key >> 32) & 255);
|
||||
Object obj1[][] = values[idx1], obj2[];
|
||||
if(obj1 == null) values[idx1] = obj1 = new Object[256][];
|
||||
obj2 = obj1[idx2];
|
||||
if(obj2 == null) {
|
||||
obj1[idx2] = obj2 = new Object[5];
|
||||
obj2[0] = cache = new Entry(key, value);
|
||||
}
|
||||
else {
|
||||
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 < obj2.length; i++) {
|
||||
if(obj2[i] == null || ((Entry)obj2[i]).key == key) {
|
||||
obj2[i] = cache = new Entry(key, value);
|
||||
for (i = 0; i < inner.length; i++) {
|
||||
if (inner[i] == null || ((Entry) inner[i]).key == key) {
|
||||
inner[i] = cache = new Entry(key, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
obj2 = Arrays.copyOf(obj2, i+i);
|
||||
obj2[i] = new Entry(key, value);
|
||||
outer[outerIdx] = inner = Arrays.copyOf(inner, i + i);
|
||||
inner[i] = new Entry(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,17 +44,21 @@ public class LongHashtable<V> extends LongHash {
|
||||
}
|
||||
|
||||
public boolean containsKey(long key) {
|
||||
if(cache != null && cache.key == key) return true;
|
||||
int idx1 = (int) (key & 255);
|
||||
int idx2 = (int) ((key >> 32) & 255);
|
||||
Object obj1[][] = values[idx1], obj2[];
|
||||
if(obj1 == null) return false;
|
||||
obj2 = obj1[idx2];
|
||||
if(obj2 == null) return false;
|
||||
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 < obj2.length; i++) {
|
||||
Entry e = (Entry)obj2[i];
|
||||
if(e == null) return false;
|
||||
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;
|
||||
@ -72,16 +69,42 @@ public class LongHashtable<V> extends LongHash {
|
||||
}
|
||||
|
||||
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 : values) {
|
||||
if(outer == null) continue;
|
||||
for (Object[][] outer : this.values) {
|
||||
if (outer == null)
|
||||
continue;
|
||||
for (Object[] inner : outer) {
|
||||
if(inner == null) continue;
|
||||
if (inner == null)
|
||||
continue;
|
||||
for (Object entry : inner) {
|
||||
if(entry == null) break;
|
||||
if (entry == null)
|
||||
break;
|
||||
ret.add((V) ((Entry) entry).value);
|
||||
}
|
||||
}
|
||||
@ -89,9 +112,11 @@ public class LongHashtable<V> extends LongHash {
|
||||
return ret;
|
||||
}
|
||||
|
||||
private class Entry {
|
||||
private class Entry
|
||||
{
|
||||
long key;
|
||||
Object value;
|
||||
|
||||
Entry(long k, Object v) {
|
||||
key = k;
|
||||
value = v;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren