Package-level declarations

A set of collection libraries suited for small data sets which are also optimized for Android, usually by sacrificing performance for efficiency in memory.

Types

Link copied to clipboard
open class ArrayMap<K, V> : SimpleArrayMap<K, V> , Map<K, V>
ArrayMap is a generic key->value mapping data structure that is designed to be more memory efficient than a traditional java.util.HashMap, this implementation is a version of the platform's android.util.ArrayMap that can be used on older versions of the platform.
Link copied to clipboard
class ArraySet<E> constructor(capacity: Int = 0) : MutableSet<E>

ArraySet is a generic set data structure that is designed to be more memory efficient than a traditional HashSet. The design is very similar to ArrayMap, with all of the caveats described there. This implementation is separate from ArrayMap, however, so the Object array contains only one item for each entry in the set (instead of a pair for a mapping).

Link copied to clipboard
class CircularArray<E> constructor(minCapacity: Int = 8)

CircularArray is a generic circular array data structure that provides O(1) random read, O(1) prepend and O(1) append. The CircularArray automatically grows its capacity when number of added items is over its capacity.

Link copied to clipboard
class CircularIntArray constructor(minCapacity: Int = 8)

CircularIntArray is a circular integer array data structure that provides O(1) random read, O(1) prepend and O(1) append. The CircularIntArray automatically grows its capacity when number of added integers is over its capacity.

Link copied to clipboard
expect open class LongSparseArray<E> constructor(initialCapacity: Int = 10)

SparseArray mapping longs to Objects. Unlike a normal array of Objects, there can be gaps in the indices. It is intended to be more memory efficient than using a HashMap to map Longs to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping.

actual open class LongSparseArray<E> @JvmOverloads constructor(initialCapacity: Int = 10) : Cloneable

SparseArray mapping longs to Objects. Unlike a normal array of Objects, there can be gaps in the indices. It is intended to be more memory efficient than using a HashMap to map Longs to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping.

actual open class LongSparseArray<E> constructor(initialCapacity: Int)

SparseArray mapping longs to Objects. Unlike a normal array of Objects, there can be gaps in the indices. It is intended to be more memory efficient than using a HashMap to map Longs to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping.

Link copied to clipboard
open class LruCache<K : Any, V : Any>(maxSize: Int)

Static library version of android.util.LruCache. Used to write apps that run on API levels prior to 12. When running on API level 12 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.

Link copied to clipboard
open class SimpleArrayMap<K, V> constructor(capacity: Int = 0)

Base implementation of androidx.collection.ArrayMap that doesn't include any standard Java container API interoperability. These features are generally heavier-weight ways to interact with the container, so discouraged, but they can be useful to make it easier to use as a drop-in replacement for HashMap. If you don't need them, this class can be preferable since it doesn't bring in any of the implementation of those APIs, allowing that code to be stripped by ProGuard.

Link copied to clipboard
expect open class SparseArrayCompat<E> constructor(initialCapacity: Int = 10)

SparseArrays map integers to Objects. Unlike a normal array of Objects, there can be gaps in the indices. It is intended to be more memory efficient than using a HashMap to map Integers to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping.

actual open class SparseArrayCompat<E> @JvmOverloads constructor(initialCapacity: Int = 10) : Cloneable

SparseArrays map integers to Objects. Unlike a normal array of Objects, there can be gaps in the indices. It is intended to be more memory efficient than using a HashMap to map Integers to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping.

actual open class SparseArrayCompat<E> constructor(initialCapacity: Int)

SparseArrays map integers to Objects. Unlike a normal array of Objects, there can be gaps in the indices. It is intended to be more memory efficient than using a HashMap to map Integers to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping.

Functions

Link copied to clipboard
inline fun <K, V> arrayMapOf(): ArrayMap<K, V>

Returns an empty new ArrayMap.

fun <K, V> arrayMapOf(vararg pairs: Pair<K, V>): ArrayMap<K, V>

Returns a new ArrayMap with the specified contents, given as a list of pairs where the first component is the key and the second component is the value.

Link copied to clipboard
inline fun <T> arraySetOf(): ArraySet<T>

Returns an empty new ArraySet.

fun <T> arraySetOf(vararg values: T): ArraySet<T>

Returns a new ArraySet with the specified contents.

Link copied to clipboard
inline operator fun <T> LongSparseArray<T>.contains(key: Long): Boolean
inline operator fun <T> SparseArrayCompat<T>.contains(key: Int): Boolean

Returns true if the collection contains key.

Link copied to clipboard
inline fun <T> LongSparseArray<T>.forEach(action: (key: Long, value: T) -> Unit)
inline fun <T> SparseArrayCompat<T>.forEach(action: (key: Int, value: T) -> Unit)

Performs the given action for each key/value entry.

Link copied to clipboard
inline fun <T> LongSparseArray<T>.getOrDefault(key: Long, defaultValue: T): T
inline fun <T> SparseArrayCompat<T>.getOrDefault(key: Int, defaultValue: T): T

Return the value corresponding to key, or defaultValue when not present.

Link copied to clipboard
inline fun <T> LongSparseArray<T>.getOrElse(key: Long, defaultValue: () -> T): T
inline fun <T> SparseArrayCompat<T>.getOrElse(key: Int, defaultValue: () -> T): T

Return the value corresponding to key, or from defaultValue when not present.

Link copied to clipboard

Return true when the collection contains elements.

Link copied to clipboard

Return an iterator over the collection's keys.

Link copied to clipboard
inline fun <K : Any, V : Any> lruCache(    maxSize: Int,     crossinline sizeOf: (key: K, value: V) -> Int = { _, _ -> 1 },     crossinline create: (key: K) -> V? = { null as V? },     crossinline onEntryRemoved: (evicted: Boolean, key: K, oldValue: V, newValue: V?) -> Unit = { _, _, _, _ -> }): LruCache<K, V>

Creates an LruCache with the given parameters.

Link copied to clipboard

Creates a new collection by adding or replacing entries from other.

Link copied to clipboard
inline operator fun <T> LongSparseArray<T>.set(key: Long, value: T)
inline operator fun <T> SparseArrayCompat<T>.set(key: Int, value: T)

Allows the use of the index operator for storing values in the collection.

Link copied to clipboard

Return an iterator over the collection's values.

Properties

Link copied to clipboard

Returns the number of key/value pairs in the collection.

Returns the number of key/value pairs in the collection.