Trie
public struct Trie<Key, Value> : Sendable where Key : Collection, Key : Sendable, Value : Sendable, Key.Element : Hashable, Key.Element : Sendable
extension Trie: CustomStringConvertible
extension Trie: Equatable where Value: Equatable
extension Trie: Hashable where Value: Hashable
A trie (a.k.a. prefix tree).
-
A node representing either one of the strings in a trie or a prefix thereof.
See moreDeclaration
-
The nodes in the trie, the first of which is the root.
Declaration
Swift
fileprivate var nodes: [Node] -
Creates an empty trie.
Declaration
Swift
public init() -
The number of key/value pairs in
self.Declaration
Swift
public var count: Int { get } -
trueiffselfis empty.Declaration
Swift
public var isEmpty: Bool { get } -
Returns a collection with the key/value pairs in
self.Declaration
Swift
public var elements: Elements { get } -
Returns a pair
(n, i)such thatkey[..<i]is the longest key prefix contained inselfandnis a sub-trie mapping the keys prefixed bykey[..<i]to their corresponding value inself.If
keyis fully contained in one of the keys inself, theniiskey.endIndexandnis the result ofself[prefix: key]. Ifkeyshares no prefix with any of the keys stored inself, theniiskey.startIndexandnis equal toself.Declaration
Swift
public func longestPrefix<K: Collection & Sendable>( startingWith key: K ) -> (trie: SubTrie<Key, Value>, position: K.Index) where K.Element == Key.Element -
Accesses the value associated with
key.Declaration
Swift
public subscript<K>(key: K) -> Value? where K : Collection, Key.Element == K.Element { get set } -
Returns a sub-trie mapping the keys prefixed by
keyto their corresponding value inself, ornilifselfcontains no key starting with bykey.Declaration
Swift
public subscript<K: Collection & Sendable>( prefix key: K ) -> SubTrie<Key, Value>? where K.Element == Key.Element -
Returns the node corresponding to the longest prefix shared with
keylooked up fromroot.Declaration
-
Returns the node corresponding to
keylooked up fromroot.Declaration
-
Declaration
Swift
public struct Elements : Collection -
Declaration
Swift
public var description: String { get }
-
Returns
trueiffselfshares storage withother.Declaration
Swift
private func isSharingStorage(with other: `Self`) -> Bool -
Declaration
Swift
public static func == (lhs: `Self`, rhs: `Self`) -> Bool
-
Declaration
Swift
public func hash(into hasher: inout Hasher)
View on GitHub