Suppressed generics/rawtypes/etc warnings, since these aren't my files, I shouldn't change them too much (as they work, as-is)
This commit is contained in:
parent
9adfc35908
commit
6270168430
@ -28,6 +28,7 @@ import dorkbox.util.RandomUtil;
|
|||||||
/** A resizable, ordered or unordered array of objects. If unordered, this class avoids a memory copy when removing elements (the
|
/** A resizable, ordered or unordered array of objects. If unordered, this class avoids a memory copy when removing elements (the
|
||||||
* last element is moved to the removed element's position).
|
* last element is moved to the removed element's position).
|
||||||
* @author Nathan Sweet */
|
* @author Nathan Sweet */
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes", "SuspiciousSystemArraycopy", "unused", "NullableProblems", "DuplicatedCode"})
|
||||||
public class Array<T> implements Iterable<T> {
|
public class Array<T> implements Iterable<T> {
|
||||||
/** Provides direct access to the underlying array. If the Array's generic type is not Object, this field may only be accessed
|
/** Provides direct access to the underlying array. If the Array's generic type is not Object, this field may only be accessed
|
||||||
* if the {@link Array#Array(boolean, int, Class)} constructor was used. */
|
* if the {@link Array#Array(boolean, int, Class)} constructor was used. */
|
||||||
@ -261,7 +262,7 @@ public class Array<T> implements Iterable<T> {
|
|||||||
public T removeIndex (int index) {
|
public T removeIndex (int index) {
|
||||||
if (index >= size) throw new IndexOutOfBoundsException("index can't be >= size: " + index + " >= " + size);
|
if (index >= size) throw new IndexOutOfBoundsException("index can't be >= size: " + index + " >= " + size);
|
||||||
T[] items = this.items;
|
T[] items = this.items;
|
||||||
T value = (T)items[index];
|
T value = items[index];
|
||||||
size--;
|
size--;
|
||||||
if (ordered)
|
if (ordered)
|
||||||
System.arraycopy(items, index + 1, items, index, size - index);
|
System.arraycopy(items, index + 1, items, index, size - index);
|
||||||
@ -448,6 +449,7 @@ public class Array<T> implements Iterable<T> {
|
|||||||
|
|
||||||
/** Returns an iterator for the items in the array. Remove is supported. Note that the same iterator instance is returned each
|
/** Returns an iterator for the items in the array. Remove is supported. Note that the same iterator instance is returned each
|
||||||
* time this method is called. Use the {@link ArrayIterator} constructor for nested or multithreaded iteration. */
|
* time this method is called. Use the {@link ArrayIterator} constructor for nested or multithreaded iteration. */
|
||||||
|
@Override
|
||||||
public Iterator<T> iterator () {
|
public Iterator<T> iterator () {
|
||||||
if (iterable == null) iterable = new ArrayIterable(this);
|
if (iterable == null) iterable = new ArrayIterable(this);
|
||||||
return iterable.iterator();
|
return iterable.iterator();
|
||||||
@ -492,6 +494,7 @@ public class Array<T> implements Iterable<T> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode () {
|
public int hashCode () {
|
||||||
if (!ordered) return super.hashCode();
|
if (!ordered) return super.hashCode();
|
||||||
Object[] items = this.items;
|
Object[] items = this.items;
|
||||||
@ -504,6 +507,7 @@ public class Array<T> implements Iterable<T> {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals (Object object) {
|
public boolean equals (Object object) {
|
||||||
if (object == this) return true;
|
if (object == this) return true;
|
||||||
if (!ordered) return false;
|
if (!ordered) return false;
|
||||||
@ -522,6 +526,7 @@ public class Array<T> implements Iterable<T> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString () {
|
public String toString () {
|
||||||
if (size == 0) return "[]";
|
if (size == 0) return "[]";
|
||||||
T[] items = this.items;
|
T[] items = this.items;
|
||||||
@ -563,6 +568,7 @@ public class Array<T> implements Iterable<T> {
|
|||||||
return new Array(array);
|
return new Array(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("NullableProblems")
|
||||||
static public class ArrayIterator<T> implements Iterator<T>, Iterable<T> {
|
static public class ArrayIterator<T> implements Iterator<T>, Iterable<T> {
|
||||||
private final Array<T> array;
|
private final Array<T> array;
|
||||||
private final boolean allowRemove;
|
private final boolean allowRemove;
|
||||||
@ -580,6 +586,7 @@ public class Array<T> implements Iterable<T> {
|
|||||||
this.allowRemove = allowRemove;
|
this.allowRemove = allowRemove;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasNext () {
|
public boolean hasNext () {
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
// System.out.println(iterable.lastAcquire);
|
// System.out.println(iterable.lastAcquire);
|
||||||
@ -588,6 +595,7 @@ public class Array<T> implements Iterable<T> {
|
|||||||
return index < array.size;
|
return index < array.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public T next () {
|
public T next () {
|
||||||
if (index >= array.size) throw new NoSuchElementException(String.valueOf(index));
|
if (index >= array.size) throw new NoSuchElementException(String.valueOf(index));
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
@ -597,6 +605,7 @@ public class Array<T> implements Iterable<T> {
|
|||||||
return array.items[index++];
|
return array.items[index++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void remove () {
|
public void remove () {
|
||||||
if (!allowRemove) throw new RuntimeException("Remove not allowed.");
|
if (!allowRemove) throw new RuntimeException("Remove not allowed.");
|
||||||
index--;
|
index--;
|
||||||
@ -607,11 +616,13 @@ public class Array<T> implements Iterable<T> {
|
|||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterator<T> iterator () {
|
public Iterator<T> iterator () {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "NullableProblems"})
|
||||||
static public class ArrayIterable<T> implements Iterable<T> {
|
static public class ArrayIterable<T> implements Iterable<T> {
|
||||||
private final Array<T> array;
|
private final Array<T> array;
|
||||||
private final boolean allowRemove;
|
private final boolean allowRemove;
|
||||||
@ -628,6 +639,7 @@ public class Array<T> implements Iterable<T> {
|
|||||||
this.allowRemove = allowRemove;
|
this.allowRemove = allowRemove;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterator<T> iterator () {
|
public Iterator<T> iterator () {
|
||||||
// lastAcquire.getBuffer().setLength(0);
|
// lastAcquire.getBuffer().setLength(0);
|
||||||
// new Throwable().printStackTrace(new java.io.PrintWriter(lastAcquire));
|
// new Throwable().printStackTrace(new java.io.PrintWriter(lastAcquire));
|
||||||
|
@ -26,6 +26,7 @@ import dorkbox.util.Property;
|
|||||||
/**
|
/**
|
||||||
* @author dorkbox, llc
|
* @author dorkbox, llc
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public
|
public
|
||||||
class ConcurrentIterator<T> {
|
class ConcurrentIterator<T> {
|
||||||
/**
|
/**
|
||||||
|
@ -32,6 +32,7 @@ import dorkbox.util.RandomUtil;
|
|||||||
* depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the
|
* depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the
|
||||||
* next higher POT size.
|
* next higher POT size.
|
||||||
* @author Nathan Sweet */
|
* @author Nathan Sweet */
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes", "NullableProblems"})
|
||||||
public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
|
public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
|
||||||
private static final int PRIME1 = 0xbe1f14b1;
|
private static final int PRIME1 = 0xbe1f14b1;
|
||||||
private static final int PRIME2 = 0xb4b82e39;
|
private static final int PRIME2 = 0xb4b82e39;
|
||||||
@ -510,6 +511,7 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
|
|||||||
return (h ^ h >>> hashShift) & mask;
|
return (h ^ h >>> hashShift) & mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode () {
|
public int hashCode () {
|
||||||
int h = 0;
|
int h = 0;
|
||||||
K[] keyTable = this.keyTable;
|
K[] keyTable = this.keyTable;
|
||||||
@ -528,6 +530,7 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals (Object obj) {
|
public boolean equals (Object obj) {
|
||||||
if (obj == this) return true;
|
if (obj == this) return true;
|
||||||
if (!(obj instanceof IdentityMap)) return false;
|
if (!(obj instanceof IdentityMap)) return false;
|
||||||
@ -553,6 +556,7 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString () {
|
public String toString () {
|
||||||
if (size == 0) return "[]";
|
if (size == 0) return "[]";
|
||||||
StringBuilder buffer = new StringBuilder(32);
|
StringBuilder buffer = new StringBuilder(32);
|
||||||
@ -580,6 +584,7 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
|
|||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterator<Entry<K, V>> iterator () {
|
public Iterator<Entry<K, V>> iterator () {
|
||||||
return entries();
|
return entries();
|
||||||
}
|
}
|
||||||
@ -645,11 +650,13 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
|
|||||||
public K key;
|
public K key;
|
||||||
public V value;
|
public V value;
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString () {
|
public String toString () {
|
||||||
return key + "=" + value;
|
return key + "=" + value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("DuplicatedCode")
|
||||||
static private abstract class MapIterator<K, V, I> implements Iterable<I>, Iterator<I> {
|
static private abstract class MapIterator<K, V, I> implements Iterable<I>, Iterator<I> {
|
||||||
public boolean hasNext;
|
public boolean hasNext;
|
||||||
|
|
||||||
@ -679,6 +686,7 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void remove () {
|
public void remove () {
|
||||||
if (currentIndex < 0) throw new IllegalStateException("next must be called before remove.");
|
if (currentIndex < 0) throw new IllegalStateException("next must be called before remove.");
|
||||||
if (currentIndex >= map.capacity) {
|
if (currentIndex >= map.capacity) {
|
||||||
@ -694,6 +702,7 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"NullableProblems", "DuplicatedCode", "unchecked", "FieldMayBeFinal"})
|
||||||
static public class Entries<K, V> extends MapIterator<K, V, Entry<K, V>> {
|
static public class Entries<K, V> extends MapIterator<K, V, Entry<K, V>> {
|
||||||
private Entry<K, V> entry = new Entry();
|
private Entry<K, V> entry = new Entry();
|
||||||
|
|
||||||
@ -702,6 +711,7 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Note the same entry instance is returned each time this method is called. */
|
/** Note the same entry instance is returned each time this method is called. */
|
||||||
|
@Override
|
||||||
public Entry<K, V> next () {
|
public Entry<K, V> next () {
|
||||||
if (!hasNext) throw new NoSuchElementException();
|
if (!hasNext) throw new NoSuchElementException();
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
@ -713,26 +723,31 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasNext () {
|
public boolean hasNext () {
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
return hasNext;
|
return hasNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterator<Entry<K, V>> iterator () {
|
public Iterator<Entry<K, V>> iterator () {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"rawtypes", "NullableProblems"})
|
||||||
static public class Values<V> extends MapIterator<Object, V, V> {
|
static public class Values<V> extends MapIterator<Object, V, V> {
|
||||||
public Values (IdentityMap<?, V> map) {
|
public Values (IdentityMap<?, V> map) {
|
||||||
super((IdentityMap<Object, V>)map);
|
super((IdentityMap<Object, V>)map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasNext () {
|
public boolean hasNext () {
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
return hasNext;
|
return hasNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public V next () {
|
public V next () {
|
||||||
if (!hasNext) throw new NoSuchElementException();
|
if (!hasNext) throw new NoSuchElementException();
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
@ -742,6 +757,7 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterator<V> iterator () {
|
public Iterator<V> iterator () {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -761,16 +777,19 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
static public class Keys<K> extends MapIterator<K, Object, K> {
|
static public class Keys<K> extends MapIterator<K, Object, K> {
|
||||||
public Keys (IdentityMap<K, ?> map) {
|
public Keys (IdentityMap<K, ?> map) {
|
||||||
super((IdentityMap<K, Object>)map);
|
super((IdentityMap<K, Object>)map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasNext () {
|
public boolean hasNext () {
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
return hasNext;
|
return hasNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public K next () {
|
public K next () {
|
||||||
if (!hasNext) throw new NoSuchElementException();
|
if (!hasNext) throw new NoSuchElementException();
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
@ -780,6 +799,7 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterator<K> iterator () {
|
public Iterator<K> iterator () {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ import dorkbox.util.RandomUtil;
|
|||||||
* depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the
|
* depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the
|
||||||
* next higher POT size.
|
* next higher POT size.
|
||||||
* @author Nathan Sweet */
|
* @author Nathan Sweet */
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
|
public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
|
||||||
private static final int PRIME1 = 0xbe1f14b1;
|
private static final int PRIME1 = 0xbe1f14b1;
|
||||||
private static final int PRIME2 = 0xb4b82e39;
|
private static final int PRIME2 = 0xb4b82e39;
|
||||||
@ -556,6 +557,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
|
|||||||
return (h ^ h >>> hashShift) & mask;
|
return (h ^ h >>> hashShift) & mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode () {
|
public int hashCode () {
|
||||||
int h = 0;
|
int h = 0;
|
||||||
if (hasZeroValue && zeroValue != null) {
|
if (hasZeroValue && zeroValue != null) {
|
||||||
@ -577,6 +579,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals (Object obj) {
|
public boolean equals (Object obj) {
|
||||||
if (obj == this) return true;
|
if (obj == this) return true;
|
||||||
if (!(obj instanceof IntMap)) return false;
|
if (!(obj instanceof IntMap)) return false;
|
||||||
@ -606,6 +609,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString () {
|
public String toString () {
|
||||||
if (size == 0) return "[]";
|
if (size == 0) return "[]";
|
||||||
StringBuilder buffer = new StringBuilder(32);
|
StringBuilder buffer = new StringBuilder(32);
|
||||||
@ -638,6 +642,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
|
|||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterator<Entry<V>> iterator () {
|
public Iterator<Entry<V>> iterator () {
|
||||||
return entries();
|
return entries();
|
||||||
}
|
}
|
||||||
@ -703,6 +708,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
|
|||||||
public int key;
|
public int key;
|
||||||
public V value;
|
public V value;
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString () {
|
public String toString () {
|
||||||
return key + "=" + value;
|
return key + "=" + value;
|
||||||
}
|
}
|
||||||
@ -762,6 +768,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
static public class Entries<V> extends MapIterator<V> implements Iterable<Entry<V>>, Iterator<Entry<V>> {
|
static public class Entries<V> extends MapIterator<V> implements Iterable<Entry<V>>, Iterator<Entry<V>> {
|
||||||
private Entry<V> entry = new Entry();
|
private Entry<V> entry = new Entry();
|
||||||
|
|
||||||
@ -770,6 +777,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Note the same entry instance is returned each time this method is called. */
|
/** Note the same entry instance is returned each time this method is called. */
|
||||||
|
@Override
|
||||||
public Entry<V> next () {
|
public Entry<V> next () {
|
||||||
if (!hasNext) throw new NoSuchElementException();
|
if (!hasNext) throw new NoSuchElementException();
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
@ -786,30 +794,36 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasNext () {
|
public boolean hasNext () {
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
return hasNext;
|
return hasNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterator<Entry<V>> iterator () {
|
public Iterator<Entry<V>> iterator () {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void remove () {
|
public void remove () {
|
||||||
super.remove();
|
super.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
static public class Values<V> extends MapIterator<V> implements Iterable<V>, Iterator<V> {
|
static public class Values<V> extends MapIterator<V> implements Iterable<V>, Iterator<V> {
|
||||||
public Values (IntMap<V> map) {
|
public Values (IntMap<V> map) {
|
||||||
super(map);
|
super(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasNext () {
|
public boolean hasNext () {
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
return hasNext;
|
return hasNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public V next () {
|
public V next () {
|
||||||
if (!hasNext) throw new NoSuchElementException();
|
if (!hasNext) throw new NoSuchElementException();
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
@ -823,6 +837,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterator<V> iterator () {
|
public Iterator<V> iterator () {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -835,12 +850,15 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void remove () {
|
public void remove () {
|
||||||
super.remove();
|
super.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
static public class Keys extends MapIterator {
|
static public class Keys extends MapIterator {
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public Keys (IntMap map) {
|
public Keys (IntMap map) {
|
||||||
super(map);
|
super(map);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,11 @@
|
|||||||
package dorkbox.util.collections;
|
package dorkbox.util.collections;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
|
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -137,6 +141,7 @@ class LockFreeHashMap<K, V> implements Map<K, V>, Cloneable, Serializable {
|
|||||||
.containsValue(value);
|
.containsValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
V get(final Object key) {
|
V get(final Object key) {
|
||||||
|
@ -373,6 +373,7 @@ class LockFreeIntBiMap<V> {
|
|||||||
* Returns an iterator for the values in the map. Remove is supported. Note that the same iterator instance is returned each
|
* Returns an iterator for the values in the map. Remove is supported. Note that the same iterator instance is returned each
|
||||||
* time this method is called. Use the {@link Entries} constructor for nested or multithreaded iteration.
|
* time this method is called. Use the {@link Entries} constructor for nested or multithreaded iteration.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public
|
public
|
||||||
Values<V> values() {
|
Values<V> values() {
|
||||||
return forwardREF.get(this)
|
return forwardREF.get(this)
|
||||||
|
@ -37,6 +37,7 @@ import com.esotericsoftware.kryo.util.ObjectMap.Values;
|
|||||||
* <p>
|
* <p>
|
||||||
* This data structure is for many-read/few-write scenarios
|
* This data structure is for many-read/few-write scenarios
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public final
|
public final
|
||||||
class LockFreeObjectMap<K, V> implements Cloneable, Serializable {
|
class LockFreeObjectMap<K, V> implements Cloneable, Serializable {
|
||||||
// Recommended for best performance while adhering to the "single writer principle". Must be static-final
|
// Recommended for best performance while adhering to the "single writer principle". Must be static-final
|
||||||
|
@ -15,7 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package dorkbox.util.collections;
|
package dorkbox.util.collections;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
|
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,6 +35,7 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
|
|||||||
* <p>
|
* <p>
|
||||||
* This data structure is for many-read/few-write scenarios
|
* This data structure is for many-read/few-write scenarios
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public final
|
public final
|
||||||
class LockFreeSet<E> implements Set<E>, Cloneable, java.io.Serializable {
|
class LockFreeSet<E> implements Set<E>, Cloneable, java.io.Serializable {
|
||||||
// Recommended for best performance while adhering to the "single writer principle". Must be static-final
|
// Recommended for best performance while adhering to the "single writer principle". Must be static-final
|
||||||
|
@ -31,6 +31,7 @@ import dorkbox.util.RandomUtil;
|
|||||||
* depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the
|
* depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the
|
||||||
* next higher POT size.
|
* next higher POT size.
|
||||||
* @author Nathan Sweet */
|
* @author Nathan Sweet */
|
||||||
|
@SuppressWarnings({"NullableProblems", "rawtypes", "unchecked"})
|
||||||
public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
|
public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
|
||||||
private static final int PRIME1 = 0xbe1f14b1;
|
private static final int PRIME1 = 0xbe1f14b1;
|
||||||
private static final int PRIME2 = 0xb4b82e39;
|
private static final int PRIME2 = 0xb4b82e39;
|
||||||
@ -553,6 +554,7 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
|
|||||||
return (int)((h ^ h >>> hashShift) & mask);
|
return (int)((h ^ h >>> hashShift) & mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode () {
|
public int hashCode () {
|
||||||
int h = 0;
|
int h = 0;
|
||||||
if (hasZeroValue && zeroValue != null) {
|
if (hasZeroValue && zeroValue != null) {
|
||||||
@ -574,6 +576,7 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals (Object obj) {
|
public boolean equals (Object obj) {
|
||||||
if (obj == this) return true;
|
if (obj == this) return true;
|
||||||
if (!(obj instanceof LongMap)) return false;
|
if (!(obj instanceof LongMap)) return false;
|
||||||
@ -603,6 +606,7 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString () {
|
public String toString () {
|
||||||
if (size == 0) return "[]";
|
if (size == 0) return "[]";
|
||||||
StringBuilder buffer = new StringBuilder(32);
|
StringBuilder buffer = new StringBuilder(32);
|
||||||
@ -630,6 +634,7 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
|
|||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterator<Entry<V>> iterator () {
|
public Iterator<Entry<V>> iterator () {
|
||||||
return entries();
|
return entries();
|
||||||
}
|
}
|
||||||
@ -695,6 +700,7 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
|
|||||||
public long key;
|
public long key;
|
||||||
public V value;
|
public V value;
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString () {
|
public String toString () {
|
||||||
return key + "=" + value;
|
return key + "=" + value;
|
||||||
}
|
}
|
||||||
@ -754,6 +760,7 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("NullableProblems")
|
||||||
static public class Entries<V> extends MapIterator<V> implements Iterable<Entry<V>>, Iterator<Entry<V>> {
|
static public class Entries<V> extends MapIterator<V> implements Iterable<Entry<V>>, Iterator<Entry<V>> {
|
||||||
private Entry<V> entry = new Entry();
|
private Entry<V> entry = new Entry();
|
||||||
|
|
||||||
@ -762,6 +769,7 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Note the same entry instance is returned each time this method is called. */
|
/** Note the same entry instance is returned each time this method is called. */
|
||||||
|
@Override
|
||||||
public Entry<V> next () {
|
public Entry<V> next () {
|
||||||
if (!hasNext) throw new NoSuchElementException();
|
if (!hasNext) throw new NoSuchElementException();
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
@ -778,30 +786,36 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasNext () {
|
public boolean hasNext () {
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
return hasNext;
|
return hasNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterator<Entry<V>> iterator () {
|
public Iterator<Entry<V>> iterator () {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void remove () {
|
public void remove () {
|
||||||
super.remove();
|
super.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
static public class Values<V> extends MapIterator<V> implements Iterable<V>, Iterator<V> {
|
static public class Values<V> extends MapIterator<V> implements Iterable<V>, Iterator<V> {
|
||||||
public Values (LongMap<V> map) {
|
public Values (LongMap<V> map) {
|
||||||
super(map);
|
super(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasNext () {
|
public boolean hasNext () {
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
return hasNext;
|
return hasNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public V next () {
|
public V next () {
|
||||||
if (!hasNext) throw new NoSuchElementException();
|
if (!hasNext) throw new NoSuchElementException();
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
@ -815,6 +829,7 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterator<V> iterator () {
|
public Iterator<V> iterator () {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -827,11 +842,13 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void remove () {
|
public void remove () {
|
||||||
super.remove();
|
super.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
static public class Keys extends MapIterator {
|
static public class Keys extends MapIterator {
|
||||||
public Keys (LongMap map) {
|
public Keys (LongMap map) {
|
||||||
super(map);
|
super(map);
|
||||||
|
@ -32,6 +32,7 @@ import dorkbox.util.RandomUtil;
|
|||||||
* depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the
|
* depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the
|
||||||
* next higher POT size.
|
* next higher POT size.
|
||||||
* @author Nathan Sweet */
|
* @author Nathan Sweet */
|
||||||
|
@SuppressWarnings({"unchecked", "NullableProblems", "rawtypes"})
|
||||||
public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
|
public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
|
||||||
private static final int PRIME1 = 0xbe1f14b1;
|
private static final int PRIME1 = 0xbe1f14b1;
|
||||||
private static final int PRIME2 = 0xb4b82e39;
|
private static final int PRIME2 = 0xb4b82e39;
|
||||||
@ -66,6 +67,7 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
|
|||||||
/** Creates a new map with the specified initial capacity and load factor. This map will hold initialCapacity items before
|
/** Creates a new map with the specified initial capacity and load factor. This map will hold initialCapacity items before
|
||||||
* growing the backing table.
|
* growing the backing table.
|
||||||
* @param initialCapacity If not a power of two, it is increased to the next nearest power of two. */
|
* @param initialCapacity If not a power of two, it is increased to the next nearest power of two. */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public ObjectFloatMap (int initialCapacity, float loadFactor) {
|
public ObjectFloatMap (int initialCapacity, float loadFactor) {
|
||||||
if (initialCapacity < 0) throw new IllegalArgumentException("initialCapacity must be >= 0: " + initialCapacity);
|
if (initialCapacity < 0) throw new IllegalArgumentException("initialCapacity must be >= 0: " + initialCapacity);
|
||||||
initialCapacity = MathUtil.nextPowerOfTwo((int)Math.ceil(initialCapacity / loadFactor));
|
initialCapacity = MathUtil.nextPowerOfTwo((int)Math.ceil(initialCapacity / loadFactor));
|
||||||
@ -500,6 +502,7 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
|
|||||||
return (h ^ h >>> hashShift) & mask;
|
return (h ^ h >>> hashShift) & mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode () {
|
public int hashCode () {
|
||||||
int h = 0;
|
int h = 0;
|
||||||
K[] keyTable = this.keyTable;
|
K[] keyTable = this.keyTable;
|
||||||
@ -516,6 +519,7 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals (Object obj) {
|
public boolean equals (Object obj) {
|
||||||
if (obj == this) return true;
|
if (obj == this) return true;
|
||||||
if (!(obj instanceof ObjectFloatMap)) return false;
|
if (!(obj instanceof ObjectFloatMap)) return false;
|
||||||
@ -535,6 +539,7 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString () {
|
public String toString () {
|
||||||
if (size == 0) return "{}";
|
if (size == 0) return "{}";
|
||||||
StringBuilder buffer = new StringBuilder(32);
|
StringBuilder buffer = new StringBuilder(32);
|
||||||
@ -562,6 +567,7 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
|
|||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Entries<K> iterator () {
|
public Entries<K> iterator () {
|
||||||
return entries();
|
return entries();
|
||||||
}
|
}
|
||||||
@ -627,6 +633,7 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
|
|||||||
public K key;
|
public K key;
|
||||||
public float value;
|
public float value;
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString () {
|
public String toString () {
|
||||||
return key + "=" + value;
|
return key + "=" + value;
|
||||||
}
|
}
|
||||||
@ -683,6 +690,7 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Note the same entry instance is returned each time this method is called. */
|
/** Note the same entry instance is returned each time this method is called. */
|
||||||
|
@Override
|
||||||
public Entry<K> next () {
|
public Entry<K> next () {
|
||||||
if (!hasNext) throw new NoSuchElementException();
|
if (!hasNext) throw new NoSuchElementException();
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
@ -694,15 +702,18 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasNext () {
|
public boolean hasNext () {
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
return hasNext;
|
return hasNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Entries<K> iterator () {
|
public Entries<K> iterator () {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void remove () {
|
public void remove () {
|
||||||
super.remove();
|
super.remove();
|
||||||
}
|
}
|
||||||
@ -736,16 +747,19 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
static public class Keys<K> extends MapIterator<K> implements Iterable<K>, Iterator<K> {
|
static public class Keys<K> extends MapIterator<K> implements Iterable<K>, Iterator<K> {
|
||||||
public Keys (ObjectFloatMap<K> map) {
|
public Keys (ObjectFloatMap<K> map) {
|
||||||
super((ObjectFloatMap<K>)map);
|
super((ObjectFloatMap<K>)map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasNext () {
|
public boolean hasNext () {
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
return hasNext;
|
return hasNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public K next () {
|
public K next () {
|
||||||
if (!hasNext) throw new NoSuchElementException();
|
if (!hasNext) throw new NoSuchElementException();
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
@ -755,6 +769,7 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Keys<K> iterator () {
|
public Keys<K> iterator () {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -774,6 +789,7 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void remove () {
|
public void remove () {
|
||||||
super.remove();
|
super.remove();
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import dorkbox.util.RandomUtil;
|
|||||||
* depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the
|
* depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the
|
||||||
* next higher POT size.
|
* next higher POT size.
|
||||||
* @author Nathan Sweet */
|
* @author Nathan Sweet */
|
||||||
|
@SuppressWarnings({"unchecked", "NullableProblems"})
|
||||||
public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
|
public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
|
||||||
private static final int PRIME1 = 0xbe1f14b1;
|
private static final int PRIME1 = 0xbe1f14b1;
|
||||||
private static final int PRIME2 = 0xb4b82e39;
|
private static final int PRIME2 = 0xb4b82e39;
|
||||||
@ -501,6 +502,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
|
|||||||
return (h ^ h >>> hashShift) & mask;
|
return (h ^ h >>> hashShift) & mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode () {
|
public int hashCode () {
|
||||||
int h = 0;
|
int h = 0;
|
||||||
K[] keyTable = this.keyTable;
|
K[] keyTable = this.keyTable;
|
||||||
@ -517,6 +519,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals (Object obj) {
|
public boolean equals (Object obj) {
|
||||||
if (obj == this) return true;
|
if (obj == this) return true;
|
||||||
if (!(obj instanceof ObjectIntMap)) return false;
|
if (!(obj instanceof ObjectIntMap)) return false;
|
||||||
@ -536,6 +539,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString () {
|
public String toString () {
|
||||||
if (size == 0) return "{}";
|
if (size == 0) return "{}";
|
||||||
StringBuilder buffer = new StringBuilder(32);
|
StringBuilder buffer = new StringBuilder(32);
|
||||||
@ -563,6 +567,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
|
|||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Entries<K> iterator () {
|
public Entries<K> iterator () {
|
||||||
return entries();
|
return entries();
|
||||||
}
|
}
|
||||||
@ -628,6 +633,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
|
|||||||
public K key;
|
public K key;
|
||||||
public int value;
|
public int value;
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString () {
|
public String toString () {
|
||||||
return key + "=" + value;
|
return key + "=" + value;
|
||||||
}
|
}
|
||||||
@ -684,6 +690,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Note the same entry instance is returned each time this method is called. */
|
/** Note the same entry instance is returned each time this method is called. */
|
||||||
|
@Override
|
||||||
public Entry<K> next () {
|
public Entry<K> next () {
|
||||||
if (!hasNext) throw new NoSuchElementException();
|
if (!hasNext) throw new NoSuchElementException();
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
@ -695,15 +702,18 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasNext () {
|
public boolean hasNext () {
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
return hasNext;
|
return hasNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Entries<K> iterator () {
|
public Entries<K> iterator () {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void remove () {
|
public void remove () {
|
||||||
super.remove();
|
super.remove();
|
||||||
}
|
}
|
||||||
@ -742,11 +752,13 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
|
|||||||
super((ObjectIntMap<K>)map);
|
super((ObjectIntMap<K>)map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasNext () {
|
public boolean hasNext () {
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
return hasNext;
|
return hasNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public K next () {
|
public K next () {
|
||||||
if (!hasNext) throw new NoSuchElementException();
|
if (!hasNext) throw new NoSuchElementException();
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
@ -756,6 +768,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Keys<K> iterator () {
|
public Keys<K> iterator () {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -775,6 +788,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void remove () {
|
public void remove () {
|
||||||
super.remove();
|
super.remove();
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import dorkbox.util.RandomUtil;
|
|||||||
* Iteration can be very slow for a map with a large capacity. {@link #clear(int)} and {@link #shrink(int)} can be used to reduce
|
* Iteration can be very slow for a map with a large capacity. {@link #clear(int)} and {@link #shrink(int)} can be used to reduce
|
||||||
* the capacity. {@link OrderedMap} provides much faster iteration.
|
* the capacity. {@link OrderedMap} provides much faster iteration.
|
||||||
* @author Nathan Sweet */
|
* @author Nathan Sweet */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public class ObjectMap<K, V> implements Iterable<ObjectMap.Entry<K, V>> {
|
public class ObjectMap<K, V> implements Iterable<ObjectMap.Entry<K, V>> {
|
||||||
private static final int PRIME1 = 0xbe1f14b1;
|
private static final int PRIME1 = 0xbe1f14b1;
|
||||||
private static final int PRIME2 = 0xb4b82e39;
|
private static final int PRIME2 = 0xb4b82e39;
|
||||||
@ -722,6 +723,7 @@ public class ObjectMap<K, V> implements Iterable<ObjectMap.Entry<K, V>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("NullableProblems")
|
||||||
static public class Entries<K, V> extends MapIterator<K, V, Entry<K, V>> {
|
static public class Entries<K, V> extends MapIterator<K, V, Entry<K, V>> {
|
||||||
Entry<K, V> entry = new Entry();
|
Entry<K, V> entry = new Entry();
|
||||||
|
|
||||||
@ -754,7 +756,7 @@ public class ObjectMap<K, V> implements Iterable<ObjectMap.Entry<K, V>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("NullableProblems")
|
@SuppressWarnings({"NullableProblems", "unchecked", "rawtypes"})
|
||||||
static public class Values<V> extends MapIterator<Object, V, V> {
|
static public class Values<V> extends MapIterator<Object, V, V> {
|
||||||
public Values (ObjectMap<?, V> map) {
|
public Values (ObjectMap<?, V> map) {
|
||||||
super((ObjectMap<Object, V>)map);
|
super((ObjectMap<Object, V>)map);
|
||||||
@ -794,6 +796,7 @@ public class ObjectMap<K, V> implements Iterable<ObjectMap.Entry<K, V>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "NullableProblems", "rawtypes"})
|
||||||
static public class Keys<K> extends MapIterator<K, Object, K> {
|
static public class Keys<K> extends MapIterator<K, Object, K> {
|
||||||
public Keys (ObjectMap<K, ?> map) {
|
public Keys (ObjectMap<K, ?> map) {
|
||||||
super((ObjectMap<K, Object>)map);
|
super((ObjectMap<K, Object>)map);
|
||||||
|
@ -34,6 +34,7 @@ import dorkbox.util.RandomUtil;
|
|||||||
* Iteration can be very slow for a set with a large capacity. {@link #clear(int)} and {@link #shrink(int)} can be used to reduce
|
* Iteration can be very slow for a set with a large capacity. {@link #clear(int)} and {@link #shrink(int)} can be used to reduce
|
||||||
* the capacity. {@link OrderedSet} provides much faster iteration.
|
* the capacity. {@link OrderedSet} provides much faster iteration.
|
||||||
* @author Nathan Sweet */
|
* @author Nathan Sweet */
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes", "NullableProblems", "SuspiciousSystemArraycopy"})
|
||||||
public class ObjectSet<T> implements Iterable<T> {
|
public class ObjectSet<T> implements Iterable<T> {
|
||||||
private static final int PRIME1 = 0xbe1f14b1;
|
private static final int PRIME1 = 0xbe1f14b1;
|
||||||
private static final int PRIME2 = 0xb4b82e39;
|
private static final int PRIME2 = 0xb4b82e39;
|
||||||
@ -440,6 +441,7 @@ public class ObjectSet<T> implements Iterable<T> {
|
|||||||
return (h ^ h >>> hashShift) & mask;
|
return (h ^ h >>> hashShift) & mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode () {
|
public int hashCode () {
|
||||||
int h = 0;
|
int h = 0;
|
||||||
for (int i = 0, n = capacity + stashSize; i < n; i++)
|
for (int i = 0, n = capacity + stashSize; i < n; i++)
|
||||||
@ -447,6 +449,7 @@ public class ObjectSet<T> implements Iterable<T> {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals (Object obj) {
|
public boolean equals (Object obj) {
|
||||||
if (!(obj instanceof ObjectSet)) return false;
|
if (!(obj instanceof ObjectSet)) return false;
|
||||||
ObjectSet other = (ObjectSet)obj;
|
ObjectSet other = (ObjectSet)obj;
|
||||||
@ -457,6 +460,7 @@ public class ObjectSet<T> implements Iterable<T> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString () {
|
public String toString () {
|
||||||
return '{' + toString(", ") + '}';
|
return '{' + toString(", ") + '}';
|
||||||
}
|
}
|
||||||
@ -483,6 +487,7 @@ public class ObjectSet<T> implements Iterable<T> {
|
|||||||
|
|
||||||
/** Returns an iterator for the keys in the set. Remove is supported. Note that the same iterator instance is returned each
|
/** Returns an iterator for the keys in the set. Remove is supported. Note that the same iterator instance is returned each
|
||||||
* time this method is called. Use the {@link ObjectSetIterator} constructor for nested or multithreaded iteration. */
|
* time this method is called. Use the {@link ObjectSetIterator} constructor for nested or multithreaded iteration. */
|
||||||
|
@Override
|
||||||
public ObjectSetIterator<T> iterator () {
|
public ObjectSetIterator<T> iterator () {
|
||||||
if (iterator1 == null) {
|
if (iterator1 == null) {
|
||||||
iterator1 = new ObjectSetIterator(this);
|
iterator1 = new ObjectSetIterator(this);
|
||||||
@ -535,6 +540,7 @@ public class ObjectSet<T> implements Iterable<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void remove () {
|
public void remove () {
|
||||||
if (currentIndex < 0) throw new IllegalStateException("next must be called before remove.");
|
if (currentIndex < 0) throw new IllegalStateException("next must be called before remove.");
|
||||||
if (currentIndex >= set.capacity) {
|
if (currentIndex >= set.capacity) {
|
||||||
@ -548,11 +554,13 @@ public class ObjectSet<T> implements Iterable<T> {
|
|||||||
set.size--;
|
set.size--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasNext () {
|
public boolean hasNext () {
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
return hasNext;
|
return hasNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public K next () {
|
public K next () {
|
||||||
if (!hasNext) throw new NoSuchElementException();
|
if (!hasNext) throw new NoSuchElementException();
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
@ -562,6 +570,7 @@ public class ObjectSet<T> implements Iterable<T> {
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ObjectSetIterator<K> iterator () {
|
public ObjectSetIterator<K> iterator () {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import java.util.NoSuchElementException;
|
|||||||
* matter, copying during remove can be greatly reduced by setting {@link Array#ordered} to false for
|
* matter, copying during remove can be greatly reduced by setting {@link Array#ordered} to false for
|
||||||
* {@link OrderedSet#orderedItems()}.
|
* {@link OrderedSet#orderedItems()}.
|
||||||
* @author Nathan Sweet */
|
* @author Nathan Sweet */
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public class OrderedSet<T> extends ObjectSet<T> {
|
public class OrderedSet<T> extends ObjectSet<T> {
|
||||||
final Array<T> items;
|
final Array<T> items;
|
||||||
OrderedSetIterator iterator1, iterator2;
|
OrderedSetIterator iterator1, iterator2;
|
||||||
@ -50,6 +51,7 @@ public class OrderedSet<T> extends ObjectSet<T> {
|
|||||||
items.addAll(set.items);
|
items.addAll(set.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean add (T key) {
|
public boolean add (T key) {
|
||||||
if (!super.add(key)) return false;
|
if (!super.add(key)) return false;
|
||||||
items.add(key);
|
items.add(key);
|
||||||
@ -66,6 +68,7 @@ public class OrderedSet<T> extends ObjectSet<T> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean remove (T key) {
|
public boolean remove (T key) {
|
||||||
if (!super.remove(key)) return false;
|
if (!super.remove(key)) return false;
|
||||||
items.removeValue(key, false);
|
items.removeValue(key, false);
|
||||||
@ -78,11 +81,13 @@ public class OrderedSet<T> extends ObjectSet<T> {
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void clear (int maximumCapacity) {
|
public void clear (int maximumCapacity) {
|
||||||
items.clear();
|
items.clear();
|
||||||
super.clear(maximumCapacity);
|
super.clear(maximumCapacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void clear () {
|
public void clear () {
|
||||||
items.clear();
|
items.clear();
|
||||||
super.clear();
|
super.clear();
|
||||||
@ -92,6 +97,7 @@ public class OrderedSet<T> extends ObjectSet<T> {
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public OrderedSetIterator<T> iterator () {
|
public OrderedSetIterator<T> iterator () {
|
||||||
if (iterator1 == null) {
|
if (iterator1 == null) {
|
||||||
iterator1 = new OrderedSetIterator(this);
|
iterator1 = new OrderedSetIterator(this);
|
||||||
@ -109,6 +115,7 @@ public class OrderedSet<T> extends ObjectSet<T> {
|
|||||||
return iterator2;
|
return iterator2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString () {
|
public String toString () {
|
||||||
if (size == 0) return "{}";
|
if (size == 0) return "{}";
|
||||||
T[] items = this.items.items;
|
T[] items = this.items.items;
|
||||||
@ -123,6 +130,7 @@ public class OrderedSet<T> extends ObjectSet<T> {
|
|||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString (String separator) {
|
public String toString (String separator) {
|
||||||
return items.toString(separator);
|
return items.toString(separator);
|
||||||
}
|
}
|
||||||
@ -135,11 +143,13 @@ public class OrderedSet<T> extends ObjectSet<T> {
|
|||||||
items = set.items;
|
items = set.items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void reset () {
|
public void reset () {
|
||||||
nextIndex = 0;
|
nextIndex = 0;
|
||||||
hasNext = set.size > 0;
|
hasNext = set.size > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public T next () {
|
public T next () {
|
||||||
if (!hasNext) throw new NoSuchElementException();
|
if (!hasNext) throw new NoSuchElementException();
|
||||||
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
|
||||||
@ -149,6 +159,7 @@ public class OrderedSet<T> extends ObjectSet<T> {
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void remove () {
|
public void remove () {
|
||||||
if (nextIndex < 0) throw new IllegalStateException("next must be called before remove.");
|
if (nextIndex < 0) throw new IllegalStateException("next must be called before remove.");
|
||||||
nextIndex--;
|
nextIndex--;
|
||||||
|
@ -32,6 +32,7 @@ import java.util.Comparator;
|
|||||||
* single-pass for k=min and k=max, and Hoare's quickselect for values in between.
|
* single-pass for k=min and k=max, and Hoare's quickselect for values in between.
|
||||||
* </p>
|
* </p>
|
||||||
* @author Jon Renner */
|
* @author Jon Renner */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public class Select {
|
public class Select {
|
||||||
private static Select instance;
|
private static Select instance;
|
||||||
private QuickSelect quickSelect;
|
private QuickSelect quickSelect;
|
||||||
|
@ -21,6 +21,7 @@ import java.util.Comparator;
|
|||||||
* Note that sorting primitive arrays with the Arrays.sort methods does not allocate memory (unless sorting large arrays of char,
|
* Note that sorting primitive arrays with the Arrays.sort methods does not allocate memory (unless sorting large arrays of char,
|
||||||
* short, or byte).
|
* short, or byte).
|
||||||
* @author Nathan Sweet */
|
* @author Nathan Sweet */
|
||||||
|
@SuppressWarnings({"RedundantCast", "unchecked", "rawtypes"})
|
||||||
public class Sort {
|
public class Sort {
|
||||||
static private Sort instance;
|
static private Sort instance;
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ import java.util.Comparator;
|
|||||||
* While the API to this class consists solely of static methods, it is (privately) instantiable; a TimSort instance holds the
|
* While the API to this class consists solely of static methods, it is (privately) instantiable; a TimSort instance holds the
|
||||||
* state of an ongoing sort, assuming the input array is large enough to warrant the full-blown TimSort. Small arrays are sorted
|
* state of an ongoing sort, assuming the input array is large enough to warrant the full-blown TimSort. Small arrays are sorted
|
||||||
* in place, using a binary insertion sort. */
|
* in place, using a binary insertion sort. */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
class TimSort<T> {
|
class TimSort<T> {
|
||||||
/** This is the minimum sized sequence that will be merged. Shorter sequences will be lengthened by calling binarySort. If the
|
/** This is the minimum sized sequence that will be merged. Shorter sequences will be lengthened by calling binarySort. If the
|
||||||
* entire array is less than this length, no merges will be performed.
|
* entire array is less than this length, no merges will be performed.
|
||||||
|
Loading…
Reference in New Issue
Block a user