MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / NewAny

Function NewAny

structure/heap/heap.go:24–31  ·  view source on GitHub ↗

NewAny gives a new heap object. element can be anything, but must provide less function.

(less func(a, b T) bool)

Source from the content-addressed store, hash-verified

22
23// NewAny gives a new heap object. element can be anything, but must provide less function.
24func NewAny[T any](less func(a, b T) bool) (*Heap[T], error) {
25 if less == nil {
26 return nil, errors.New("less func is necessary")
27 }
28 return &Heap[T]{
29 lessFunc: less,
30 }, nil
31}
32
33// Push pushes the element t onto the heap.
34// The complexity is O(log n) where n = h.Len().

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected