Better trie implementations

This commit is contained in:
2025-10-08 20:57:13 +02:00
parent 5f0f4aa96b
commit 582163d4be
26 changed files with 2482 additions and 122 deletions

View File

@@ -1,11 +1,29 @@
package dataset
import (
"fmt"
"strings"
"git.maze.io/maze/styx/dataset/dnstrie"
"github.com/miekg/dns"
)
type DomainTrie struct {
*dnstrie.ValueTrie[bool]
}
func NewDomainTrie(permit bool, domains ...string) (*DomainTrie, error) {
trie := &DomainTrie{
ValueTrie: dnstrie.NewValue[bool](),
}
for _, domain := range domains {
if err := trie.Insert(domain, permit); err != nil {
return nil, fmt.Errorf("dataset: error inserting %s: %w", domain, err)
}
}
return trie, nil
}
type DomainTree struct {
root *domainTreeNode
}