Skip to content

Commit

Permalink
Initial v2 code
Browse files Browse the repository at this point in the history
  • Loading branch information
Daisuke Maki committed Oct 11, 2024
1 parent fe02a1e commit 16b5a7b
Show file tree
Hide file tree
Showing 9 changed files with 292 additions and 276 deletions.
29 changes: 0 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,3 @@ This trie is implemented such that generic Key types can be used.
Most other trie implementations are optimized for string based keys, but my use
case is to match certain numeric opcodes to arbitrary data.

Within this library Keys are treated as sequence of Labels.
For example, a string can be thought of as Key that is comprised of a sequence
of rune Labels.

Each Key need to be able to break down to Labels via the `Iterate` method.
Each Label in turn becomes the local key in a trie node.
Each Label need to implement a `UniqueID` method to identify itself.

# SYNOPSIS

```go
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

t := trie.New()

t.Put(ctx, trie.StringKey("foo"), 1)
v, ok := t.Get(ctx, trie.StringKey("foo"))
ok := t.Delete(ctx, trie.StringKey("foo"))
for p := range t.Walk(ctx) {
// p.Labels
// p.Value
}
```

# REFERENCES

Originally based on https://github.com/koron/go-trie
Much code stolen from https://github.com/dghubble/trie
12 changes: 9 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module github.com/lestrrat-go/trie
module github.com/lestrrat-go/trie/v2

go 1.16
go 1.23

require github.com/stretchr/testify v1.7.0
require github.com/stretchr/testify v1.9.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
27 changes: 0 additions & 27 deletions interface.go

This file was deleted.

18 changes: 18 additions & 0 deletions string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package trie

import (
"iter"

Check failure on line 4 in string.go

View workflow job for this annotation

GitHub Actions / Go 1.15.x test

package iter is not in GOROOT (/opt/hostedtoolcache/go/1.15.15/x64/src/iter)

Check failure on line 4 in string.go

View workflow job for this annotation

GitHub Actions / Go 1.14.x test

package iter is not in GOROOT (/opt/hostedtoolcache/go/1.14.15/x64/src/iter)
)

// String returns a Tokenizer that tokenizes a string into individual runes.
func String() Tokenizer[string, rune] {
return TokenizeFunc[string, rune](func(s string) (iter.Seq[rune], error) {
return func(yield func(rune) bool) {
for _, r := range s {
if !yield(r) {
break
}
}
}, nil
})
}
34 changes: 0 additions & 34 deletions string_key.go

This file was deleted.

Loading

0 comments on commit 16b5a7b

Please sign in to comment.