8
8
9
9
import Foundation
10
10
11
+ /// Protocol for structures representing Trie Tree
12
+ /// - ``DataTrieTree``: Handles the trie tree contained in ``Data``
13
+ /// - ``MemoryTrieTree``: Handles the trie tree exsisted on memory
14
+ ///
15
+ /// It conforms to Sequence and sequentially retrieves the elements of the tree
16
+ /// that exist contiguously in memory space.
17
+ ///
18
+ /// To retrieve all elements, it is more accurate to use the `entries` parameter, which traverses each node.
19
+ /// This is because some trie trees contain meaningless spaces between elements, which may not be contiguous in memory space.
11
20
public protocol TrieTreeProtocol < Content> : Sequence where Element == TrieNode < Content > {
12
21
associatedtype Content : TrieNodeContent
13
22
14
23
func element( atOffset offset: Int ) -> Element ?
15
24
}
16
25
17
26
extension TrieTreeProtocol {
27
+ /// Elements of each of the nodes that make up the trie tree
28
+ ///
29
+ /// It is obtained by traversing the nodes of the trie tree.It is obtained by traversing a trie tree.
30
+ /// In the case of traversal by the `Self` iterator, elements of contiguous memory space are retrieved sequentially.
18
31
public var entries : [ Element ] {
19
32
guard let root = first ( where: { _ in true } ) else {
20
33
return [ ]
@@ -42,6 +55,11 @@ extension TrieTreeProtocol {
42
55
}
43
56
44
57
extension TrieTreeProtocol {
58
+ /// Traverses the trie tree to obtain the names and contents of all the terminals.
59
+ /// - Parameters:
60
+ /// - currentName: current name
61
+ /// - entry: Node element that is the root to start scanning
62
+ /// - result: All terminal names and contents of the `entry`.
45
63
public func _recurseTrie(
46
64
currentName: String ,
47
65
entry: Element ,
@@ -64,6 +82,9 @@ extension TrieTreeProtocol {
64
82
}
65
83
66
84
extension TrieTreeProtocol {
85
+ /// Search the trie tree by name to get terminal content and node offset
86
+ /// - Parameter key: name
87
+ /// - Returns: If found, retruns terminal content and node offset
67
88
public func _search( for key: String ) -> ( offset: Int , content: Content ) ? {
68
89
guard !key. isEmpty else { return nil }
69
90
0 commit comments