Added allocateIterators as an instance variable, instead of static.

master
Robinson 2023-11-29 12:05:14 +01:00
parent c8add14601
commit 493b6baa7a
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
15 changed files with 98 additions and 30 deletions

View File

@ -32,10 +32,8 @@
*/
package dorkbox.collections
import dorkbox.collections.Collections.allocateIterators
import dorkbox.collections.Collections.random
import dorkbox.collections.ObjectMap.Companion.dummy
import java.lang.IllegalStateException
import java.util.*
import kotlin.math.max
import kotlin.math.min
@ -54,6 +52,14 @@ class ArrayMap<K: Any, V> : MutableMap<K, V?>{
const val version = Collections.version
}
/**
* When true, [Iterable.iterator] will allocate a new iterator for each invocation.
*
* When false, the iterator is reused and nested use will throw an exception. Default is
* false.
*/
var allocateIterators = false
var keyTable: Array<K?>
var valueTable: Array<V?>
var size_ = 0

View File

@ -46,13 +46,4 @@ object Collections {
fun nextPowerOfTwo(value: Int): Int {
return 1 shl 32 - Integer.numberOfLeadingZeros(value - 1)
}
/**
* When true, [Iterable.iterator] for [ObjectMap], and other collections will allocate a new
* iterator for each invocation.
*
* When false, the iterator is reused and nested use will throw an exception. Default is
* false.
*/
var allocateIterators = false
}

View File

@ -32,7 +32,6 @@
*/
package dorkbox.collections
import dorkbox.collections.Collections.allocateIterators
import dorkbox.collections.Collections.random
import dorkbox.collections.Predicate.PredicateIterable
import java.util.*
@ -46,6 +45,14 @@ import kotlin.math.min
* @author Nathan Sweet
*/
class ExpandingArray<T> : MutableIterable<T> {
/**
* When true, [Iterable.iterator] will allocate a new iterator for each invocation.
*
* When false, the iterator is reused and nested use will throw an exception. Default is
* false.
*/
var allocateIterators = false
/**
* Provides direct access to the underlying array. If the Array's generic type is not Object, this field may only be accessed
* if the [ExpandingArray.Array] constructor was used.
@ -813,7 +820,7 @@ class ExpandingArray<T> : MutableIterable<T> {
* @see Collections.allocateIterators
*/
override fun iterator(): ArrayIterator<T> {
if (allocateIterators) return ArrayIterator(array, allowRemove)
if (array.allocateIterators) return ArrayIterator(array, allowRemove)
// lastAcquire.getBuffer().setLength(0);
// new Throwable().printStackTrace(new java.io.PrintWriter(lastAcquire));

View File

@ -32,7 +32,6 @@
*/
package dorkbox.collections
import dorkbox.collections.Collections.allocateIterators
import dorkbox.collections.ObjectSet.Companion.tableSize
import java.util.*
@ -59,6 +58,14 @@ class IntFloatMap : MutableMap<Int, Float> {
const val version = Collections.version
}
/**
* When true, [Iterable.iterator] will allocate a new iterator for each invocation.
*
* When false, the iterator is reused and nested use will throw an exception. Default is
* false.
*/
var allocateIterators = false
private var size_ = 0
var keyTable: IntArray
var valueTable: FloatArray

View File

@ -32,7 +32,6 @@
*/
package dorkbox.collections
import dorkbox.collections.Collections.allocateIterators
import dorkbox.collections.ObjectSet.Companion.tableSize
import java.util.*
@ -59,6 +58,14 @@ class IntIntMap : MutableMap<Int, Int> {
const val version = Collections.version
}
/**
* When true, [Iterable.iterator] will allocate a new iterator for each invocation.
*
* When false, the iterator is reused and nested use will throw an exception. Default is
* false.
*/
var allocateIterators = false
private var size_ = 0
var keyTable: IntArray
var valueTable: IntArray

View File

@ -32,7 +32,6 @@
*/
package dorkbox.collections
import dorkbox.collections.Collections.allocateIterators
import dorkbox.collections.ObjectSet.Companion.tableSize
import java.util.*
@ -60,6 +59,14 @@ open class IntMap<V> : MutableMap<Int, V> {
const val version = Collections.version
}
/**
* When true, [Iterable.iterator] will allocate a new iterator for each invocation.
*
* When false, the iterator is reused and nested use will throw an exception. Default is
* false.
*/
var allocateIterators = false
private var size_ = 0
var keyTable: IntArray
var valueTable: Array<V?>

View File

@ -32,7 +32,6 @@
*/
package dorkbox.collections
import dorkbox.collections.Collections.allocateIterators
import dorkbox.collections.ObjectSet.Companion.tableSize
import java.util.*
@ -66,6 +65,14 @@ class IntSet: MutableSet<Int> {
}
}
/**
* When true, [Iterable.iterator] will allocate a new iterator for each invocation.
*
* When false, the iterator is reused and nested use will throw an exception. Default is
* false.
*/
var allocateIterators = false
private var size_ = 0
var keyTable: IntArray
var hasZeroValue = false

View File

@ -32,7 +32,6 @@
*/
package dorkbox.collections
import dorkbox.collections.Collections.allocateIterators
import dorkbox.collections.ObjectSet.Companion.tableSize
import java.util.*
@ -59,6 +58,14 @@ class LongMap<V> : MutableMap<Long, V?> {
const val version = Collections.version
}
/**
* When true, [Iterable.iterator] will allocate a new iterator for each invocation.
*
* When false, the iterator is reused and nested use will throw an exception. Default is
* false.
*/
var allocateIterators = false
private var size_ = 0
var keyTable: LongArray
var valueTable: Array<V?>

View File

@ -32,7 +32,6 @@
*/
package dorkbox.collections
import dorkbox.collections.Collections.allocateIterators
import dorkbox.collections.ObjectSet.Companion.tableSize
import java.util.*
@ -66,6 +65,14 @@ class LongSet: MutableSet<Long> {
}
}
/**
* When true, [Iterable.iterator] will allocate a new iterator for each invocation.
*
* When false, the iterator is reused and nested use will throw an exception. Default is
* false.
*/
var allocateIterators = false
private var size_ = 0
var keyTable: LongArray
var hasZeroValue = false

View File

@ -34,9 +34,7 @@
package dorkbox.collections
import dorkbox.collections.Collections.allocateIterators
import dorkbox.collections.ObjectSet.Companion.tableSize
import java.lang.IllegalStateException
import java.util.*
/**
@ -68,6 +66,14 @@ open class ObjectFloatMap<K: Any> : MutableMap<K, Float> {
internal val dummy = Any()
}
/**
* When true, [Iterable.iterator] will allocate a new iterator for each invocation.
*
* When false, the iterator is reused and nested use will throw an exception. Default is
* false.
*/
var allocateIterators = false
protected var mapSize = 0
var keyTable: Array<K?>

View File

@ -34,7 +34,6 @@
package dorkbox.collections
import dorkbox.collections.Collections.allocateIterators
import dorkbox.collections.ObjectSet.Companion.tableSize
import java.util.*
@ -64,6 +63,14 @@ open class ObjectIntMap<K: Any> : MutableMap<K, Int> {
const val version = Collections.version
}
/**
* When true, [Iterable.iterator] will allocate a new iterator for each invocation.
*
* When false, the iterator is reused and nested use will throw an exception. Default is
* false.
*/
var allocateIterators = false
protected var mapSize = 0
var keyTable: Array<K?>

View File

@ -34,9 +34,7 @@
package dorkbox.collections
import dorkbox.collections.Collections.allocateIterators
import dorkbox.collections.ObjectSet.Companion.tableSize
import java.lang.IllegalStateException
import java.util.*
/**
@ -68,6 +66,14 @@ open class ObjectMap<K: Any, V> : MutableMap<K, V?> {
internal val dummy = Any()
}
/**
* When true, [Iterable.iterator] will allocate a new iterator for each invocation.
*
* When false, the iterator is reused and nested use will throw an exception. Default is
* false.
*/
var allocateIterators = false
protected var mapSize = 0
var keyTable: Array<K?>

View File

@ -79,6 +79,14 @@ open class ObjectSet<T: Any> : MutableSet<T> {
}
}
/**
* When true, [Iterable.iterator] will allocate a new iterator for each invocation.
*
* When false, the iterator is reused and nested use will throw an exception. Default is
* false.
*/
var allocateIterators = false
override var size = 0
var keyTable: Array<T?>
@ -466,7 +474,7 @@ open class ObjectSet<T: Any> : MutableSet<T> {
* Use the [ObjectSetIterator] constructor for nested or multithreaded iteration.
*/
override fun iterator(): ObjectSetIterator<T> {
if (Collections.allocateIterators) return ObjectSetIterator(this)
if (allocateIterators) return ObjectSetIterator(this)
if (iterator1 == null) {
iterator1 = ObjectSetIterator(this)
iterator2 = ObjectSetIterator(this)

View File

@ -32,10 +32,6 @@
*/
package dorkbox.collections
import dorkbox.collections.Collections.allocateIterators
/**
* An [ObjectMap] that also stores keys in an [ArrayList] using the insertion order. Null keys are not allowed. No
* allocation is done except when growing the table size.

View File

@ -32,7 +32,6 @@
*/
package dorkbox.collections
import dorkbox.collections.Collections.allocateIterators
import java.util.Comparator
/**