ArraySet

class ArraySet<E> constructor(capacity: Int = 0) : MutableSet<E> (source)

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).

Note that this implementation is not intended to be appropriate for data structures that may contain large numbers of items. It is generally slower than a traditional HashSet, since lookups require a binary search and adds and removes require inserting and deleting entries in the array. For containers holding up to hundreds of items, the performance difference is not significant, less than 50%.

Because this container is intended to better balance memory use, unlike most other standard Java containers it will shrink its array as items are removed from it. Currently you have no control over this shrinking -- if you set a capacity and then remove an item, it may reduce the capacity to better match the current size. In the future an explicit call to set the capacity should turn off this aggressive shrinking behavior.

This structure is NOT thread-safe.

Constructors

Link copied to clipboard
fun <E> ArraySet(set: ArraySet<out E>?)

Create a new ArraySet with the mappings from the given ArraySet.

Link copied to clipboard
fun <E> ArraySet(set: Collection<E>?)

Create a new ArraySet with the mappings from the given Collection.

Link copied to clipboard
fun <E> ArraySet(array: Array<out E>?)

Create a new ArraySet with items from the given array.

Link copied to clipboard
fun ArraySet(capacity: Int = 0)

Creates a new empty ArraySet. The default capacity of an array map is 0, and will grow once items are added to it.

Functions

Link copied to clipboard
open override fun add(element: E): Boolean

Adds the specified object to this set. The set is not modified if it already contains the object.

Link copied to clipboard
fun addAll(array: ArraySet<out E>)

Perform a add of all values in array

open override fun addAll(elements: Collection<E>): Boolean

Perform an add of all values in elements

Link copied to clipboard
open override fun clear()

Make the array map empty. All storage is released.

Link copied to clipboard
open operator override fun contains(element: E): Boolean

Check whether a value exists in the set.

Link copied to clipboard
open override fun containsAll(elements: Collection<E>): Boolean

Determine if the array set contains all of the values in the given collection.

Link copied to clipboard
fun ensureCapacity(minimumCapacity: Int)

Ensure the array map can hold at least minimumCapacity items.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

This implementation returns false if the object is not a set, or if the sets have different sizes. Otherwise, for each value in this set, it checks to make sure the value also exists in the other set. If any value doesn't exist, the method returns false; otherwise, it returns true.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun indexOf(key: Any?): Int

Returns the index of a value in the set.

Link copied to clipboard
open override fun isEmpty(): Boolean

Return true if the array map contains no items.

Link copied to clipboard
open operator override fun iterator(): MutableIterator<E>

Return a MutableIterator over all values in the set.

Link copied to clipboard
open override fun remove(element: E): Boolean

Removes the specified object from this set.

Link copied to clipboard
fun removeAll(array: ArraySet<out E>): Boolean

Perform a remove of all values in array

open override fun removeAll(elements: Collection<E>): Boolean

Remove all values in the array set that exist in the given collection.

Link copied to clipboard
fun removeAt(index: Int): E

Remove the key/value mapping at the given index.

Link copied to clipboard
open override fun retainAll(elements: Collection<E>): Boolean

Remove all values in the array set that do not exist in the given collection.

Link copied to clipboard
open override fun toString(): String

This implementation composes a string by iterating over its values. If this set contains itself as a value, the string "(this Set)" will appear in its place.

Link copied to clipboard
fun valueAt(index: Int): E

Return the value at the given index in the array.

Properties

Link copied to clipboard
open override val size: Int