Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Heap #48

Merged
merged 8 commits into from
Feb 25, 2023
Merged

Generic Heap #48

merged 8 commits into from
Feb 25, 2023

Conversation

patrick-ogrady
Copy link
Contributor

@patrick-ogrady patrick-ogrady commented Feb 25, 2023

  • Implement a single min/max heap instead of adding one per type (use generics)
  • Add wrapper functions for heap.Push, heap.Remove, and heap.Pop so users of this package don't need to use containers.Heap as well
    • We only make the "incorrect" functions directly accessible on the innerHeap, which cannot be called outside of the package.

@patrick-ogrady
Copy link
Contributor Author

Going to wrap the inner heap struct so I can use Push/Pop instead of Add/Remove

// a specific index instead of using `containers.heap`,
// which makes using this heap less error-prone.
func (h *Heap[I, V]) Pop() *Entry[I, V] {
if len(h.ih.items) == 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We directly call into ih to avoid the overhead of another function call here

@patrick-ogrady patrick-ogrady merged commit 721f8b6 into main Feb 25, 2023
@patrick-ogrady patrick-ogrady deleted the heap-package branch February 25, 2023 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move generic heap to its own package and remove the one in mempool and tokenvm/controller
1 participant