Skip to content

Commit

Permalink
Uninternal functions :)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeypospelov committed Sep 7, 2023
1 parent d7b83a1 commit e87e09a
Show file tree
Hide file tree
Showing 38 changed files with 115 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package kotlinx.collections.immutable.implementations.immutableList

internal abstract class AbstractListIterator<out E>(var index: Int, var size: Int) : ListIterator<E> {
abstract class AbstractListIterator<out E>(var index: Int, var size: Int) : ListIterator<E> {
override fun hasNext(): Boolean {
return index < size
}
Expand All @@ -22,19 +22,19 @@ internal abstract class AbstractListIterator<out E>(var index: Int, var size: In
return index - 1
}

internal fun checkHasNext() {
fun checkHasNext() {
if (!hasNext())
throw NoSuchElementException()
}

internal fun checkHasPrevious() {
fun checkHasPrevious() {
if (!hasPrevious())
throw NoSuchElementException()
}
}


internal class SingleElementListIterator<E>(private val element: E, index: Int): AbstractListIterator<E>(index, 1) {
class SingleElementListIterator<E>(private val element: E, index: Int): AbstractListIterator<E>(index, 1) {
override fun next(): E {
checkHasNext()
index++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package kotlinx.collections.immutable.implementations.immutableList

internal class BufferIterator<out T>(
class BufferIterator<out T>(
private val buffer: Array<T>,
index: Int,
size: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import kotlinx.collections.immutable.mutate
* @param rootShift specifies the height of the trie structure, so that `rootShift = (height - 1) * LOG_MAX_BUFFER_SIZE`;
* elements in the [root] array are indexed with bits of the index starting from `rootShift` and until `rootShift + LOG_MAX_BUFFER_SIZE`.
*/
internal class PersistentVector<E>(private val root: Array<Any?>,
class PersistentVector<E>(private val root: Array<Any?>,
private val tail: Array<Any?>,
override val size: Int,
private val rootShift: Int) : PersistentList<E>, AbstractPersistentList<E>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.collections.immutable.internal.MutabilityOwnership
import kotlinx.collections.immutable.internal.assert
import kotlinx.collections.immutable.internal.modCount

internal class PersistentVectorBuilder<E>(private var vector: PersistentList<E>,
class PersistentVectorBuilder<E>(private var vector: PersistentList<E>,
private var vectorRoot: Array<Any?>?,
private var vectorTail: Array<Any?>,
internal var rootShift: Int) : AbstractMutableList<E>(), PersistentList.Builder<E> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package kotlinx.collections.immutable.implementations.immutableList

internal class PersistentVectorIterator<out T>(root: Array<Any?>,
class PersistentVectorIterator<out T>(root: Array<Any?>,
private val tail: Array<T>,
index: Int,
size: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package kotlinx.collections.immutable.implementations.immutableList
* [TrieIterator] is responsible for iterating over elements located at root,
* whereas tail elements are iterated directly from this class.
*/
internal class PersistentVectorMutableIterator<T>(
class PersistentVectorMutableIterator<T>(
private val builder: PersistentVectorBuilder<T>,
index: Int
) : MutableListIterator<T>, AbstractListIterator<T>(index, builder.size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.collections.immutable.internal.ListImplementation.checkPositionIn
import kotlinx.collections.immutable.internal.assert
import kotlinx.collections.immutable.mutate

internal class SmallPersistentVector<E>(private val buffer: Array<Any?>) : ImmutableList<E>, AbstractPersistentList<E>() {
class SmallPersistentVector<E>(private val buffer: Array<Any?>) : ImmutableList<E>, AbstractPersistentList<E>() {

init {
assert(buffer.size <= MAX_BUFFER_SIZE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package kotlinx.collections.immutable.implementations.immutableList

internal class TrieIterator<out E>(root: Array<Any?>,
class TrieIterator<out E>(root: Array<Any?>,
index: Int,
size: Int,
private var height: Int) : AbstractListIterator<E>(index, size) {
Expand All @@ -17,7 +17,7 @@ internal class TrieIterator<out E>(root: Array<Any?>,
fillPath(index - if (isInRightEdge) 1 else 0, 1)
}

internal fun reset(root: Array<Any?>, index: Int, size: Int, height: Int) {
fun reset(root: Array<Any?>, index: Int, size: Int, height: Int) {
this.index = index
this.size = size
this.height = height
Expand Down
4 changes: 2 additions & 2 deletions core/commonMain/src/implementations/immutableList/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ internal const val LOG_MAX_BUFFER_SIZE = 5
internal const val MAX_BUFFER_SIZE_MINUS_ONE = MAX_BUFFER_SIZE - 1
internal const val MUTABLE_BUFFER_SIZE = MAX_BUFFER_SIZE + 1

internal class ObjectRef(var value: Any?)
class ObjectRef(var value: Any?)

internal fun <E> persistentVectorOf(): PersistentList<E> {
fun <E> persistentVectorOf(): PersistentList<E> {
return SmallPersistentVector.EMPTY
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.collections.immutable.implementations.persistentOrderedMap.Persis
import kotlinx.collections.immutable.implementations.persistentOrderedMap.PersistentOrderedMapBuilder
import kotlinx.collections.immutable.mutate

internal class PersistentHashMap<K, V>(internal val node: TrieNode<K, V>,
class PersistentHashMap<K, V>(val node: TrieNode<K, V>,
override val size: Int): AbstractMap<K, V>(), PersistentMap<K, V> {

override val keys: ImmutableSet<K>
Expand All @@ -34,9 +34,7 @@ internal class PersistentHashMap<K, V>(internal val node: TrieNode<K, V>,
return PersistentHashMapEntries(this)
}

// TODO: compiler bug: this bridge should be generated automatically
@PublishedApi
internal fun getEntries(): Set<Map.Entry<K, V>> {
fun getEntries(): Set<Map.Entry<K, V>> {
return createEntries()
}

Expand Down Expand Up @@ -111,9 +109,9 @@ internal class PersistentHashMap<K, V>(internal val node: TrieNode<K, V>,
*/
override fun hashCode(): Int = super<AbstractMap>.hashCode()

internal companion object {
companion object {
private val EMPTY = PersistentHashMap(TrieNode.EMPTY, 0)
@Suppress("UNCHECKED_CAST")
internal fun <K, V> emptyOf(): PersistentHashMap<K, V> = EMPTY as PersistentHashMap<K, V>
fun <K, V> emptyOf(): PersistentHashMap<K, V> = EMPTY as PersistentHashMap<K, V>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.collections.immutable.internal.DeltaCounter
import kotlinx.collections.immutable.internal.MapImplementation
import kotlinx.collections.immutable.internal.MutabilityOwnership

internal class PersistentHashMapBuilder<K, V>(private var map: PersistentHashMap<K, V>) : PersistentMap.Builder<K, V>, AbstractMutableMap<K, V>() {
class PersistentHashMapBuilder<K, V>(private var map: PersistentHashMap<K, V>) : PersistentMap.Builder<K, V>, AbstractMutableMap<K, V>() {
internal var ownership = MutabilityOwnership()
private set
internal var node = map.node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package kotlinx.collections.immutable.implementations.immutableMap
import kotlinx.collections.immutable.internal.assert


internal class TrieNodeMutableEntriesIterator<K, V>(
class TrieNodeMutableEntriesIterator<K, V>(
private val parentIterator: PersistentHashMapBuilderEntriesIterator<K, V>
) : TrieNodeBaseIterator<K, V, MutableMap.MutableEntry<K, V>>() {

Expand All @@ -35,7 +35,7 @@ private class MutableMapEntry<K, V>(
}


internal open class PersistentHashMapBuilderBaseIterator<K, V, T>(
open class PersistentHashMapBuilderBaseIterator<K, V, T>(
private val builder: PersistentHashMapBuilder<K, V>,
path: Array<TrieNodeBaseIterator<K, V, T>>
) : MutableIterator<T>, PersistentHashMapBaseIterator<K, V, T>(builder.node, path) {
Expand Down Expand Up @@ -125,7 +125,7 @@ internal open class PersistentHashMapBuilderBaseIterator<K, V, T>(
}
}

internal class PersistentHashMapBuilderEntriesIterator<K, V>(
class PersistentHashMapBuilderEntriesIterator<K, V>(
builder: PersistentHashMapBuilder<K, V>
) : MutableIterator<MutableMap.MutableEntry<K, V>> {
private val base = PersistentHashMapBuilderBaseIterator<K, V, MutableMap.MutableEntry<K, V>>(
Expand All @@ -140,8 +140,8 @@ internal class PersistentHashMapBuilderEntriesIterator<K, V>(
fun setValue(key: K, newValue: V): Unit = base.setValue(key, newValue)
}

internal class PersistentHashMapBuilderKeysIterator<K, V>(builder: PersistentHashMapBuilder<K, V>)
class PersistentHashMapBuilderKeysIterator<K, V>(builder: PersistentHashMapBuilder<K, V>)
: PersistentHashMapBuilderBaseIterator<K, V, K>(builder, Array(TRIE_MAX_HEIGHT + 1) { TrieNodeKeysIterator<K, V>() })

internal class PersistentHashMapBuilderValuesIterator<K, V>(builder: PersistentHashMapBuilder<K, V>)
class PersistentHashMapBuilderValuesIterator<K, V>(builder: PersistentHashMapBuilder<K, V>)
: PersistentHashMapBuilderBaseIterator<K, V, V>(builder, Array(TRIE_MAX_HEIGHT + 1) { TrieNodeValuesIterator<K, V>() })
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package kotlinx.collections.immutable.implementations.immutableMap
import kotlinx.collections.immutable.internal.MapImplementation

// intermediate abstract class to workaround KT-43321
internal abstract class AbstractMapBuilderEntries<E : Map.Entry<K, V>, K, V> : AbstractMutableSet<E>() {
abstract class AbstractMapBuilderEntries<E : Map.Entry<K, V>, K, V> : AbstractMutableSet<E>() {
final override fun contains(element: E): Boolean {
// TODO: Eliminate this check after KT-30016 gets fixed.
@Suppress("USELESS_CAST")
Expand All @@ -26,7 +26,7 @@ internal abstract class AbstractMapBuilderEntries<E : Map.Entry<K, V>, K, V> : A
abstract fun removeEntry(element: Map.Entry<K, V>): Boolean
}

internal class PersistentHashMapBuilderEntries<K, V>(private val builder: PersistentHashMapBuilder<K, V>)
class PersistentHashMapBuilderEntries<K, V>(private val builder: PersistentHashMapBuilder<K, V>)
: AbstractMapBuilderEntries<MutableMap.MutableEntry<K, V>, K, V>() {
override fun add(element: MutableMap.MutableEntry<K, V>): Boolean {
throw UnsupportedOperationException()
Expand All @@ -52,7 +52,7 @@ internal class PersistentHashMapBuilderEntries<K, V>(private val builder: Persis
}
}

internal class PersistentHashMapBuilderKeys<K, V>(private val builder: PersistentHashMapBuilder<K, V>) : MutableSet<K>, AbstractMutableSet<K>() {
class PersistentHashMapBuilderKeys<K, V>(private val builder: PersistentHashMapBuilder<K, V>) : MutableSet<K>, AbstractMutableSet<K>() {
override fun add(element: K): Boolean {
throw UnsupportedOperationException()
}
Expand Down Expand Up @@ -81,7 +81,7 @@ internal class PersistentHashMapBuilderKeys<K, V>(private val builder: Persisten
}
}

internal class PersistentHashMapBuilderValues<K, V>(private val builder: PersistentHashMapBuilder<K, V>) : MutableCollection<V>, AbstractMutableCollection<V>() {
class PersistentHashMapBuilderValues<K, V>(private val builder: PersistentHashMapBuilder<K, V>) : MutableCollection<V>, AbstractMutableCollection<V>() {
override val size: Int
get() = builder.size

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlin.js.JsName

internal const val TRIE_MAX_HEIGHT = 7

internal abstract class TrieNodeBaseIterator<out K, out V, out T> : Iterator<T> {
abstract class TrieNodeBaseIterator<out K, out V, out T> : Iterator<T> {
protected var buffer = TrieNode.EMPTY.buffer
private set
private var dataSize = 0
Expand Down Expand Up @@ -62,7 +62,7 @@ internal abstract class TrieNodeBaseIterator<out K, out V, out T> : Iterator<T>
}
}

internal class TrieNodeKeysIterator<out K, out V> : TrieNodeBaseIterator<K, V, K>() {
class TrieNodeKeysIterator<out K, out V> : TrieNodeBaseIterator<K, V, K>() {
override fun next(): K {
assert(hasNextKey())
index += 2
Expand All @@ -71,7 +71,7 @@ internal class TrieNodeKeysIterator<out K, out V> : TrieNodeBaseIterator<K, V, K
}
}

internal class TrieNodeValuesIterator<out K, out V> : TrieNodeBaseIterator<K, V, V>() {
class TrieNodeValuesIterator<out K, out V> : TrieNodeBaseIterator<K, V, V>() {
override fun next(): V {
assert(hasNextKey())
index += 2
Expand All @@ -80,7 +80,7 @@ internal class TrieNodeValuesIterator<out K, out V> : TrieNodeBaseIterator<K, V,
}
}

internal class TrieNodeEntriesIterator<out K, out V> : TrieNodeBaseIterator<K, V, Map.Entry<K, V>>() {
class TrieNodeEntriesIterator<out K, out V> : TrieNodeBaseIterator<K, V, Map.Entry<K, V>>() {
override fun next(): Map.Entry<K, V> {
assert(hasNextKey())
index += 2
Expand All @@ -89,7 +89,7 @@ internal class TrieNodeEntriesIterator<out K, out V> : TrieNodeBaseIterator<K, V
}
}

internal open class MapEntry<out K, out V>(override val key: K, override val value: V) : Map.Entry<K, V> {
open class MapEntry<out K, out V>(override val key: K, override val value: V) : Map.Entry<K, V> {
override fun hashCode(): Int = key.hashCode() xor value.hashCode()
override fun equals(other: Any?): Boolean =
(other as? Map.Entry<*, *>)?.let { it.key == key && it.value == value } ?: false
Expand All @@ -98,7 +98,7 @@ internal open class MapEntry<out K, out V>(override val key: K, override val val
}


internal abstract class PersistentHashMapBaseIterator<K, V, T>(
abstract class PersistentHashMapBaseIterator<K, V, T>(
node: TrieNode<K, V>,
protected val path: Array<TrieNodeBaseIterator<K, V, T>>
) : Iterator<T> {
Expand Down Expand Up @@ -174,11 +174,11 @@ internal abstract class PersistentHashMapBaseIterator<K, V, T>(
}
}

internal class PersistentHashMapEntriesIterator<K, V>(node: TrieNode<K, V>)
class PersistentHashMapEntriesIterator<K, V>(node: TrieNode<K, V>)
: PersistentHashMapBaseIterator<K, V, Map.Entry<K, V>>(node, Array(TRIE_MAX_HEIGHT + 1) { TrieNodeEntriesIterator<K, V>() })

internal class PersistentHashMapKeysIterator<K, V>(node: TrieNode<K, V>)
class PersistentHashMapKeysIterator<K, V>(node: TrieNode<K, V>)
: PersistentHashMapBaseIterator<K, V, K>(node, Array(TRIE_MAX_HEIGHT + 1) { TrieNodeKeysIterator<K, V>() })

internal class PersistentHashMapValuesIterator<K, V>(node: TrieNode<K, V>)
class PersistentHashMapValuesIterator<K, V>(node: TrieNode<K, V>)
: PersistentHashMapBaseIterator<K, V, V>(node, Array(TRIE_MAX_HEIGHT + 1) { TrieNodeValuesIterator<K, V>() })
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.collections.immutable.ImmutableCollection
import kotlinx.collections.immutable.ImmutableSet
import kotlinx.collections.immutable.internal.MapImplementation

internal class PersistentHashMapEntries<K, V>(private val map: PersistentHashMap<K, V>) : ImmutableSet<Map.Entry<K, V>>, AbstractSet<Map.Entry<K, V>>() {
class PersistentHashMapEntries<K, V>(private val map: PersistentHashMap<K, V>) : ImmutableSet<Map.Entry<K, V>>, AbstractSet<Map.Entry<K, V>>() {
override val size: Int get() = map.size

override fun contains(element: Map.Entry<K, V>): Boolean {
Expand All @@ -21,7 +21,7 @@ internal class PersistentHashMapEntries<K, V>(private val map: PersistentHashMap
}
}

internal class PersistentHashMapKeys<K, V>(private val map: PersistentHashMap<K, V>) : ImmutableSet<K>, AbstractSet<K>() {
class PersistentHashMapKeys<K, V>(private val map: PersistentHashMap<K, V>) : ImmutableSet<K>, AbstractSet<K>() {
override val size: Int
get() = map.size

Expand All @@ -34,7 +34,7 @@ internal class PersistentHashMapKeys<K, V>(private val map: PersistentHashMap<K,
}
}

internal class PersistentHashMapValues<K, V>(private val map: PersistentHashMap<K, V>) : ImmutableCollection<V>, AbstractCollection<V>() {
class PersistentHashMapValues<K, V>(private val map: PersistentHashMap<K, V>) : ImmutableCollection<V>, AbstractCollection<V>() {
override val size: Int
get() = map.size

Expand Down
Loading

0 comments on commit e87e09a

Please sign in to comment.