doctree

package
v0.123.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateKey

func ValidateKey(key string) error

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

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 LockType

type LockType int
const (
	LockTypeNone LockType = iota
	LockTypeRead
	LockTypeWrite
)

type MutableTree

type MutableTree interface {
	Delete(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) Delete

func (t MutableTrees) Delete(key string)

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) 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 multipled 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)

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]) 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, bool)

func (*NodeShiftTree[T]) InsertIntoValuesDimension

func (r *NodeShiftTree[T]) InsertIntoValuesDimension(s string, v T) (T, bool)

func (*NodeShiftTree[T]) InsertRawWithLock

func (r *NodeShiftTree[T]) InsertRawWithLock(s string, v any) (any, bool)

func (*NodeShiftTree[T]) InsertWithLock

func (r *NodeShiftTree[T]) InsertWithLock(s string, v T) (T, 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.

func (*NodeShiftTreeWalker[T]) Walk

func (r *NodeShiftTreeWalker[T]) Walk(ctx context.Context) error

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 a T (can be the same as old).
	Insert(old, new T) T

	// Insert inserts new into the given dimension.
	// It may replace old.
	// It returns a T (can be the same as old).
	InsertInto(old, new T, dimension Dimension) T

	// Delete deletes T from the given dimension and returns whether the dimension was deleted and if  it's empty after the delete.
	Delete(v T, dimension Dimension) (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 any] struct {
	// contains filtered or unexported fields
}

SimpleTree is a thread safe radix tree that holds T.

func NewSimpleTree

func NewSimpleTree[T any]() *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]) LongestPrefix

func (tree *SimpleTree[T]) LongestPrefix(s string) (string, T)

func (*SimpleTree[T]) WalkPrefix

func (tree *SimpleTree[T]) WalkPrefix(lockType LockType, s string, f func(s string, v T) (bool, error)) error

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 any] struct {
	// contains filtered or unexported fields
}

func NewTreeShiftTree

func NewTreeShiftTree[T any](d, length int) *TreeShiftTree[T]

func (*TreeShiftTree[T]) Delete

func (t *TreeShiftTree[T]) Delete(key string)

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]) Lock

func (t *TreeShiftTree[T]) Lock(writable bool) (commit 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 (t *TreeShiftTree[T]) WalkPrefix(lockType LockType, s string, f func(s string, v T) (bool, error)) error

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 WalkFunc

type WalkFunc[T any] func(string, T) (bool, error)

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL