mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-17 10:55:04 +00:00
format all the things!
This commit is contained in:
1 parent
54ec75fd3d
commit
b36c6dade6
377 files changed
+6833
-6772
No files matched your search
@@ -5,233 +5,240 @@
|
||||
package stanhebben.zenscript.parser;
|
||||
|
||||
/**
|
||||
* A HashMap implementation which is optimized to associate integers with integers.
|
||||
* A HashMap implementation which is optimized to associate integers with
|
||||
* integers.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class HashMapII {
|
||||
private int[] keys;
|
||||
private int[] values;
|
||||
private int[] next;
|
||||
private int mask;
|
||||
private int size;
|
||||
private int[] keys;
|
||||
private int[] values;
|
||||
private int[] next;
|
||||
private int mask;
|
||||
private int size;
|
||||
|
||||
/**
|
||||
* Creates a new HashMap for integer keys and values.
|
||||
*/
|
||||
public HashMapII() {
|
||||
keys = new int[16];
|
||||
values = new int[16];
|
||||
next = new int[16];
|
||||
mask = 15;
|
||||
size = 0;
|
||||
/**
|
||||
* Creates a new HashMap for integer keys and values.
|
||||
*/
|
||||
public HashMapII() {
|
||||
keys = new int[16];
|
||||
values = new int[16];
|
||||
next = new int[16];
|
||||
mask = 15;
|
||||
size = 0;
|
||||
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
keys[i] = Integer.MIN_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of key/value pairs in the hashmap.
|
||||
*
|
||||
* @return hashmap size
|
||||
*/
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
keys[i] = Integer.MIN_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Associates the specified value with the specified key in this map. If the
|
||||
* map previously contained a mapping for the key, the old value is replaced.
|
||||
*
|
||||
* @param key key with which the specified value is to be associated
|
||||
* @param value value to be associated with the specified key
|
||||
*/
|
||||
public void put(int key, int value) {
|
||||
if (size > (keys.length * 3) >> 2) {
|
||||
expand();
|
||||
}
|
||||
/**
|
||||
* Returns the number of key/value pairs in the hashmap.
|
||||
*
|
||||
* @return hashmap size
|
||||
*/
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
int index = key & mask;
|
||||
/**
|
||||
* Associates the specified value with the specified key in this map. If the
|
||||
* map previously contained a mapping for the key, the old value is
|
||||
* replaced.
|
||||
*
|
||||
* @param key key with which the specified value is to be associated
|
||||
* @param value value to be associated with the specified key
|
||||
*/
|
||||
public void put(int key, int value) {
|
||||
if (size > (keys.length * 3) >> 2) {
|
||||
expand();
|
||||
}
|
||||
|
||||
if (keys[index] == Integer.MIN_VALUE) {
|
||||
keys[index] = key;
|
||||
values[index] = value;
|
||||
} else {
|
||||
while (next[index] != 0) {
|
||||
index = next[index] - 1;
|
||||
if (keys[index] == key) {
|
||||
values[index] = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
int ref = index;
|
||||
while (keys[index] != Integer.MIN_VALUE) {
|
||||
index++;
|
||||
if (index == keys.length) index = 0;
|
||||
}
|
||||
next[ref] = index + 1;
|
||||
int index = key & mask;
|
||||
|
||||
keys[index] = key;
|
||||
values[index] = value;
|
||||
}
|
||||
if (keys[index] == Integer.MIN_VALUE) {
|
||||
keys[index] = key;
|
||||
values[index] = value;
|
||||
} else {
|
||||
while (next[index] != 0) {
|
||||
index = next[index] - 1;
|
||||
if (keys[index] == key) {
|
||||
values[index] = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
int ref = index;
|
||||
while (keys[index] != Integer.MIN_VALUE) {
|
||||
index++;
|
||||
if (index == keys.length)
|
||||
index = 0;
|
||||
}
|
||||
next[ref] = index + 1;
|
||||
|
||||
size++;
|
||||
}
|
||||
keys[index] = key;
|
||||
values[index] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value to which the specified key is mapped, or null if this
|
||||
* map contains no mapping for the key.
|
||||
*
|
||||
* @param key the key whose associated value is to be returned
|
||||
* @return the value to which the specified key is mapped, or Integer.MIN_VALUE if this map contains no mapping for the key
|
||||
*/
|
||||
public int get(int key) {
|
||||
int index = key & mask;
|
||||
while (keys[index] != key) {
|
||||
if (next[index] == 0) {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
index = next[index] - 1;
|
||||
}
|
||||
return values[index];
|
||||
}
|
||||
size++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value to which the specified key is mapped, or null if this
|
||||
* map contains no mapping for the key.
|
||||
*
|
||||
* @param key the key whose associated value is to be returned
|
||||
* @param def the default key value
|
||||
* @return the value to which the specified key is mapped, or the default value if this map contains no mapping for the key
|
||||
*/
|
||||
public int get(int key, int def) {
|
||||
int index = key & mask;
|
||||
while (keys[index] != key) {
|
||||
if (next[index] == 0) {
|
||||
return def;
|
||||
}
|
||||
index = next[index] - 1;
|
||||
}
|
||||
return values[index];
|
||||
}
|
||||
/**
|
||||
* Returns the value to which the specified key is mapped, or null if this
|
||||
* map contains no mapping for the key.
|
||||
*
|
||||
* @param key the key whose associated value is to be returned
|
||||
* @return the value to which the specified key is mapped, or
|
||||
* Integer.MIN_VALUE if this map contains no mapping for the key
|
||||
*/
|
||||
public int get(int key) {
|
||||
int index = key & mask;
|
||||
while (keys[index] != key) {
|
||||
if (next[index] == 0) {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
index = next[index] - 1;
|
||||
}
|
||||
return values[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this map contains a mapping for the specified key.
|
||||
*
|
||||
* @param key The key whose presence in this map is to be tested
|
||||
* @return true if this map contains a mapping for the specified key.
|
||||
*/
|
||||
public boolean containsKey(int key) {
|
||||
int index = key & mask;
|
||||
while (keys[index] != key) {
|
||||
if (next[index] == 0) {
|
||||
return false;
|
||||
}
|
||||
index = next[index] - 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Returns the value to which the specified key is mapped, or null if this
|
||||
* map contains no mapping for the key.
|
||||
*
|
||||
* @param key the key whose associated value is to be returned
|
||||
* @param def the default key value
|
||||
* @return the value to which the specified key is mapped, or the default
|
||||
* value if this map contains no mapping for the key
|
||||
*/
|
||||
public int get(int key, int def) {
|
||||
int index = key & mask;
|
||||
while (keys[index] != key) {
|
||||
if (next[index] == 0) {
|
||||
return def;
|
||||
}
|
||||
index = next[index] - 1;
|
||||
}
|
||||
return values[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over the keys in this HashMap. The elements are
|
||||
* returned in no particular order.
|
||||
*
|
||||
* @return an iterator over the keys in this HashMap
|
||||
*/
|
||||
public IteratorI keys() {
|
||||
return new KeyIterator();
|
||||
}
|
||||
/**
|
||||
* Returns true if this map contains a mapping for the specified key.
|
||||
*
|
||||
* @param key The key whose presence in this map is to be tested
|
||||
* @return true if this map contains a mapping for the specified key.
|
||||
*/
|
||||
public boolean containsKey(int key) {
|
||||
int index = key & mask;
|
||||
while (keys[index] != key) {
|
||||
if (next[index] == 0) {
|
||||
return false;
|
||||
}
|
||||
index = next[index] - 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with all keys in this HashMap. The elements are returned
|
||||
* in no particular order.
|
||||
*
|
||||
* @return an array with all keys in this HashMap
|
||||
*/
|
||||
public int[] keysArray() {
|
||||
int[] result = new int[size];
|
||||
int ix = 0;
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
if (keys[i] != Integer.MIN_VALUE) result[ix++] = keys[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Returns an iterator over the keys in this HashMap. The elements are
|
||||
* returned in no particular order.
|
||||
*
|
||||
* @return an iterator over the keys in this HashMap
|
||||
*/
|
||||
public IteratorI keys() {
|
||||
return new KeyIterator();
|
||||
}
|
||||
|
||||
////////////////////
|
||||
// Private methods
|
||||
////////////////////
|
||||
/**
|
||||
* Returns an array with all keys in this HashMap. The elements are returned
|
||||
* in no particular order.
|
||||
*
|
||||
* @return an array with all keys in this HashMap
|
||||
*/
|
||||
public int[] keysArray() {
|
||||
int[] result = new int[size];
|
||||
int ix = 0;
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
if (keys[i] != Integer.MIN_VALUE)
|
||||
result[ix++] = keys[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands the size of this array. (it doubles the size)
|
||||
*/
|
||||
private void expand() {
|
||||
int[] newKeys = new int[keys.length * 2];
|
||||
int[] newValues = new int[values.length * 2];
|
||||
int[] newNext = new int[next.length * 2];
|
||||
int newMask = newKeys.length - 1;
|
||||
// //////////////////
|
||||
// Private methods
|
||||
// //////////////////
|
||||
|
||||
for (int i = 0; i < newKeys.length; i++) {
|
||||
newKeys[i] = Integer.MIN_VALUE;
|
||||
}
|
||||
/**
|
||||
* Expands the size of this array. (it doubles the size)
|
||||
*/
|
||||
private void expand() {
|
||||
int[] newKeys = new int[keys.length * 2];
|
||||
int[] newValues = new int[values.length * 2];
|
||||
int[] newNext = new int[next.length * 2];
|
||||
int newMask = newKeys.length - 1;
|
||||
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
if (keys[i] == Integer.MIN_VALUE) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < newKeys.length; i++) {
|
||||
newKeys[i] = Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
int key = keys[i];
|
||||
int value = values[i];
|
||||
int index = key & newMask;
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
if (keys[i] == Integer.MIN_VALUE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (newKeys[index] == Integer.MIN_VALUE) {
|
||||
newKeys[index] = key;
|
||||
newValues[index] = value;
|
||||
} else {
|
||||
while (newNext[index] != 0) {
|
||||
index = newNext[index] - 1;
|
||||
}
|
||||
int ref = index;
|
||||
while (newKeys[index] != Integer.MIN_VALUE) {
|
||||
index = (index + 1) & newMask;
|
||||
}
|
||||
newNext[ref] = index + 1;
|
||||
int key = keys[i];
|
||||
int value = values[i];
|
||||
int index = key & newMask;
|
||||
|
||||
newKeys[index] = key;
|
||||
newValues[index] = value;
|
||||
}
|
||||
}
|
||||
if (newKeys[index] == Integer.MIN_VALUE) {
|
||||
newKeys[index] = key;
|
||||
newValues[index] = value;
|
||||
} else {
|
||||
while (newNext[index] != 0) {
|
||||
index = newNext[index] - 1;
|
||||
}
|
||||
int ref = index;
|
||||
while (newKeys[index] != Integer.MIN_VALUE) {
|
||||
index = (index + 1) & newMask;
|
||||
}
|
||||
newNext[ref] = index + 1;
|
||||
|
||||
keys = newKeys;
|
||||
values = newValues;
|
||||
next = newNext;
|
||||
mask = newMask;
|
||||
}
|
||||
newKeys[index] = key;
|
||||
newValues[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////
|
||||
// Private inner classes
|
||||
//////////////////////////
|
||||
keys = newKeys;
|
||||
values = newValues;
|
||||
next = newNext;
|
||||
mask = newMask;
|
||||
}
|
||||
|
||||
private class KeyIterator implements IteratorI {
|
||||
private int i;
|
||||
// ////////////////////////
|
||||
// Private inner classes
|
||||
// ////////////////////////
|
||||
|
||||
public KeyIterator() {
|
||||
i = 0;
|
||||
skip();
|
||||
}
|
||||
private class KeyIterator implements IteratorI {
|
||||
private int i;
|
||||
|
||||
public boolean hasNext() {
|
||||
return i < keys.length;
|
||||
}
|
||||
public KeyIterator() {
|
||||
i = 0;
|
||||
skip();
|
||||
}
|
||||
|
||||
public int next() {
|
||||
int result = keys[i++];
|
||||
skip();
|
||||
return result;
|
||||
}
|
||||
public boolean hasNext() {
|
||||
return i < keys.length;
|
||||
}
|
||||
|
||||
private void skip() {
|
||||
while (i < keys.length && keys[i] == Integer.MIN_VALUE) i++;
|
||||
}
|
||||
}
|
||||
public int next() {
|
||||
int result = keys[i++];
|
||||
skip();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void skip() {
|
||||
while (i < keys.length && keys[i] == Integer.MIN_VALUE)
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user