From ef0cfe2f2e5a78dda3e0860222adb77c4d7b5d78 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 10 Mar 2017 17:02:23 +0100 Subject: [PATCH] Moved Random utils into their own class --- src/dorkbox/util/collections/IntArray.java | 6 +++--- src/dorkbox/util/collections/IntMap.java | 3 ++- src/dorkbox/util/collections/ObjectIntMap.java | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/dorkbox/util/collections/IntArray.java b/src/dorkbox/util/collections/IntArray.java index edc43e6..6ca4155 100644 --- a/src/dorkbox/util/collections/IntArray.java +++ b/src/dorkbox/util/collections/IntArray.java @@ -21,7 +21,7 @@ package dorkbox.util.collections; 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. If unordered, this class * 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 () { for (int i = this.size - 1; i >= 0; i--) { - int ii = MathUtil.randomInt(i); + int ii = RandomUtil.int_(i); int temp = this.items[i]; this.items[i] = this.items[ii]; this.items[ii] = temp; @@ -311,7 +311,7 @@ public class IntArray { if (this.size == 0) { return 0; } - return this.items[MathUtil.randomInt(0, this.size - 1)]; + return this.items[RandomUtil.int_(0, this.size - 1)]; } public int[] toArray () { diff --git a/src/dorkbox/util/collections/IntMap.java b/src/dorkbox/util/collections/IntMap.java index c358004..3262ebe 100644 --- a/src/dorkbox/util/collections/IntMap.java +++ b/src/dorkbox/util/collections/IntMap.java @@ -23,6 +23,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; 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 * for problematic keys. Null values are allowed. No allocation is done except when growing the table size.
@@ -237,7 +238,7 @@ public class IntMap { int i = 0, pushIterations = this.pushIterations; do { // Replace the key and value for one of the hashes. - switch (MathUtil.randomInt(2)) { + switch (RandomUtil.int_(2)) { case 0: evictedKey = key1; evictedValue = valueTable[index1]; diff --git a/src/dorkbox/util/collections/ObjectIntMap.java b/src/dorkbox/util/collections/ObjectIntMap.java index 778273d..a0a5629 100644 --- a/src/dorkbox/util/collections/ObjectIntMap.java +++ b/src/dorkbox/util/collections/ObjectIntMap.java @@ -17,7 +17,7 @@ package dorkbox.util.collections; 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 * small stash for problematic keys. Null keys are not allowed. No allocation is done except when growing the table size.
@@ -210,7 +210,7 @@ public class ObjectIntMap { int i = 0, pushIterations = this.pushIterations; do { // Replace the key and value for one of the hashes. - switch (MathUtil.randomInt(2)) { + switch (RandomUtil.int_(2)) { case 0: evictedKey = key1; evictedValue = valueTable[index1];