tree

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHashFunc

func GetHashFunc[T any]() func(T) uintptr

GetHashFunc returns a cached hash function for type T.

func TypeKeyOf

func TypeKeyOf[T any]() uintptr

TypeKeyOf returns a uintptr that uniquely identifies the type T, suitable for use as a sync.Map key. It extracts the type-descriptor word from an eface wrapping *T, which is a compile-time constant. Using uintptr instead of reflect.Type avoids the expensive nilinterhash→typehash chain that sync.Map incurs when hashing interface keys.

func UseLHS

func UseLHS[T any](a, _ T) T

UseLHS returns its LHS arg.

func UseRHS

func UseRHS[T any](_, b T) T

UseRHS returns its RHS arg.

Types

type Builder

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

Builder[T] provides a more efficient way to build nodes incrementally.

func NewBuilder

func NewBuilder[T any](int) *Builder[T]

func (*Builder[T]) Add

func (b *Builder[T]) Add(v T)

func (*Builder[T]) Borrow

func (b *Builder[T]) Borrow() Tree[T]

func (*Builder[T]) Count

func (b *Builder[T]) Count() int

func (*Builder[T]) Finish

func (b *Builder[T]) Finish() Tree[T]

func (Builder[T]) Format

func (b Builder[T]) Format(state fmt.State, verb rune)

func (*Builder[T]) Get

func (b *Builder[T]) Get(el T) *T

func (*Builder[T]) Remove

func (b *Builder[T]) Remove(v T)

func (Builder[T]) String

func (b Builder[T]) String() string

type CombineArgs

type CombineArgs[T any] struct {
	*EqArgs[T]
	// contains filtered or unexported fields
}

func CachedNPCombineArgs

func CachedNPCombineArgs[T any]() *CombineArgs[T]

CachedNPCombineArgs returns a cached default CombineArgs with non-parallel behaviour and same set to the type's equality function. Suitable for Set.With where Equal is full equality and identical elements should not cause allocation.

func DefaultNPCombineArgs

func DefaultNPCombineArgs[T any]() *CombineArgs[T]

DefaultNPCombineArgs provides default combiner with non-parallel behaviour.

func DefaultNPKeyCombineArgs

func DefaultNPKeyCombineArgs[T any]() *CombineArgs[T]

func NewCombineArgs

func NewCombineArgs[T any](ea *EqArgs[T], combine func(a, b T) T) *CombineArgs[T]

func NewCombineArgsWithSame

func NewCombineArgsWithSame[T any](ea *EqArgs[T], combine func(a, b T) T, same func(a, b T) bool) *CombineArgs[T]

NewCombineArgsWithSame creates CombineArgs with a full-equality check for no-op detection. Use this when Equal is weaker than structural equality (e.g. Map's key-only equality).

func (*CombineArgs[T]) Flip

func (a *CombineArgs[T]) Flip() *CombineArgs[T]

Flip returns the arguments with the combining function's operands reversed. The pair is built when the arguments are constructed, not on first use: Combine runs on several goroutines once a tree is large enough to fan out, and a lazily assigned field would be a data race between them.

type EqArgs

type EqArgs[T any] struct {
	NodeArgs
	EqHash[T]
	// contains filtered or unexported fields
}

func DefaultNPEqArgs

func DefaultNPEqArgs[T any]() *EqArgs[T]

DefaultNPEqArgs provides default equality with non-parallel behaviour. The result is cached per type T since Gauge is a constant (NonParallel = -1) and EqArgs is read-only during Get/Without.

func DefaultNPKeyEqArgs

func DefaultNPKeyEqArgs[T any]() *EqArgs[T]

func NewDefaultEqArgs

func NewDefaultEqArgs[T any](gauge depth.Gauge) *EqArgs[T]

NewDefaultEqArgs creates EqArgs using the default resolved hash and equality functions.

func NewDefaultKeyEqArgs

func NewDefaultKeyEqArgs[T any](gauge depth.Gauge) *EqArgs[T]

func NewEqArgs

func NewEqArgs[T any](gauge depth.Gauge, ops EqHash[T]) *EqArgs[T]

NewEqArgs creates EqArgs from an EqHash implementation.

type EqHash

type EqHash[T any] interface {
	Equal(a, b T) bool
	Hash(a T) uintptr
}

EqHash provides equality and hashing operations for tree elements.

type Iterator

type Iterator[T any] interface {
	Next() bool
	Value() T
}

Iterator provides for iterating over a Set.

func Empty

func Empty[T any]() Iterator[T]

Empty is the empty iterator.

type Less

type Less[T any] func(a, b T) bool

Less dictates the order of two elements.

type NodeArgs

type NodeArgs struct {
	depth.Gauge
}

func NewNodeArgs

func NewNodeArgs(gauge depth.Gauge) NodeArgs

type Tree

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

func Map

func Map[T, U any](t Tree[T], f func(v T) U) (out Tree[U])

func (Tree[T]) Combine

func (t Tree[T]) Combine(args *CombineArgs[T], u Tree[T]) (out Tree[T])

func (Tree[T]) Count

func (t Tree[T]) Count() int

func (Tree[T]) Difference

func (t Tree[T]) Difference(args *EqArgs[T], u Tree[T]) (out Tree[T])

func (Tree[T]) Equal

func (t Tree[T]) Equal(args *EqArgs[T], u Tree[T]) bool

func (Tree[T]) Format

func (t Tree[T]) Format(f fmt.State, verb rune)

func (Tree[T]) Gauge

func (t Tree[T]) Gauge() depth.Gauge

func (Tree[T]) Get

func (t Tree[T]) Get(v T) *T

func (Tree[T]) GetWith

func (t Tree[T]) GetWith(args *EqArgs[T], v T) *T

GetWith is like Get but accepts pre-built EqArgs, avoiding the per-call allocation of DefaultNPEqArgs.

func (Tree[T]) H0

func (t Tree[T]) H0() uintptr

func (Tree[T]) Intersection

func (t Tree[T]) Intersection(args *EqArgs[T], u Tree[T]) (out Tree[T])

func (Tree[T]) Iterator

func (t Tree[T]) Iterator() Iterator[T]

func (Tree[T]) OrderedIterator

func (t Tree[T]) OrderedIterator(less Less[T], n int) Iterator[T]

func (Tree[T]) Reduce

func (t Tree[T]) Reduce(args NodeArgs, r func(values ...T) T) (_ T, _ bool)

func (Tree[T]) String

func (t Tree[T]) String() string

func (Tree[T]) SubsetOf

func (t Tree[T]) SubsetOf(args *EqArgs[T], u Tree[T]) bool

func (Tree[T]) Vet

func (t Tree[T]) Vet()

func (Tree[T]) Where

func (t Tree[T]) Where(args *WhereArgs[T]) (out Tree[T])

func (Tree[T]) With

func (t Tree[T]) With(v T) (out Tree[T])

func (Tree[T]) WithWith

func (t Tree[T]) WithWith(args *CombineArgs[T], v T) (out Tree[T])

WithWith is like With but uses pre-built CombineArgs, avoiding per-call allocation of equality/hash functions and enabling no-op detection via CombineArgs.same.

func (Tree[T]) Without

func (t Tree[T]) Without(v T) (out Tree[T])

func (Tree[T]) WithoutWith

func (t Tree[T]) WithoutWith(args *EqArgs[T], v T) (out Tree[T])

WithoutWith is like Without but accepts pre-built EqArgs, avoiding the per-call allocation of DefaultNPEqArgs.

type WhereArgs

type WhereArgs[T any] struct {
	NodeArgs

	Pred func(elem T) bool
}

Jump to

Keyboard shortcuts

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