Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Tree ¶
A loser tree is a binary tree laid out such that nodes N and N+1 have parent N/2. We store M leaf nodes in positions M...2M-1, and M-1 internal nodes in positions 1..M-1. Node 0 is a special node, containing the winner of the contest.
func New ¶
func New[E any, S Sequence](sequences []S, maxVal E, at func(S) E, less func(E, E) bool, close func(S)) *Tree[E, S]
New returns a new loser tree that merges the given sequences. The sequences must be sorted according to the less function already. The maxVal is used to initialize the tree. The at function returns the current value of the sequence. The less function compares two values. The close function is called on each sequence when the tree is closed or when a sequence returns false from Next(). If any sequence returns an error from Err() after Next() = false, the tree will stop and return that error in Err(). Examples:
tree := loser.New(...) defer tree.Close() for tree.Next() { value := tree.Winner().At() ... } if err := tree.Err(); err != nil { ... }
func (*Tree[E, S]) Close ¶
func (t *Tree[E, S]) Close()
Call the close function on all sequences that are still open.