mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-21 16:01:22 +02:00
chore: update dependencies
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
package trie
|
||||
|
||||
import (
|
||||
"github.com/puzpuzpuz/xsync/v3"
|
||||
"github.com/puzpuzpuz/xsync/v4"
|
||||
)
|
||||
|
||||
type Node struct {
|
||||
key string
|
||||
children *xsync.MapOf[string, *Node] // lock-free map which allows concurrent access
|
||||
value AnyValue // only end nodes have values
|
||||
children *xsync.Map[string, *Node] // lock-free map which allows concurrent access
|
||||
value AnyValue // only end nodes have values
|
||||
}
|
||||
|
||||
func mayPrefix(key, part string) string {
|
||||
@@ -20,7 +20,7 @@ func mayPrefix(key, part string) string {
|
||||
func (node *Node) newChild(part string) *Node {
|
||||
return &Node{
|
||||
key: mayPrefix(node.key, part),
|
||||
children: xsync.NewMapOf[string, *Node](),
|
||||
children: xsync.NewMap[string, *Node](),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,16 +39,16 @@ func (node *Node) Get(key *Key) (any, bool) {
|
||||
return v, true
|
||||
}
|
||||
|
||||
func (node *Node) loadOrStore(key *Key, newFunc func() any) *Node {
|
||||
func (node *Node) loadOrStore(key *Key, newFunc func() any) (*Node, bool) {
|
||||
for i, seg := range key.segments {
|
||||
child, _ := node.children.LoadOrCompute(seg, func() *Node {
|
||||
child, _ := node.children.LoadOrCompute(seg, func() (*Node, bool) {
|
||||
newNode := node.newChild(seg)
|
||||
if i == len(key.segments)-1 {
|
||||
newNode.value.Store(newFunc())
|
||||
}
|
||||
return newNode
|
||||
return newNode, false
|
||||
})
|
||||
node = child
|
||||
}
|
||||
return node
|
||||
return node, false
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package trie
|
||||
|
||||
import "github.com/puzpuzpuz/xsync/v3"
|
||||
import "github.com/puzpuzpuz/xsync/v4"
|
||||
|
||||
type Root struct {
|
||||
*Node
|
||||
cached *xsync.MapOf[string, *Node]
|
||||
cached *xsync.Map[string, *Node]
|
||||
}
|
||||
|
||||
func NewTrie() *Root {
|
||||
return &Root{
|
||||
Node: &Node{
|
||||
children: xsync.NewMapOf[string, *Node](),
|
||||
children: xsync.NewMap[string, *Node](),
|
||||
},
|
||||
cached: xsync.NewMapOf[string, *Node](),
|
||||
cached: xsync.NewMap[string, *Node](),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func (r *Root) getNode(key *Key, newFunc func() any) *Node {
|
||||
if key.hasWildcard {
|
||||
panic("should not call Load or Store on a key with any wildcard: " + key.full)
|
||||
}
|
||||
node, _ := r.cached.LoadOrCompute(key.full, func() *Node {
|
||||
node, _ := r.cached.LoadOrCompute(key.full, func() (*Node, bool) {
|
||||
return r.Node.loadOrStore(key, newFunc)
|
||||
})
|
||||
return node
|
||||
|
||||
Reference in New Issue
Block a user