https://github.com/varugasu/go-heap
Heap implementation based on container/heap using Generics
https://github.com/varugasu/go-heap
data-structures generics go golang heap
Last synced: 2 months ago
JSON representation
Heap implementation based on container/heap using Generics
- Host: GitHub
- URL: https://github.com/varugasu/go-heap
- Owner: varugasu
- License: mit
- Created: 2022-05-22T17:42:38.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-28T19:22:31.000Z (almost 3 years ago)
- Last Synced: 2024-12-27T06:09:50.326Z (4 months ago)
- Topics: data-structures, generics, go, golang, heap
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Heap with Generics
A library to work with **Heaps** using **Generics**
The current heap solution in `container/heap` relies on the following interfaces:
```go
package sorttype Interface interface {
Len() int
Less(i, j int) bool
Swap(i, j int)
}
``````go
package heaptype Interface interface {
sort.Interface
Push(x any)
Pop() any
}
```But with generics with **do not need** to **implement Interfaces**. Any slice will work as long as we define a `Less` function.
```go
type Less[T any] func(t1, t2 T) boolfunc Heapify[T any](t []T, less Less[T])
```This `Less` function allow us to create **any kind of Heap**, even with **custom algorithms** for complex data structures