LinkedHashTreeMap

A map of comparable keys to values. Unlike {@code TreeMap} , this class uses insertion order for iteration order. Comparison order is only used as an optimization for efficient insertion and removal.

This implementation was derived from Android 4.1's TreeMap and LinkedHashMap classes.

class LinkedHashTreeMap<K, V> : AbstractMap<K, V> , Serializable

Constructors

LinkedHashTreeMap
Link copied to clipboard

Create a natural order, empty tree map whose keys must be mutually comparable and non-null.

open fun LinkedHashTreeMap()
LinkedHashTreeMap
Link copied to clipboard

Create a tree map ordered by {@code comparator} . This map's keys may only be null if {@code * comparator} permits.

open fun LinkedHashTreeMap(comparator: Comparator<out Any>)

Types

AvlBuilder
Link copied to clipboard

Builds AVL trees of a predetermined size by accepting nodes of increasing value. To use:

  1. Call reset to initialize the target size size.
  2. Call size times with increasing values.
  3. Call root to get the root of the balanced tree.

The returned tree will satisfy the AVL constraint: for every node N, the height of N.left and N.right is different by at most 1. It accomplishes this by omitting deepest-level leaf nodes when building trees whose size isn't a power of 2 minus 1.

Unlike rebuilding a tree from scratch, this approach requires no value comparisons. Using this class to create a tree of size S is {@code O(S)} .

class AvlBuilder<K, V>
AvlIterator
Link copied to clipboard

Walks an AVL tree in iteration order. Once a node has been returned, its left, right and parent links are no longer used. For this reason it is safe to transform these links as you walk a tree.

Warning: this iterator is destructive. It clears the parent node of all nodes in the tree. It is an error to make a partial iteration of a tree.

open class AvlIterator<K, V>
EntrySet
Link copied to clipboard
class EntrySet : AbstractSet<Map.Entry<K, V>>
KeySet
Link copied to clipboard
class KeySet : AbstractSet<K>
LinkedTreeMapIterator
Link copied to clipboard
abstract class LinkedTreeMapIterator<T> : Iterator<T>
Node
Link copied to clipboard
class Node<K, V> : Map.Entry<K, V>

Functions

clear
Link copied to clipboard
open fun clear()
open fun clear()
clone
Link copied to clipboard
open fun clone(): Any
compute
Link copied to clipboard
open fun compute(key: K, remappingFunction: BiFunction<out Any, out Any, out V>): V
computeIfAbsent
Link copied to clipboard
open fun computeIfAbsent(key: K, mappingFunction: Function<out Any, out V>): V
computeIfPresent
Link copied to clipboard
open fun computeIfPresent(key: K, remappingFunction: BiFunction<out Any, out Any, out V>): V
containsKey
Link copied to clipboard
open fun containsKey(key: Any): Boolean
open fun containsKey(key: Any): Boolean
containsValue
Link copied to clipboard
open fun containsValue(value: Any): Boolean
copyOf
Link copied to clipboard
open fun <K, V> copyOf(map: Map<out K, out V>): Map<K, V>
doubleCapacity
Link copied to clipboard

Returns a new array containing the same nodes as {@code oldTable} , but with twice as many trees, each of (approximately) half the previous size.

open fun <K, V> doubleCapacity(oldTable: Array<LinkedHashTreeMap.Node<K, V>>): Array<LinkedHashTreeMap.Node<K, V>>
entry
Link copied to clipboard
open fun <K, V> entry(k: K, v: V): Map.Entry<K, V>
entrySet
Link copied to clipboard
open fun entrySet(): Set<Map.Entry<K, V>>
abstract fun entrySet(): Set<Map.Entry<K, V>>
eq
Link copied to clipboard
open fun eq(o1: Any, o2: Any): Boolean
equals
Link copied to clipboard
open fun equals(o: Any): Boolean
find
Link copied to clipboard

Returns the node at or adjacent to the given key, creating it if requested.

open fun find(key: K, create: Boolean): LinkedHashTreeMap.Node<K, V>
findByEntry
Link copied to clipboard

Returns this map's entry that has the same key and value as {@code entry} , or null if this map has no such entry.

This method uses the comparator for key equality rather than {@code equals} . If this map's comparator isn't consistent with equals (such as {@code String.CASE_INSENSITIVE_ORDER} ), then {@code remove()} and {@code contains()} will violate the collections API.

open fun findByEntry(entry: Map.Entry<out Any, out Any>): LinkedHashTreeMap.Node<K, V>
findByObject
Link copied to clipboard
open fun findByObject(key: Any): LinkedHashTreeMap.Node<K, V>
forEach
Link copied to clipboard
open fun forEach(action: BiConsumer<out Any, out Any>)
get
Link copied to clipboard
open fun get(key: Any): V
open fun get(key: Any): V
getOrDefault
Link copied to clipboard
open fun getOrDefault(key: Any, defaultValue: V): V
hashCode
Link copied to clipboard
open fun hashCode(): Int
isEmpty
Link copied to clipboard
open fun isEmpty(): Boolean
keySet
Link copied to clipboard
open fun keySet(): Set<K>
open fun keySet(): Set<K>
merge
Link copied to clipboard
open fun merge(key: K, value: V, remappingFunction: BiFunction<out Any, out Any, out V>): V
of
Link copied to clipboard
open fun <K, V> of(): Map<K, V>
ofEntries
Link copied to clipboard
open fun <K, V> ofEntries(entries: Array<Map.Entry<out K, out V>>): Map<K, V>
put
Link copied to clipboard
open fun put(key: K, value: V): V
open fun put(key: K, value: V): V
putAll
Link copied to clipboard
open fun putAll(m: Map<out K, out V>)
putIfAbsent
Link copied to clipboard
open fun putIfAbsent(key: K, value: V): V
remove
Link copied to clipboard
open fun remove(key: Any): V
open fun remove(key: Any): V
open fun remove(key: Any, value: Any): Boolean
removeInternal
Link copied to clipboard

Removes {@code node} from this tree, rearranging the tree's structure as necessary.

open fun removeInternal(node: LinkedHashTreeMap.Node<K, V>, unlink: Boolean)
removeInternalByKey
Link copied to clipboard
open fun removeInternalByKey(key: Any): LinkedHashTreeMap.Node<K, V>
replace
Link copied to clipboard
open fun replace(key: K, value: V): V
open fun replace(key: K, oldValue: V, newValue: V): Boolean
replaceAll
Link copied to clipboard
open fun replaceAll(function: BiFunction<out Any, out Any, out V>)
size
Link copied to clipboard
open fun size(): Int
open fun size(): Int
toString
Link copied to clipboard
open fun toString(): String
values
Link copied to clipboard
open fun values(): Collection<V>

Properties

comparator
Link copied to clipboard
open val comparator: Comparator<out Any>
header
Link copied to clipboard
val header: LinkedHashTreeMap.Node<K, V>
modCount
Link copied to clipboard
open val modCount: Int
size
Link copied to clipboard
open val size: Int
table
Link copied to clipboard
open val table: Array<LinkedHashTreeMap.Node<K, V>>
threshold
Link copied to clipboard
open val threshold: Int