



Fast genericHeap in Golang. Create your Heap data structure with any data type. Set yourcompression function to sort your data with any field that you want. Push, Pop and Update yourdata in heap without any problems. Write your equality function to filterthe elements that you want to update.
Pyramid is built withGolang internal libraries and does not include any externallibraries.
Getpyramid package.
go get github.com/amirhnajafiz/pyramid
Now you can use pyramid to build any type ofHeap.
Creating amax-heap of type Integer.
package mainimport ("fmt""github.com/amirhnajafiz/pyramid")funcmain() {// initializing a heap with comparator functionh:= pyramid.NewHeap[int](func(aint,bint)bool {returna>b})// Using push methodh.Push(2)h.Push(12)h.Push(4)h.Push(90)h.Push(20)// Using length methodforh.Length()>0 {// Using pop methodfmt.Printf("%d ",h.Pop().(int))}}
Creating amin-heap of type customData.
// Creating a custom Data struct type.typeDatastruct {PriorityintDatastring}funcmain() {// Creating a heap of Data type.h:= pyramid.NewHeap[Data](func(aData,bData)bool {returna.Priority<b.Priority})// Push data into heap.fori:=0;i<10;i++ {h.Push(Data{Priority:i,Data:fmt.Sprintf("data: %d",i+1)})}forh.Length()>0 {fmt.Printf("%s\n",h.Pop().(Data).Data)}}
You can update any item in the list, also you can define aequal function to check the equality of your objects.
special:=675h.Push(special)fori:=2;i<100;i++ {h.Push(i)}h.Update(special,0,func(aint,bint)bool {returna==b})
If we have 10000 items, and we want to update them 1 Million times, it wouldonly take 12 seconds:
go run load-test/update/main.go -push 10000 -update 1000000
testing: 10000 numbersstart: Oct 16 14:42:34.752done: Oct 16 14:42:52.064final size: 10000min: 2