Package ghidra.util.search.trie
Class ByteTrie<T>
java.lang.Object
ghidra.util.search.trie.ByteTrie<T>
- Type Parameters:
T- the item storage type
- All Implemented Interfaces:
ByteTrieIfc<T>
- Direct Known Subclasses:
CaseInsensitiveByteTrie
ByteTrie is a byte-based trie specifically designed to implement the Aho-Corasick
string search algorithm.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a byte sequence to the trie, with corresponding user item.find(byte[] value) Finds a byte sequence in the trie and returns a node interface object for it, or null if not present.protected ByteTrieNode<T> generateNode(byte id, ByteTrieNode<T> parent, int length) voidinorder(TaskMonitor monitor, Op<T> op) Visits all the nodes in the trie such that the visitation order is properly ordered (even though the actual algorithm below is a PREORDER traversal).booleanisEmpty()Returns if the trie is empty.intReturns the number of nodes in the trie; this is essentially equal to the sum of the number of characters in all byte sequences present in the trie, minus their shared prefixes.search(byte[] text, TaskMonitor monitor) Search an array of bytes using the Aho-Corasick multiple string trie search algorithm.search(Memory memory, AddressSetView view, TaskMonitor monitor) Search memory using the Aho-Corasick multiple string trie search algorithm.intsize()Returns the number of byte sequences in the trie.
-
Constructor Details
-
ByteTrie
public ByteTrie()
-
-
Method Details
-
generateNode
-
isEmpty
public boolean isEmpty()Returns if the trie is empty.- Specified by:
isEmptyin interfaceByteTrieIfc<T>- Returns:
- if the trie is empty
-
size
public int size()Returns the number of byte sequences in the trie.- Specified by:
sizein interfaceByteTrieIfc<T>- Returns:
- the number of byte sequences in the trie
-
numberOfNodes
public int numberOfNodes()Returns the number of nodes in the trie; this is essentially equal to the sum of the number of characters in all byte sequences present in the trie, minus their shared prefixes.- Specified by:
numberOfNodesin interfaceByteTrieIfc<T>- Returns:
- the number of nodes in the trie
-
add
Adds a byte sequence to the trie, with corresponding user item. Returns if the add took place, or if this add was essentially a replacement of a previously present value (previous user item is lost forever).- Specified by:
addin interfaceByteTrieIfc<T>- Parameters:
value- the byte sequence to insert into the trieitem- a user item to store in that location- Returns:
- whether the add took place
-
find
Finds a byte sequence in the trie and returns a node interface object for it, or null if not present.- Specified by:
findin interfaceByteTrieIfc<T>- Parameters:
value- the byte sequence sought- Returns:
- the node interface if present, or null
-
inorder
Visits all the nodes in the trie such that the visitation order is properly ordered (even though the actual algorithm below is a PREORDER traversal). The client is responsible for not performing actions on non-terminal nodes as necessary.- Specified by:
inorderin interfaceByteTrieIfc<T>- Parameters:
monitor- a task monitorop- the operation to perform- Throws:
CancelledException- if the user cancels
-
search
public List<SearchResult<Integer,T>> search(byte[] text, TaskMonitor monitor) throws CancelledException Search an array of bytes using the Aho-Corasick multiple string trie search algorithm.- Specified by:
searchin interfaceByteTrieIfc<T>- Parameters:
text- the bytes to searchmonitor- a task monitor- Returns:
- a list of search results
- Throws:
CancelledException
-
search
public List<SearchResult<Address,T>> search(Memory memory, AddressSetView view, TaskMonitor monitor) throws MemoryAccessException, CancelledException Search memory using the Aho-Corasick multiple string trie search algorithm.- Specified by:
searchin interfaceByteTrieIfc<T>- Parameters:
memory- the program memory managerview- the address set view to searchmonitor- a task monitor- Returns:
- a list of search results
- Throws:
MemoryAccessException- if bytes are not availableCancelledException- if the user cancels
-