SubTrie

public struct SubTrie<Key, Value> : Sendable where Key : Collection, Key : Sendable, Value : Sendable, Key.Element : Hashable, Key.Element : Sendable
extension SubTrie: CustomStringConvertible

A part of a trie.

  • The type of a trie projected by an instance of Self.

    Declaration

    Swift

    public typealias Base = Trie<Key, Value>
  • The Trie of which self is a projection.

    Declaration

    Swift

    fileprivate let base: Base
  • The root of this sub-tree.

    Declaration

    Swift

    fileprivate let root: Base.Node.Identifier
  • The number of key/value pairs in self.

    Declaration

    Swift

    public var count: Int { get }
  • Returns a collection with the key/value pairs in self.

    Declaration

    Swift

    public var elements: Base.Elements { get }
  • Accesses the value associated with key.

    Declaration

    Swift

    public subscript<K>(key: K) -> Value? where K : Collection, K : Sendable, Key.Element == K.Element { get }
  • Returns a sub-trie mapping the keys prefixed by key to their corresponding value in self, or nil if self contains no key starting with by key.

    Declaration

    Swift

    public subscript<K>(prefix key: K) -> SubTrie? where K : Collection, K : Sendable, Key.Element == K.Element { get }
  • Returns a pair (n, i) such that key[..<i] is the longest key prefix contained in self and n is a sub-trie mapping the keys prefixed by key[..<i] to their corresponding value in self.

    Declaration

    Swift

    public func longestPrefix<K: Collection & Sendable>(
      startingWith key: K
    ) -> (trie: SubTrie<Key, Value>, position: K.Index) where K.Element == Key.Element
  • Declaration

    Swift

    public var description: String { get }