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:
Denis Zharkov
2015-10-02 19:49:14 +03:00
parent 61416b3d14
commit e52e6cf869
@@ -25,22 +25,22 @@ import java.util.*
* Also, [iterator] returns an iterator which does not support [MutableIterator.remove]. * Also, [iterator] returns an iterator which does not support [MutableIterator.remove].
*/ */
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
class SmartSet<T> private constructor() : AbstractSet<T>() { class SmartSet<T> private constructor() /* : AbstractSet<T>() */ {
companion object { companion object {
private val ARRAY_THRESHOLD = 5 private val ARRAY_THRESHOLD = 5
@JvmStatic @JvmStatic
fun create<T>() = SmartSet<T>() fun create<T>(): MutableSet<T> = LinkedHashSet()
@JvmStatic @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 // 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 data: Any? = null
private var size: Int = 0 private var size: Int = 0
/*
override fun iterator(): MutableIterator<T> = when { override fun iterator(): MutableIterator<T> = when {
size == 0 -> Collections.emptySet<T>().iterator() size == 0 -> Collections.emptySet<T>().iterator()
size == 1 -> SingletonIterator(data as T) 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> size < ARRAY_THRESHOLD -> o in data as Array<T>
else -> o in data as Set<T> else -> o in data as Set<T>
} }
*/
private class SingletonIterator<T>(private val element: T) : MutableIterator<T> { private class SingletonIterator<T>(private val element: T) : MutableIterator<T> {
private var hasNext = true private var hasNext = true