diff --git a/anonymizer.go b/anonymizer.go index c9b373b..76073bc 100644 --- a/anonymizer.go +++ b/anonymizer.go @@ -4,8 +4,6 @@ import ( _ "embed" "iter" "unicode" - - "github.com/derekparker/trie" ) type Anonymizer struct { @@ -61,7 +59,7 @@ func (a Anonymizer) mask(runes []rune, span span) { } // Check if the word in the given span should be anonymized. -func shouldAnonymize(dict *trie.Trie, span span) bool { +func shouldAnonymize(dict *Dict, span span) bool { word := span.word if unicode.IsUpper(word[0]) { if span.initial { diff --git a/dictionaries.go b/dictionaries.go index 63a6f9a..b683421 100644 --- a/dictionaries.go +++ b/dictionaries.go @@ -6,11 +6,11 @@ import ( "os" "unicode" - "github.com/derekparker/trie" + "github.com/derekparker/trie/v3" ) // Dictionary of words. -type Dict = trie.Trie +type Dict = trie.Trie[struct{}] const ( dictDir = "/usr/share/dict/" @@ -35,7 +35,7 @@ var languages = map[string]string{ "pt": "portuguese", "es": "spanish", "sv": "swedish", - "ua": "ukrainian", + "uk": "ukrainian", } func init() { @@ -97,13 +97,13 @@ func loadDict(path string) (*Dict, error) { return nil, fmt.Errorf("open %s: %v", path, err) } defer file.Close() - dict := trie.New() + dict := trie.New[struct{}]() scanner := bufio.NewScanner(file) // optionally, resize scanner's capacity for lines over 64K, see next example for scanner.Scan() { word := scanner.Text() if isLower(word) { - dict.Add(word, nil) + dict.Add(word, struct{}{}) } } return dict, nil diff --git a/go.mod b/go.mod index ab0067b..fb290ff 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,8 @@ module github.com/orsinium-labs/anonymizer -go 1.23.0 +go 1.23.3 require ( - github.com/derekparker/trie v0.0.0-20230829180723-39f4de51ef7d + github.com/derekparker/trie/v3 v3.0.0-20240916174412-4095f8e392f7 github.com/matryer/is v1.4.1 ) diff --git a/go.sum b/go.sum index daab6eb..f9835ca 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ -github.com/derekparker/trie v0.0.0-20230829180723-39f4de51ef7d h1:hUWoLdw5kvo2xCsqlsIBMvWUc1QCSsCYD2J2+Fg6YoU= -github.com/derekparker/trie v0.0.0-20230829180723-39f4de51ef7d/go.mod h1:C7Es+DLenIpPc9J6IYw4jrK0h7S9bKj4DNl8+KxGEXU= +github.com/derekparker/trie/v3 v3.0.0-20240916174412-4095f8e392f7 h1:gsEwGHr/KBuoslhPtj+T2grgoV6puovmeTm1eupzDXg= +github.com/derekparker/trie/v3 v3.0.0-20240916174412-4095f8e392f7/go.mod h1:P94lW0LPgiaMgKAEQD59IDZD2jMK9paKok8Nli/nQbE= github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ= github.com/matryer/is v1.4.1/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=