datastructure

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Heap

type Heap[T any] interface {
	Insert(value T)       // Insert or update an element in the heap
	Extract() (T, error)  // Extract the top element
	Peek() (T, error)     // Get the top element without removing it
	Remove(value T) error // Remove an element from the heap
	Len() int             // Get the size of the heap
}

Heap interface exposing public methods.

func NewHeap

func NewHeap[T any](hType HeapType, compare func(a, b T) int) Heap[T]

NewHeap creates a new heap (MinHeap/MaxHeap).

type HeapType

type HeapType int

HeapType represents the type of heap (Min or Max).

const (
	MinHeap HeapType = iota // Min-Heap (smallest value at the top)
	MaxHeap                 // Max-Heap (largest value at the top)
)

type Set

type Set[T comparable] interface {
	Add(value T) bool
	Remove(value T) bool
	Contains(value T) bool
	Values() []T
}

func NewSet

func NewSet[T comparable](keys ...T) Set[T]

NewSet returns a new Set.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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