Documentation ¶
Index ¶
- func ValidateKey(key string) error
- type Config
- type Dimension
- type DimensionFlag
- type Event
- type LockType
- type MutableTree
- type MutableTrees
- type NodeShiftTree
- func (t *NodeShiftTree[T]) CanLock() bool
- func (r *NodeShiftTree[T]) Delete(key string) (T, bool)
- func (r *NodeShiftTree[T]) DeleteAll(key string)
- func (r *NodeShiftTree[T]) DeletePrefix(prefix string) int
- func (t *NodeShiftTree[T]) DeletePrefixAll(prefix string) int
- func (r *NodeShiftTree[T]) DeleteRaw(key string)
- func (r *NodeShiftTree[T]) ForEeachInDimension(s string, d int, f func(T) bool)
- func (r *NodeShiftTree[T]) Get(s string) T
- func (r *NodeShiftTree[T]) GetRaw(s string) (T, bool)
- func (r *NodeShiftTree[T]) Has(s string) bool
- func (t *NodeShiftTree[T]) Increment(d int) *NodeShiftTree[T]
- func (r *NodeShiftTree[T]) InsertIntoCurrentDimension(s string, v T) (T, T, bool)
- func (r *NodeShiftTree[T]) InsertIntoValuesDimension(s string, v T) (T, T, bool)
- func (r *NodeShiftTree[T]) InsertIntoValuesDimensionWithLock(s string, v T) (T, T, bool)
- func (r *NodeShiftTree[T]) InsertRawWithLock(s string, v any) (any, bool)
- func (t *NodeShiftTree[T]) Len() int
- func (t *NodeShiftTree[T]) Lock(writable bool) (commit func())
- func (r *NodeShiftTree[T]) LongestPrefix(s string, exact bool, predicate func(v T) bool) (string, T)
- func (r *NodeShiftTree[T]) LongestPrefixAll(s string) (string, bool)
- func (t *NodeShiftTree[T]) Shape(d, v int) *NodeShiftTree[T]
- func (t *NodeShiftTree[T]) String() string
- func (r *NodeShiftTree[T]) WalkPrefixRaw(prefix string, walker func(key string, value T) bool)
- type NodeShiftTreeWalker
- type Shifter
- type SimpleTree
- func (tree *SimpleTree[T]) Get(s string) T
- func (tree *SimpleTree[T]) Insert(s string, v T) T
- func (tree *SimpleTree[T]) Lock(lockType LockType) func()
- func (tree *SimpleTree[T]) LongestPrefix(s string) (string, T)
- func (tree *SimpleTree[T]) WalkPrefix(lockType LockType, s string, f func(s string, v T) (bool, error)) error
- type Tree
- type TreeShiftTree
- func (t *TreeShiftTree[T]) Delete(key string)
- func (t *TreeShiftTree[T]) DeleteAllFunc(s string, f func(s string, v T) bool)
- func (t *TreeShiftTree[T]) DeletePrefix(prefix string) int
- func (t *TreeShiftTree[T]) Get(s string) T
- func (t *TreeShiftTree[T]) Insert(s string, v T) T
- func (t *TreeShiftTree[T]) LenRaw() int
- func (t *TreeShiftTree[T]) Lock(lockType LockType) func()
- func (t *TreeShiftTree[T]) LongestPrefix(s string) (string, T)
- func (t TreeShiftTree[T]) Shape(d, v int) *TreeShiftTree[T]
- func (t *TreeShiftTree[T]) WalkPrefix(lockType LockType, s string, f func(s string, v T) (bool, error)) error
- func (t *TreeShiftTree[T]) WalkPrefixRaw(lockType LockType, s string, f func(s string, v T) (bool, error)) error
- type WalkConfig
- type WalkContext
- func (ctx *WalkContext[T]) AddEventListener(event, path string, handler func(*Event[T]))
- func (ctx *WalkContext[T]) AddPostHook(handler func() error)
- func (ctx *WalkContext[T]) Data() *SimpleTree[any]
- func (ctx *WalkContext[T]) HandleEvents() error
- func (ctx *WalkContext[T]) HandleEventsAndHooks() error
- func (ctx *WalkContext[T]) SendEvent(event *Event[T])
- type WalkFunc
- type WalkableTree
- type WalkableTrees
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateKey ¶
ValidateKey returns an error if the key is not valid.
Types ¶
type Config ¶
type Config[T any] struct { // Shifter handles tree transformations. Shifter Shifter[T] }
type Dimension ¶
type Dimension [1]int
Dimension is a row in the Hugo build matrix which currently has one value: language.
type DimensionFlag ¶
type DimensionFlag byte
DimensionFlag is a flag in the Hugo build matrix.
const ( // Language is currently the only dimension in the Hugo build matrix. DimensionLanguage DimensionFlag = 1 << iota )
func (DimensionFlag) Has ¶
func (d DimensionFlag) Has(o DimensionFlag) bool
Has returns whether the given flag is set.
func (DimensionFlag) Index ¶
func (d DimensionFlag) Index() int
Index returns this flag's index in the Dimensions array.
func (DimensionFlag) Set ¶
func (d DimensionFlag) Set(o DimensionFlag) DimensionFlag
Set sets the given flag.
type Event ¶
type Event[T any] struct { Name string Path string Source T // contains filtered or unexported fields }
Event is used to communicate events in the tree.
func (*Event[T]) StopPropagation ¶
func (e *Event[T]) StopPropagation()
StopPropagation stops the propagation of the event.
type MutableTree ¶
type MutableTree interface { DeleteRaw(key string) DeleteAll(key string) DeletePrefix(prefix string) int DeletePrefixAll(prefix string) int Lock(writable bool) (commit func()) CanLock() bool // Used for troubleshooting only. }
MutableTree is a tree that can be modified.
type MutableTrees ¶
type MutableTrees []MutableTree
func (MutableTrees) CanLock ¶
func (t MutableTrees) CanLock() bool
func (MutableTrees) DeleteAll ¶
func (t MutableTrees) DeleteAll(key string)
func (MutableTrees) DeletePrefix ¶
func (t MutableTrees) DeletePrefix(prefix string) int
func (MutableTrees) DeletePrefixAll ¶
func (t MutableTrees) DeletePrefixAll(prefix string) int
func (MutableTrees) DeleteRaw ¶ added in v0.126.0
func (t MutableTrees) DeleteRaw(key string)
func (MutableTrees) Lock ¶
func (t MutableTrees) Lock(writable bool) (commit func())
type NodeShiftTree ¶
type NodeShiftTree[T any] struct { // contains filtered or unexported fields }
NodeShiftTree is the root of a tree that can be shaped using the Shape method. Note that multiplied shapes of the same tree is meant to be used concurrently, so use the applicable locking when needed.
func New ¶
func New[T any](cfg Config[T]) *NodeShiftTree[T]
func (*NodeShiftTree[T]) CanLock ¶
func (t *NodeShiftTree[T]) CanLock() bool
func (*NodeShiftTree[T]) Delete ¶
func (r *NodeShiftTree[T]) Delete(key string) (T, bool)
func (*NodeShiftTree[T]) DeleteAll ¶
func (r *NodeShiftTree[T]) DeleteAll(key string)
func (*NodeShiftTree[T]) DeletePrefix ¶
func (r *NodeShiftTree[T]) DeletePrefix(prefix string) int
func (*NodeShiftTree[T]) DeletePrefixAll ¶
func (t *NodeShiftTree[T]) DeletePrefixAll(prefix string) int
func (*NodeShiftTree[T]) DeleteRaw ¶ added in v0.126.0
func (r *NodeShiftTree[T]) DeleteRaw(key string)
func (*NodeShiftTree[T]) ForEeachInDimension ¶
func (r *NodeShiftTree[T]) ForEeachInDimension(s string, d int, f func(T) bool)
func (*NodeShiftTree[T]) Get ¶
func (r *NodeShiftTree[T]) Get(s string) T
func (*NodeShiftTree[T]) GetRaw ¶
func (r *NodeShiftTree[T]) GetRaw(s string) (T, bool)
func (*NodeShiftTree[T]) Has ¶
func (r *NodeShiftTree[T]) Has(s string) bool
func (*NodeShiftTree[T]) Increment ¶
func (t *NodeShiftTree[T]) Increment(d int) *NodeShiftTree[T]
Increment the value of dimension d by 1.
func (*NodeShiftTree[T]) InsertIntoCurrentDimension ¶
func (r *NodeShiftTree[T]) InsertIntoCurrentDimension(s string, v T) (T, T, bool)
func (*NodeShiftTree[T]) InsertIntoValuesDimension ¶
func (r *NodeShiftTree[T]) InsertIntoValuesDimension(s string, v T) (T, T, bool)
InsertIntoValuesDimension inserts v into the tree at the given key and the dimension defined by the value. It returns the updated and existing T and a bool indicating if an existing record is updated.
func (*NodeShiftTree[T]) InsertIntoValuesDimensionWithLock ¶ added in v0.126.0
func (r *NodeShiftTree[T]) InsertIntoValuesDimensionWithLock(s string, v T) (T, T, bool)
It returns the updated and existing T and a bool indicating if an existing record is updated.
func (*NodeShiftTree[T]) InsertRawWithLock ¶
func (r *NodeShiftTree[T]) InsertRawWithLock(s string, v any) (any, bool)
func (*NodeShiftTree[T]) Len ¶
func (t *NodeShiftTree[T]) Len() int
func (*NodeShiftTree[T]) Lock ¶
func (t *NodeShiftTree[T]) Lock(writable bool) (commit func())
Lock locks the data store for read or read/write access until commit is invoked. Note that Root is not thread-safe outside of this transaction construct.
func (*NodeShiftTree[T]) LongestPrefix ¶
func (r *NodeShiftTree[T]) LongestPrefix(s string, exact bool, predicate func(v T) bool) (string, T)
LongestPrefix finds the longest prefix of s that exists in the tree that also matches the predicate (if set). Set exact to true to only match exact in the current dimension (e.g. language).
func (*NodeShiftTree[T]) LongestPrefixAll ¶
func (r *NodeShiftTree[T]) LongestPrefixAll(s string) (string, bool)
LongestPrefixAll returns the longest prefix considering all tree dimensions.
func (*NodeShiftTree[T]) Shape ¶
func (t *NodeShiftTree[T]) Shape(d, v int) *NodeShiftTree[T]
Shape the tree for dimension d to value v.
func (*NodeShiftTree[T]) String ¶
func (t *NodeShiftTree[T]) String() string
func (*NodeShiftTree[T]) WalkPrefixRaw ¶
func (r *NodeShiftTree[T]) WalkPrefixRaw(prefix string, walker func(key string, value T) bool)
type NodeShiftTreeWalker ¶
type NodeShiftTreeWalker[T any] struct { // The tree to walk. Tree *NodeShiftTree[T] // Handle will be called for each node in the main tree. // If the callback returns true, the walk will stop. // The callback can optionally return a callback for the nested tree. Handle func(s string, v T, exact DimensionFlag) (terminate bool, err error) // Optional prefix filter. Prefix string // Enable read or write locking if needed. LockType LockType // When set, no dimension shifting will be performed. NoShift bool // Don't fall back to alternative dimensions (e.g. language). Exact bool // Used in development only. Debug bool // Optional context. // Note that this is copied to the nested walkers using Extend. // This means that walkers can pass data (down) and events (up) to // the related walkers. WalkContext *WalkContext[T] // contains filtered or unexported fields }
func (NodeShiftTreeWalker[T]) Extend ¶
func (r NodeShiftTreeWalker[T]) Extend() *NodeShiftTreeWalker[T]
Extend returns a new NodeShiftTreeWalker with the same configuration as the and the same WalkContext as the original. Any local state is reset.
func (*NodeShiftTreeWalker[T]) ShouldSkip ¶
func (r *NodeShiftTreeWalker[T]) ShouldSkip(s string) bool
ShouldSkip returns whether the given key should be skipped in the walk.
func (*NodeShiftTreeWalker[T]) SkipPrefix ¶
func (r *NodeShiftTreeWalker[T]) SkipPrefix(prefix ...string)
SkipPrefix adds a prefix to be skipped in the walk.
type Shifter ¶
type Shifter[T any] interface { // ForEeachInDimension will call the given function for each value in the given dimension. // If the function returns true, the walk will stop. ForEeachInDimension(n T, d int, f func(T) bool) // Insert inserts new into the tree into the dimension it provides. // It may replace old. // It returns the updated and existing T // and a bool indicating if an existing record is updated. Insert(old, new T) (T, T, bool) // Insert inserts new into the given dimension. // It may replace old. // It returns the updated and existing T // and a bool indicating if an existing record is updated. InsertInto(old, new T, dimension Dimension) (T, T, bool) // Delete deletes T from the given dimension and returns the deleted T and whether the dimension was deleted and if it's empty after the delete. Delete(v T, dimension Dimension) (T, bool, bool) // Shift shifts T into the given dimension // and returns the shifted T and a bool indicating if the shift was successful and // how accurate a match T is according to its dimensions. Shift(v T, dimension Dimension, exact bool) (T, bool, DimensionFlag) }
Shifter handles tree transformations.
type SimpleTree ¶
type SimpleTree[T comparable] struct { // contains filtered or unexported fields }
SimpleTree is a thread safe radix tree that holds T.
func NewSimpleTree ¶
func NewSimpleTree[T comparable]() *SimpleTree[T]
NewSimpleTree creates a new SimpleTree.
func (*SimpleTree[T]) Get ¶
func (tree *SimpleTree[T]) Get(s string) T
func (*SimpleTree[T]) Insert ¶
func (tree *SimpleTree[T]) Insert(s string, v T) T
func (*SimpleTree[T]) Lock ¶ added in v0.126.0
func (tree *SimpleTree[T]) Lock(lockType LockType) func()
func (*SimpleTree[T]) LongestPrefix ¶
func (tree *SimpleTree[T]) LongestPrefix(s string) (string, T)
func (*SimpleTree[T]) WalkPrefix ¶
type Tree ¶
type Tree[T any] interface { Get(s string) T LongestPrefix(s string) (string, T) Insert(s string, v T) T WalkPrefix(lockType LockType, s string, f func(s string, v T) (bool, error)) error }
Tree is a radix tree that holds T.
type TreeShiftTree ¶
type TreeShiftTree[T comparable] struct { // contains filtered or unexported fields }
func NewTreeShiftTree ¶
func NewTreeShiftTree[T comparable](d, length int) *TreeShiftTree[T]
func (*TreeShiftTree[T]) Delete ¶
func (t *TreeShiftTree[T]) Delete(key string)
func (*TreeShiftTree[T]) DeleteAllFunc ¶ added in v0.126.0
func (t *TreeShiftTree[T]) DeleteAllFunc(s string, f func(s string, v T) bool)
func (*TreeShiftTree[T]) DeletePrefix ¶
func (t *TreeShiftTree[T]) DeletePrefix(prefix string) int
func (*TreeShiftTree[T]) Get ¶
func (t *TreeShiftTree[T]) Get(s string) T
func (*TreeShiftTree[T]) Insert ¶
func (t *TreeShiftTree[T]) Insert(s string, v T) T
func (*TreeShiftTree[T]) LenRaw ¶ added in v0.126.0
func (t *TreeShiftTree[T]) LenRaw() int
func (*TreeShiftTree[T]) Lock ¶
func (t *TreeShiftTree[T]) Lock(lockType LockType) func()
func (*TreeShiftTree[T]) LongestPrefix ¶
func (t *TreeShiftTree[T]) LongestPrefix(s string) (string, T)
func (TreeShiftTree[T]) Shape ¶
func (t TreeShiftTree[T]) Shape(d, v int) *TreeShiftTree[T]
func (*TreeShiftTree[T]) WalkPrefix ¶
func (*TreeShiftTree[T]) WalkPrefixRaw ¶ added in v0.126.0
type WalkConfig ¶
type WalkConfig[T any] struct { // Optional prefix filter. Prefix string // Callback will be called for each node in the tree. // If the callback returns true, the walk will stop. Callback func(ctx *WalkContext[T], s string, t T) (bool, error) // Enable read or write locking if needed. LockType LockType // When set, no dimension shifting will be performed. NoShift bool // Exact will only match exact in the current dimension (e.g. language), // and will not look for alternatives. Exact bool }
type WalkContext ¶
type WalkContext[T any] struct { HooksPost []func() error // contains filtered or unexported fields }
WalkContext is passed to the Walk callback.
func (*WalkContext[T]) AddEventListener ¶
func (ctx *WalkContext[T]) AddEventListener(event, path string, handler func(*Event[T]))
AddEventListener adds an event listener to the tree. Note that the handler func may not add listeners.
func (*WalkContext[T]) AddPostHook ¶
func (ctx *WalkContext[T]) AddPostHook(handler func() error)
AddPostHook adds a post hook to the tree. This will be run after the tree has been walked.
func (*WalkContext[T]) Data ¶
func (ctx *WalkContext[T]) Data() *SimpleTree[any]
func (*WalkContext[T]) HandleEvents ¶
func (ctx *WalkContext[T]) HandleEvents() error
func (*WalkContext[T]) HandleEventsAndHooks ¶
func (ctx *WalkContext[T]) HandleEventsAndHooks() error
func (*WalkContext[T]) SendEvent ¶
func (ctx *WalkContext[T]) SendEvent(event *Event[T])
SendEvent sends an event up the tree.
type WalkableTree ¶
type WalkableTree[T any] interface { WalkPrefixRaw(prefix string, walker func(key string, value T) bool) }
WalkableTree is a tree that can be walked.
type WalkableTrees ¶
type WalkableTrees[T any] []WalkableTree[T]
func (WalkableTrees[T]) WalkPrefixRaw ¶
func (t WalkableTrees[T]) WalkPrefixRaw(prefix string, walker func(key string, value T) bool)