mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-17 14:09:44 +02:00
chore: update dependencies
This commit is contained in:
@@ -4,17 +4,17 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/goccy/go-yaml"
|
||||
"github.com/puzpuzpuz/xsync/v3"
|
||||
"github.com/puzpuzpuz/xsync/v4"
|
||||
)
|
||||
|
||||
type Map[KT comparable, VT any] struct {
|
||||
*xsync.MapOf[KT, VT]
|
||||
*xsync.Map[KT, VT]
|
||||
}
|
||||
|
||||
const minParallelSize = 4
|
||||
|
||||
func NewMapOf[KT comparable, VT any](options ...func(*xsync.MapConfig)) Map[KT, VT] {
|
||||
return Map[KT, VT]{xsync.NewMapOf[KT, VT](options...)}
|
||||
return Map[KT, VT]{xsync.NewMap[KT, VT](options...)}
|
||||
}
|
||||
|
||||
func NewMapFrom[KT comparable, VT any](m map[KT]VT) (res Map[KT, VT]) {
|
||||
|
||||
@@ -3,15 +3,15 @@ package functional
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/puzpuzpuz/xsync/v3"
|
||||
"github.com/puzpuzpuz/xsync/v4"
|
||||
)
|
||||
|
||||
type Set[T comparable] struct {
|
||||
m *xsync.MapOf[T, struct{}]
|
||||
m *xsync.Map[T, struct{}]
|
||||
}
|
||||
|
||||
func NewSet[T comparable]() Set[T] {
|
||||
return Set[T]{m: xsync.NewMapOf[T, struct{}]()}
|
||||
return Set[T]{m: xsync.NewMap[T, struct{}]()}
|
||||
}
|
||||
|
||||
func (set Set[T]) Add(v T) {
|
||||
|
||||
@@ -3,13 +3,13 @@ package pool
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/puzpuzpuz/xsync/v3"
|
||||
"github.com/puzpuzpuz/xsync/v4"
|
||||
"github.com/yusing/go-proxy/internal/logging"
|
||||
)
|
||||
|
||||
type (
|
||||
Pool[T Object] struct {
|
||||
m *xsync.MapOf[string, T]
|
||||
m *xsync.Map[string, T]
|
||||
name string
|
||||
}
|
||||
Object interface {
|
||||
@@ -19,7 +19,7 @@ type (
|
||||
)
|
||||
|
||||
func New[T Object](name string) Pool[T] {
|
||||
return Pool[T]{xsync.NewMapOf[string, T](), name}
|
||||
return Pool[T]{xsync.NewMap[string, T](), name}
|
||||
}
|
||||
|
||||
func (p Pool[T]) Name() string {
|
||||
|
||||
@@ -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