heap

package module
v0.0.0-...-d0ebd69 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 0 Imported by: 0

README

Generic Heap Package

A flexible and customizable generic heap package for Go that empowers you to create heaps with any type of values, providing the freedom to customize the heap structure based on your specific requirements.

Installation

go get github.com/SurajKadam7/heap

Reference Video

Watch this YouTube video for a detailed understanding of heap

Example :

package main

import (
	"fmt"

	"github.com/SurajKadam7/heap"
)

type Rank struct {
	Name  string
	Score int
}

func main() {

	minHeapFunc := func(heap []Rank, parent, child int) bool {
		return heap[parent].Score < heap[child].Score
	}

	minHeap := heap.New[Rank](minHeapFunc)

	minHeap.Push(Rank{
		Name:  "ABC",
		Score: 30,
	})

	minHeap.Push(Rank{
		Name: "EFG",
		Score: 20,
	})

	fmt.Println(minHeap.Pop())
	fmt.Println(minHeap.Pop())
	fmt.Println(minHeap.Pop())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Heapify

func Heapify[T any](arr []T, f HeapFunc[T]) *heap[T]

func New

func New[T any](f HeapFunc[T]) *heap[T]

Types

type HeapFunc

type HeapFunc[T any] func(heap []T, parent, child int) bool

HeapFunc will table three arguments and return bool as a result exmple of HeapFunc MinHeap := func(heap []int, parent, child int) bool { return heap[child] >= heap[parent] } MaxHeap := func(heap []int, parent, child int) bool { return heap[child] <= heap[parent] }

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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