diff --git a/src/dorkbox/collections/IntIntMap.kt b/src/dorkbox/collections/IntIntMap.kt index 10d654b..3c2dc17 100644 --- a/src/dorkbox/collections/IntIntMap.kt +++ b/src/dorkbox/collections/IntIntMap.kt @@ -971,14 +971,19 @@ class IntIntMap : MutableMap, MutableIterable { /** * Returns a new array containing the remaining keys. */ - fun toArray(): Array { - return Array(map.size_) { next() } + fun toArray(): IntArray { + val array = IntArray(map.size) + var index = 0 + while (hasNext()) { + array[index++] = next() + } + return array } /** * Adds the remaining values to the specified array. */ - fun toArray(array: Array): Array { + fun toArray(array: IntArray): IntArray { var index = 0 while (hasNext) { array[index++] = next() diff --git a/src/dorkbox/collections/IntMap.kt b/src/dorkbox/collections/IntMap.kt index 487285e..29dd1f2 100644 --- a/src/dorkbox/collections/IntMap.kt +++ b/src/dorkbox/collections/IntMap.kt @@ -264,11 +264,11 @@ class IntMap : MutableMap, MutableIterable> { val mask = mask var next = (i + 1) and mask - var key: Int - while (keyTable[next].also { key = it } != 0) { - val placement = place(key) + var k: Int + while (keyTable[next].also { k = it } != 0) { + val placement = place(k) if ((next - placement and mask) > (i - placement and mask)) { - keyTable[i] = key + keyTable[i] = k valueTable[i] = valueTable[next] i = next } @@ -327,6 +327,7 @@ class IntMap : MutableMap, MutableIterable> { resize(tableSize) } + @Suppress("UNCHECKED_CAST") override val entries: MutableSet> get() = entries() as MutableSet> override val keys: MutableSet @@ -882,7 +883,7 @@ class IntMap : MutableMap, MutableIterable> { override fun retainAll(elements: Collection): Boolean { var removed = false map.keyTable.forEach { key -> - if (key != null) { + if (key != 0) { val value = map[key] if (!elements.contains(value)) { map.remove(key) @@ -1012,14 +1013,19 @@ class IntMap : MutableMap, MutableIterable> { /** * Returns a new array containing the remaining keys. */ - fun toArray(): Array { - return Array(map.size_) { next() } + fun toArray(): IntArray { + val array = IntArray(map.size) + var index = 0 + while (hasNext()) { + array[index++] = next() + } + return array } /** * Adds the remaining values to the specified array. */ - fun toArray(array: Array): Array { + fun toArray(array: IntArray): IntArray { var index = 0 while (hasNext) { array[index++] = next() diff --git a/src/dorkbox/collections/IntSet.kt b/src/dorkbox/collections/IntSet.kt index 921a68d..82fcab9 100644 --- a/src/dorkbox/collections/IntSet.kt +++ b/src/dorkbox/collections/IntSet.kt @@ -552,8 +552,24 @@ class IntSet: MutableSet { } /** Returns a new array containing the remaining keys. */ - fun toArray(): Array { - return Array(set.size_) { next() } + fun toArray(): IntArray { + val array = IntArray(set.size) + var index = 0 + while (hasNext()) { + array[index++] = next() + } + return array + } + + /** + * Adds the remaining values to the specified array. + */ + fun toArray(array: IntArray): IntArray { + var index = 0 + while (hasNext) { + array[index++] = next() + } + return array } companion object {