PrefixTree

class PrefixTree<K, V>(mapFactory: () -> MutableMap<K, PrefixTree<K, V>> = { mutableMapOf() })

A prefix tree, with amortized O(1) access time, amortized O(1) insertion time O(1), amortized O(1) removal time, and O(n) prune time. Thread-safe iff the internal transition tables, supplied by the factory, are thread-safe.

Author

Todd L Smith

Constructors

Link copied to clipboard
constructor(mapFactory: () -> MutableMap<K, PrefixTree<K, V>> = { mutableMapOf() })

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
operator fun get(key: Iterable<K>): V?

Fetch the value associated with the specified key, if any.

Link copied to clipboard
inline operator fun <V> PrefixTree<Int, V>.get(key: String): V?

Convenience getter for using string-keyed prefix trees.

Link copied to clipboard
fun getOrPut(key: Iterable<K>, producer: () -> V): V

Fetch the value associated with the specified key, or install the value produced by applying producer if no value was available.

Link copied to clipboard
inline fun <V> PrefixTree<Int, V>.getOrPut(key: String, noinline producer: () -> V): V

Convenience getter/setter for using string-keyed prefix trees.

Link copied to clipboard
fun payloads(key: Iterable<K>): List<V>

Fetch every payload stored under an improper suffix of the specified key, ordered lexicographically by key.

Link copied to clipboard
inline fun <V> PrefixTree<Int, V>.payloads(key: String): List<V>

Convenience accumulator for using string-keyed prefix trees.

Link copied to clipboard
fun prune()

Remove all paths from the receiver that do not lead to payloads.

Link copied to clipboard
fun remove(key: Iterable<K>): V?

Remove the specified key and any associated value from the receiver. Fast, because it does not alter the shape of the tree.

Link copied to clipboard
operator fun set(key: Iterable<K>, value: V): V?

Insert a new key-value pair into the receiver, replacing any existing value associated with the specified key.

Link copied to clipboard
inline operator fun <V> PrefixTree<Int, V>.set(key: String, value: V): V?

Convenience setter for using string-keyed prefix trees.

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