btree

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT, Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BTree

type BTree[T comparable] struct {
	// contains filtered or unexported fields
}

BTree is an ordered set items

func New

func New[T comparable](less func(a, b T) bool) *BTree[T]

New returns a new BTree

func (*BTree[T]) Ascend

func (tr *BTree[T]) Ascend(pivot T, iter func(item T) bool)

Ascend the tree within the range [pivot, last] Pass nil for pivot to scan all item in ascending order Return false to stop iterating

func (*BTree[T]) Delete

func (tr *BTree[T]) Delete(key interface{}) interface{}

Delete a value for a key

func (*BTree[T]) DeleteHint

func (tr *BTree[T]) DeleteHint(key interface{}, hint *PathHint) interface{}

DeleteHint deletes a value for a key using a path hint

func (*BTree[T]) Descend

func (tr *BTree[T]) Descend(pivot T, iter func(item T) bool)

Descend the tree within the range [pivot, first] Pass nil for pivot to scan all item in descending order Return false to stop iterating

func (*BTree[T]) Get

func (tr *BTree[T]) Get(key interface{}) interface{}

Get a value for key

func (*BTree[T]) GetHint

func (tr *BTree[T]) GetHint(key interface{}, hint *PathHint) interface{}

GetHint gets a value for key using a path hint

func (*BTree[T]) Height

func (tr *BTree[T]) Height() int

Height returns the height of the tree. Returns zero if tree has no items.

func (*BTree[T]) Len

func (tr *BTree[T]) Len() int

Len returns the number of items in the tree

func (*BTree[T]) Less

func (tr *BTree[T]) Less(a, b T) bool

Less is a convenience function that performs a comparison of two items using the same "less" function provided to New.

func (*BTree[T]) Load

func (tr *BTree[T]) Load(item T) (T, bool)

Load is for bulk loading pre-sorted items

func (*BTree[T]) Max

func (tr *BTree[T]) Max() (T, bool)

Max returns the maximum item in tree. Returns nil if the tree has no items.

func (*BTree[T]) Min

func (tr *BTree[T]) Min() (T, bool)

Min returns the minimum item in tree. Returns nil if the tree has no items.

func (*BTree[T]) PopMax

func (tr *BTree[T]) PopMax() (T, bool)

PopMax removes the minimum item in tree and returns it. Returns nil if the tree has no items.

func (*BTree[T]) PopMin

func (tr *BTree[T]) PopMin() (T, bool)

PopMin removes the minimum item in tree and returns it. Returns nil if the tree has no items.

func (*BTree[T]) Set

func (tr *BTree[T]) Set(item T) (prev T)

Set or replace a value for a key

func (*BTree[T]) SetHint

func (tr *BTree[T]) SetHint(item T, hint *PathHint) (prev T)

SetHint sets or replace a value for a key using a path hint

func (*BTree[T]) Walk

func (tr *BTree[T]) Walk(iter func(item []T))

Walk iterates over all items in tree, in order. The items param will contain one or more items.

type PathHint

type PathHint struct {
	// contains filtered or unexported fields
}

PathHint is a utility type used with the *Hint() functions. Hints provide faster operations for clustered keys.

Jump to

Keyboard shortcuts

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