Moved Random utils into their own class
This commit is contained in:
parent
36f6000b42
commit
ef0cfe2f2e
|
@ -21,7 +21,7 @@ package dorkbox.util.collections;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import dorkbox.util.MathUtil;
|
import dorkbox.util.RandomUtil;
|
||||||
|
|
||||||
/** A resizable, ordered or unordered int array. Avoids the boxing that occurs with ArrayList<Integer>. If unordered, this class
|
/** A resizable, ordered or unordered int array. Avoids the boxing that occurs with ArrayList<Integer>. If unordered, this class
|
||||||
* avoids a memory copy when removing elements (the last element is moved to the removed element's position).
|
* avoids a memory copy when removing elements (the last element is moved to the removed element's position).
|
||||||
|
@ -291,7 +291,7 @@ public class IntArray {
|
||||||
|
|
||||||
public void shuffle () {
|
public void shuffle () {
|
||||||
for (int i = this.size - 1; i >= 0; i--) {
|
for (int i = this.size - 1; i >= 0; i--) {
|
||||||
int ii = MathUtil.randomInt(i);
|
int ii = RandomUtil.int_(i);
|
||||||
int temp = this.items[i];
|
int temp = this.items[i];
|
||||||
this.items[i] = this.items[ii];
|
this.items[i] = this.items[ii];
|
||||||
this.items[ii] = temp;
|
this.items[ii] = temp;
|
||||||
|
@ -311,7 +311,7 @@ public class IntArray {
|
||||||
if (this.size == 0) {
|
if (this.size == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return this.items[MathUtil.randomInt(0, this.size - 1)];
|
return this.items[RandomUtil.int_(0, this.size - 1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] toArray () {
|
public int[] toArray () {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import dorkbox.util.MathUtil;
|
import dorkbox.util.MathUtil;
|
||||||
|
import dorkbox.util.RandomUtil;
|
||||||
|
|
||||||
/** An unordered map that uses int keys. This implementation is a cuckoo hash map using 3 hashes, random walking, and a small stash
|
/** An unordered map that uses int keys. This implementation is a cuckoo hash map using 3 hashes, random walking, and a small stash
|
||||||
* for problematic keys. Null values are allowed. No allocation is done except when growing the table size. <br>
|
* for problematic keys. Null values are allowed. No allocation is done except when growing the table size. <br>
|
||||||
|
@ -237,7 +238,7 @@ public class IntMap<V> {
|
||||||
int i = 0, pushIterations = this.pushIterations;
|
int i = 0, pushIterations = this.pushIterations;
|
||||||
do {
|
do {
|
||||||
// Replace the key and value for one of the hashes.
|
// Replace the key and value for one of the hashes.
|
||||||
switch (MathUtil.randomInt(2)) {
|
switch (RandomUtil.int_(2)) {
|
||||||
case 0:
|
case 0:
|
||||||
evictedKey = key1;
|
evictedKey = key1;
|
||||||
evictedValue = valueTable[index1];
|
evictedValue = valueTable[index1];
|
||||||
|
|
|
@ -17,7 +17,7 @@ package dorkbox.util.collections;
|
||||||
|
|
||||||
import com.esotericsoftware.kryo.util.ObjectMap;
|
import com.esotericsoftware.kryo.util.ObjectMap;
|
||||||
|
|
||||||
import dorkbox.util.MathUtil;
|
import dorkbox.util.RandomUtil;
|
||||||
|
|
||||||
/** An unordered map where the values are ints. This implementation is a cuckoo hash map using 3 hashes, random walking, and a
|
/** An unordered map where the values are ints. This implementation is a cuckoo hash map using 3 hashes, random walking, and a
|
||||||
* small stash for problematic keys. Null keys are not allowed. No allocation is done except when growing the table size. <br>
|
* small stash for problematic keys. Null keys are not allowed. No allocation is done except when growing the table size. <br>
|
||||||
|
@ -210,7 +210,7 @@ public class ObjectIntMap<K> {
|
||||||
int i = 0, pushIterations = this.pushIterations;
|
int i = 0, pushIterations = this.pushIterations;
|
||||||
do {
|
do {
|
||||||
// Replace the key and value for one of the hashes.
|
// Replace the key and value for one of the hashes.
|
||||||
switch (MathUtil.randomInt(2)) {
|
switch (RandomUtil.int_(2)) {
|
||||||
case 0:
|
case 0:
|
||||||
evictedKey = key1;
|
evictedKey = key1;
|
||||||
evictedValue = valueTable[index1];
|
evictedValue = valueTable[index1];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user