Skip to content

Commit

Permalink
Add doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
p-x9 committed Nov 22, 2024
1 parent 3672025 commit 4620021
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Sources/MachOKit/MachOFile+ExportTrie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,22 @@ extension MachOFile {
}

extension MachOFile.ExportTrie {
/// All exported symbols from the trie tree
public var exportedSymbols: [ExportedSymbol] {
wrapped.exportedSymbols
}

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

/// Search the trie tree by symbol name to get the expoted symbol
/// - Parameter key: symbol name
/// - Returns: If found, retruns exported symbol
public func search(for key: String) -> ExportedSymbol? {
wrapped.search(for: key)
}
Expand Down
10 changes: 9 additions & 1 deletion Sources/MachOKit/MachOImage+ExportTrie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,22 @@ extension MachOImage {
}

extension MachOImage.ExportTrie {
/// All exported symbols from the trie tree
public var exportedSymbols: [ExportedSymbol] {
wrapped.exportedSymbols
}

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


/// Search the trie tree by symbol name to get the expoted symbol
/// - Parameter key: symbol name
/// - Returns: If found, retruns exported symbol
public func search(for key: String) -> ExportedSymbol? {
wrapped.search(for: key)
}
Expand Down
21 changes: 21 additions & 0 deletions Sources/MachOKit/Util/TrieTree/Protocol/TrieTreeProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@

import Foundation

/// Protocol for structures representing Trie Tree
/// - ``DataTrieTree``: Handles the trie tree contained in ``Data``
/// - ``MemoryTrieTree``: Handles the trie tree exsisted on memory
///
/// It conforms to Sequence and sequentially retrieves the elements of the tree
/// that exist contiguously in memory space.
///
/// To retrieve all elements, it is more accurate to use the `entries` parameter, which traverses each node.
/// This is because some trie trees contain meaningless spaces between elements, which may not be contiguous in memory space.
public protocol TrieTreeProtocol<Content>: Sequence where Element == TrieNode<Content> {
associatedtype Content: TrieNodeContent

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

extension TrieTreeProtocol {
/// Elements of each of the nodes that make up the trie tree
///
/// It is obtained by traversing the nodes of the trie tree.It is obtained by traversing a trie tree.
/// In the case of traversal by the `Self` iterator, elements of contiguous memory space are retrieved sequentially.
public var entries: [Element] {
guard let root = first(where: { _ in true}) else {
return []
Expand Down Expand Up @@ -42,6 +55,11 @@ extension TrieTreeProtocol {
}

extension TrieTreeProtocol {
/// Traverses the trie tree to obtain the names and contents of all the terminals.
/// - Parameters:
/// - currentName: current name
/// - entry: Node element that is the root to start scanning
/// - result: All terminal names and contents of the `entry`.
public func _recurseTrie(
currentName: String,
entry: Element,
Expand All @@ -64,6 +82,9 @@ extension TrieTreeProtocol {
}

extension TrieTreeProtocol {
/// Search the trie tree by name to get terminal content and node offset
/// - Parameter key: name
/// - Returns: If found, retruns terminal content and node offset
public func _search(for key: String) -> (offset: Int, content: Content)? {
guard !key.isEmpty else { return nil }

Expand Down

0 comments on commit 4620021

Please sign in to comment.