-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Poplar heap is probably not what you want #23
Labels
Projects
Comments
Thanks for your advise. I should update those codes. \o/ |
The v2.1 update has adopted |
After adapting the EASTL's implementation, I tested the heap functions using example codes from the C++ guidances and the implementation worked exactly same with those examples. Thus, I consider that error has been fixed. C++ Referenceimport * as std from "tstl";
function main(): void
{
let v: std.Vector<number> = new std.Vector([10, 20, 30, 5, 15]);
std.make_heap(v.begin(), v.end());
console.log("initial max heap:", v.front());
std.pop_heap(v.begin(), v.end());
v.pop_back();
console.log("max heap after pop", v.front());
v.push_back(99);
std.push_heap(v.begin(), v.end());
console.log("max heap after push", v.front());
std.sort_heap(v.begin(), v.end());
console.log("final sorted range:", v.data());
}
main(); CPP Referenceimport * as std from "tstl";
function main(): void
{
let v: std.Vector<number> = new std.Vector();
v.push(3, 1, 4, 1, 5, 9);
console.log("initially, v:", v.data());
std.make_heap(v.begin(), v.end());
console.log("after make_heap:", v.data());
std.pop_heap(v.begin(), v.end());
console.log("largest element:", v.back());
v.pop_back();
console.log("after removing the largest element:", v.data());
}
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I noticed that you use my poplar heap project to implement the heap algorithms. I don't have a problem with that, but it is probably not what you want:
pop_heap
(which is a O(log n) operation) but is not available out-of-the-box as with a max heap. The poplar heap was described in a paper trying to implement a new kind of heapsort, so not having O(1) access to the max element didn't matter, but in the case of STL-like generic heap algorithms it surely matters, be it only to implement a priority queue.Well, now it's up to you what you want to do :p
The text was updated successfully, but these errors were encountered: