Skip to content

Commit

Permalink
Update trie package
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Nov 24, 2024
1 parent c671e61 commit 48d884e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
4 changes: 1 addition & 3 deletions anonymizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
_ "embed"
"iter"
"unicode"

"github.com/derekparker/trie"
)

type Anonymizer struct {
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions dictionaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand All @@ -35,7 +35,7 @@ var languages = map[string]string{
"pt": "portuguese",
"es": "spanish",
"sv": "swedish",
"ua": "ukrainian",
"uk": "ukrainian",
}

func init() {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=

0 comments on commit 48d884e

Please sign in to comment.