Skip to content

Commit 4620021

Browse files
committed
Add doc comments
1 parent 3672025 commit 4620021

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Sources/MachOKit/MachOFile+ExportTrie.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,22 @@ extension MachOFile {
4242
}
4343

4444
extension MachOFile.ExportTrie {
45+
/// All exported symbols from the trie tree
4546
public var exportedSymbols: [ExportedSymbol] {
4647
wrapped.exportedSymbols
4748
}
4849

50+
/// Elements of each of the nodes that make up the trie tree
51+
///
52+
/// It is obtained by traversing the nodes of the trie tree.It is obtained by traversing a trie tree.
53+
/// Slower than using `ExportTrie` iterator, but compatible with all Linker(ld) versions
4954
public var entries: [ExportTrieEntry] {
5055
wrapped.entries
5156
}
5257

58+
/// Search the trie tree by symbol name to get the expoted symbol
59+
/// - Parameter key: symbol name
60+
/// - Returns: If found, retruns exported symbol
5361
public func search(for key: String) -> ExportedSymbol? {
5462
wrapped.search(for: key)
5563
}

Sources/MachOKit/MachOImage+ExportTrie.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,22 @@ extension MachOImage {
4949
}
5050

5151
extension MachOImage.ExportTrie {
52+
/// All exported symbols from the trie tree
5253
public var exportedSymbols: [ExportedSymbol] {
5354
wrapped.exportedSymbols
5455
}
5556

57+
/// Elements of each of the nodes that make up the trie tree
58+
///
59+
/// It is obtained by traversing the nodes of the trie tree.It is obtained by traversing a trie tree.
60+
/// Slower than using `ExportTrie` iterator, but compatible with all Linker(ld) versions
5661
public var entries: [ExportTrieEntry] {
5762
wrapped.entries
5863
}
59-
64+
65+
/// Search the trie tree by symbol name to get the expoted symbol
66+
/// - Parameter key: symbol name
67+
/// - Returns: If found, retruns exported symbol
6068
public func search(for key: String) -> ExportedSymbol? {
6169
wrapped.search(for: key)
6270
}

Sources/MachOKit/Util/TrieTree/Protocol/TrieTreeProtocol.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,26 @@
88

99
import Foundation
1010

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.
1120
public protocol TrieTreeProtocol<Content>: Sequence where Element == TrieNode<Content> {
1221
associatedtype Content: TrieNodeContent
1322

1423
func element(atOffset offset: Int) -> Element?
1524
}
1625

1726
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.
1831
public var entries: [Element] {
1932
guard let root = first(where: { _ in true}) else {
2033
return []
@@ -42,6 +55,11 @@ extension TrieTreeProtocol {
4255
}
4356

4457
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`.
4563
public func _recurseTrie(
4664
currentName: String,
4765
entry: Element,
@@ -64,6 +82,9 @@ extension TrieTreeProtocol {
6482
}
6583

6684
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
6788
public func _search(for key: String) -> (offset: Int, content: Content)? {
6889
guard !key.isEmpty else { return nil }
6990

0 commit comments

Comments
 (0)