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

Poplar heap is probably not what you want #23

Closed
Morwenn opened this issue Nov 23, 2018 · 3 comments
Closed

Poplar heap is probably not what you want #23

Morwenn opened this issue Nov 23, 2018 · 3 comments
Labels
bug Something isn't working C++11 enhancement New feature or request
Projects

Comments

@Morwenn
Copy link

Morwenn commented Nov 23, 2018

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:

  • The C++ specification mandates that the heap algorithms use a max heap, and poplar heap is a different kind of heap altogether.
  • The poplar heap as I implemented it doesn't give you O(1) access to the max element of the heap: it is extracted when calling 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.
  • Even if poplar heap was fine, it is actually slower for pretty much everything than a max heap (and I tried to make it as fast as possible...), so it doesn't really offer anything ^^'

Well, now it's up to you what you want to do :p

@samchon
Copy link
Owner

samchon commented Nov 23, 2018

Thanks for your advise. I should update those codes. \o/

@samchon samchon added this to To do in v2.1 Update via automation Nov 23, 2018
@samchon samchon added the bug Something isn't working label Nov 23, 2018
@samchon samchon moved this from To do to In progress in v2.1 Update Dec 3, 2018
@samchon samchon added enhancement New feature or request C++11 labels Dec 3, 2018
@samchon
Copy link
Owner

samchon commented Dec 7, 2018

@samchon samchon moved this from In progress to On review in v2.1 Update Dec 7, 2018
@samchon samchon moved this from On review to Done in v2.1 Update Dec 7, 2018
@samchon samchon moved this from Done to On review in v2.1 Update Dec 7, 2018
@samchon
Copy link
Owner

samchon commented Dec 7, 2018

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++ Reference

import * 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 Reference

import * 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();

@samchon samchon closed this as completed Dec 7, 2018
v2.1 Update automation moved this from On review to Done Dec 7, 2018
@samchon samchon moved this from Done to In progress in v2.1 Update Dec 12, 2018
@samchon samchon reopened this Dec 12, 2018
@samchon samchon closed this as completed Dec 12, 2018
v2.1 Update automation moved this from In progress to Done Dec 12, 2018
@samchon samchon added C++20 and removed C++20 labels Dec 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working C++11 enhancement New feature or request
Projects
No open projects
v2.1 Update
  
Done
Development

No branches or pull requests

2 participants