tree

package
v0.0.0-...-54d7d0b Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 2 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MergeID16

func MergeID16(left uint16, leftLength uint8, right uint16, rightLength uint8) (uint16, uint8)

func MergeID32

func MergeID32(left uint32, leftLength uint8, right uint32, rightLength uint8) (uint32, uint8)

func MergeID64

func MergeID64(left uint64, leftLength uint8, right uint64, rightLength uint8) (uint64, uint8)

Types

type Enries

type Enries[T1 any] []Entry

type Entries

type Entries []Entry

type Entry

type Entry interface {
	ID() ID
	Labels() labels.Set
	String() string
	Equal(e2 Entry) bool
}

func NewEntry

func NewEntry(id ID, labels labels.Set) Entry

type FilterFunc

type FilterFunc[T any] func(payload T) bool

FilterFunc[T] is called on each result to see if it belongs in the resulting set

type ID

type ID interface {
	Copy() ID
	Length() uint8
	ID() uint64
	Matches(id uint64) uint8
	ShiftLeft(shiftCount uint8) ID
	IsLeftBitSet() bool
	String() string
	Overlaps(ID) bool
	Compare(ID) int
	Less(ID) bool
	Next() ID
	Prev() ID
	Mask(l uint8) (ID, error)
	Masked() ID
}

type IsLeftBitSetFn

type IsLeftBitSetFn func(id uint64) bool

type MatchesFunc

type MatchesFunc[T any] func(payload T, val T) bool

MatchesFunc[T] is called to check if tag data matches the input value

type Range

type Range interface {
	From() ID
	To() ID
	SetTo(ID) Range
	SetFrom(ID) Range
	String() string
	IsValid() bool
	IsZero() bool
	IDs() []ID
	Less(other Range) bool
	AppendIDs(dst []ID) []ID

	EntirelyBefore(other Range) bool
	CoveredBy(other Range) bool
	InMiddleOf(other Range) bool
	OverlapsStartOf(other Range) bool
	OverlapsEndOf(other Range) bool
}

type Tree

type Tree[T any] struct {
	// contains filtered or unexported fields
}

func NewTree

func NewTree[T any](isLeftBitSetFn IsLeftBitSetFn, length uint8) *Tree[T]

func (*Tree[T]) Add

func (r *Tree[T]) Add(id ID, val T, matchFunc MatchesFunc[T]) (bool, int)

Add adds a tag to the tree - if matchFunc is non-nil, it will be used to ensure uniqueness at this node - returns whether the val count at this address was increased, and how many vals at this address

func (*Tree[T]) Clone

func (r *Tree[T]) Clone() *Tree[T]

Clone creates an identical copy of the tree - Note: the items in the tree are not deep copied

func (*Tree[T]) Delete

func (r *Tree[T]) Delete(id ID, matchFunc MatchesFunc[T], matchVal T) int

Delete a tag from the tree if it matches matchVal, as determined by matchFunc. Returns how many tags are removed - use DeleteWithBuffer if you can reuse slices, to cut down on allocations

func (*Tree[T]) DeleteWithBuffer

func (r *Tree[T]) DeleteWithBuffer(buf []T, id ID, matchFunc MatchesFunc[T], matchVal T) int

DeleteWithBuffer a tag from the tree if it matches matchVal, as determined by matchFunc. Returns how many tags are removed - uses input slice to reduce allocations

func (*Tree[T]) Iterate

func (r *Tree[T]) Iterate() *TreeIterator[T]

Iterate returns an iterator to find all nodes from a tree. It is important for the tree to not be modified while using the iterator.

func (*Tree[T]) PrintNodes

func (r *Tree[T]) PrintNodes(nodeIndex uint)

note: this is only used for unit testing nolint

func (*Tree[T]) PrintValues

func (r *Tree[T]) PrintValues()

note: this is only used for unit testing nolint

func (*Tree[T]) Set

func (r *Tree[T]) Set(id ID, val T) (bool, int)

Set the single value for a node - overwrites what's there Returns whether the val count at this id was increased, and how many vals at this id

type TreeIterator

type TreeIterator[T any] struct {
	// contains filtered or unexported fields
}

TreeIteratorV4[T] is a stateful iterator over a tree.

func (*TreeIterator[T]) Next

func (iter *TreeIterator[T]) Next() bool

Next jumps to the next element of a tree. It returns false if there is none.

func (*TreeIterator[T]) Vals

func (iter *TreeIterator[T]) Vals() []T

Tags returns the current tags for the iterator. This is not a copy and the result should not be used outside the iterator.

func (*TreeIterator[T]) ValsWithBuffer

func (iter *TreeIterator[T]) ValsWithBuffer(ret []T) []T

TagsWithBuffer returns the current tags for the iterator. To avoid allocation, it uses the provided buffer.

type UpdatesFunc

type UpdatesFunc[T any] func(payload T) T

UpdatesFunc[T] is called to update the tag value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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