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

Remove unnecessary heap allocation in heap data structure implementation #148

Merged
merged 1 commit into from
Oct 6, 2020

Conversation

rhysd
Copy link
Contributor

@rhysd rhysd commented Oct 6, 2020

Current implementation of heap, min-heap and max-heap are using closures which are allocated dynamically on heap memory for comparing elements. However, they are not necessary to be closures here because a comparison predicate of heap data structure does not have its state. It's a pure function which takes two elements and returns boolean value. For such case, simply a function pointer is appropriate. It does not require any heap allocation.

@AnshulMalik AnshulMalik merged commit 56b7814 into TheAlgorithms:master Oct 6, 2020
kczimm pushed a commit to kczimm/Rust that referenced this pull request Oct 11, 2020
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.

2 participants