ParallelSTL
ParallelSTL copied to clipboard
Is_heap implementation is flawed in certain cases
Correct me if I'm wrong, but I don't think the parallel is_heap will work. I can't actually compile the code to test it due to some weird constexpr errors in execution_policy, but here's what I believe is wrong:
Say you have the heap: 9 8 6 7 4 5 2 0 3 1
, which when visualized looks like
Now say you call parallelized is_heap, and your heap is split into 4 separate partitions. These become
9 8 6
7 4 5
2 0 3
1
The problem is that 2 0 3
is not a max heap, but the algorithm will call std::is_heap on that range. the partitions are treating the beginning part as the head node, which is wrong in this case. The first two partitions got lucky because they chose a node which happened to have children, but in the case of a non-complete heap tree this algorithm would fail.
You are right, the implementation is incorrect. Most of the algorithms are not fully implemented, this repository contains a skeleton implementation to validate the API from the proposal. The algorithms which are implemented have unit tests in test
, every algorithm which does not have a test probably hasn't been implemented (std::is_heap
doesn't have a unit test).
You are very welcome to submit a parallel implementation to this repository if you have one.