v.token: add manual .str() methods for KeywordsMatcherTrie and TrieNode, to workaround cgen errors

This commit is contained in:
Delyan Angelov 2025-08-30 19:19:31 +03:00
parent 1b3ec4aea3
commit 4bc72835b8
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED

View file

@ -11,6 +11,11 @@ pub mut:
max_len int
}
// str returns a short representation of matcher
pub fn (km &KeywordsMatcherTrie) str() string {
return 'KeywordsMatcherTrie{ /* nodes.len: ${km.nodes.len} */ min_len: ${km.min_len}, max_len: ${km.max_len} }'
}
// TrieNode is a single node from a trie, used by KeywordsMatcherTrie
pub struct TrieNode {
pub mut:
@ -18,6 +23,14 @@ pub mut:
value int = -1 // when != -1, it is a leaf node representing a match
}
// str returns a string representation of the node content
pub fn (node &TrieNode) str() string {
if isnil(node) {
return '&TrieNode(nil)'
}
return '&TrieNode{value: ${node.value}}'
}
// find tries to find the given `word` in the set of all previously added words
// to the KeywordsMatcherTrie instance. It returns -1 if the word was NOT found
// there at all. If the word was found, find will return the `value` (value => 0),