Temporary make SmartSet less smart
SmartSet is compiled both with bootstrap and new compiler, so it can't implement both old and new Set interfaces (with 'size' as function and as property). This commit should be reverted after bootstraping
This commit is contained in:
@@ -25,22 +25,22 @@ import java.util.*
|
||||
* Also, [iterator] returns an iterator which does not support [MutableIterator.remove].
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
class SmartSet<T> private constructor() : AbstractSet<T>() {
|
||||
class SmartSet<T> private constructor() /* : AbstractSet<T>() */ {
|
||||
companion object {
|
||||
private val ARRAY_THRESHOLD = 5
|
||||
|
||||
@JvmStatic
|
||||
fun create<T>() = SmartSet<T>()
|
||||
fun create<T>(): MutableSet<T> = LinkedHashSet()
|
||||
|
||||
@JvmStatic
|
||||
fun create<T>(set: Set<T>) = SmartSet<T>().apply { this.addAll(set) }
|
||||
fun create<T>(set: Set<T>): MutableSet<T> = LinkedHashSet(set)
|
||||
}
|
||||
|
||||
// null if size = 0, object if size = 1, array of objects if size < threshold, linked hash set otherwise
|
||||
private var data: Any? = null
|
||||
|
||||
private var size: Int = 0
|
||||
|
||||
/*
|
||||
override fun iterator(): MutableIterator<T> = when {
|
||||
size == 0 -> Collections.emptySet<T>().iterator()
|
||||
size == 1 -> SingletonIterator(data as T)
|
||||
@@ -86,7 +86,7 @@ class SmartSet<T> private constructor() : AbstractSet<T>() {
|
||||
size < ARRAY_THRESHOLD -> o in data as Array<T>
|
||||
else -> o in data as Set<T>
|
||||
}
|
||||
|
||||
*/
|
||||
private class SingletonIterator<T>(private val element: T) : MutableIterator<T> {
|
||||
private var hasNext = true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user