Skip to content

Latest commit

 

History

History
28 lines (20 loc) · 799 Bytes

README.md

File metadata and controls

28 lines (20 loc) · 799 Bytes

generic heap

Binary Heaps using Generics

Rationale

I realized heaps using generics would be faster than heaps using the standard library because those heaps use interfaces and reflection.

How to use

To create a heap with this package, you need a backing array of any type and a HeapProperty function.

The HeapProperty function takes two elements of the same type as your backing array and returns a boolean.

Think of it as returning the relationship between parent and child that you want the heap to maintain.

For a min-heap of two ints, the function would look like this:

func(parent, child int) bool {
    return parent < child
}

For a max-heap of two ints, the function would look like this:

func(parent, child int) bool {
    return parent < child
}