Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSegmentTree ¶ added in v1.0.5
func NewSegmentTree[T constraints.Ordered](aggFunc AggregateFunc[T], identityEl T) *segmentTreeImpl[T]
func VisitInOrder ¶
func VisitInOrder[T constraints.Ordered](node *Node[T], call func(T))
in-order visit of node
Types ¶
type AggregateFunc ¶ added in v1.1.0
type AggregateFunc[T constraints.Ordered] func(a, b T) T
type BST ¶
type BST[T constraints.Ordered] interface { // Adds new elem to the tree, will not check if same val already exists Insert(T) *Node[T] // Returns the first node that matches Search(T) *Node[T] // In-order traversal of tree copied to slice ToSlice() []T // In-order traversal of tree, calling the func for each element visited Traverse(func(T)) // Returns the largest value node that is smaller than or equal to the given value. Floor(T) *Node[T] // Returns the smallest value node that is larger than or equal to the given value. Ceiling(T) *Node[T] }
Binary Search Tree https://en.wikipedia.org/wiki/Binary_search_tree Element comparison is based on OrderFunc provided to NewBST method
func NewBST ¶
func NewBST[T constraints.Ordered]() BST[T]
type BinaryIndexTree ¶ added in v1.0.5
type BinaryIndexTree struct {
// contains filtered or unexported fields
}
func (BinaryIndexTree) Query ¶ added in v1.0.5
func (bit BinaryIndexTree) Query(x int) int
func (BinaryIndexTree) Update ¶ added in v1.0.5
func (bit BinaryIndexTree) Update(x, val int)
type BinaryIndexTreeInterface ¶ added in v1.0.5
type BinaryIndexTreeInterface interface { //add "val" at index "x" Update(x, val int) //returns the sum of first x elements Query(x int) int }
func NewBinaryIndexTree ¶ added in v1.0.5
func NewBinaryIndexTree(size int) BinaryIndexTreeInterface
type Node ¶
type Node[T constraints.Ordered] struct { Left *Node[T] Right *Node[T] Data T }
func NewNode ¶
func NewNode[T constraints.Ordered](data T) *Node[T]
type SegmentTree ¶ added in v1.0.5
type SegmentTree[T constraints.Ordered] interface { UpdateRange(start, end int, updateFunc UpdateFunc[T]) QueryRange(start, end int) T }
type UpdateFunc ¶ added in v1.1.0
type UpdateFunc[T constraints.Ordered] func(current T) T
Click to show internal directories.
Click to hide internal directories.