lemire / FastPriorityQueue.js

a fast heap-based priority queue in JavaScript
Apache License 2.0
357 stars 57 forks source link

add `toArray` function #18

Closed Amorites closed 5 years ago

Amorites commented 5 years ago

It's common to use array or object for rendering.

lemire commented 5 years ago

What would "toArray" do, precisely?

Amorites commented 5 years ago

As a opposite operation of headpify. Convert the fpq to array in order.

Maybe like:

function transformFPQToArray(fpq) {
    const temp = fpq.clone();
    const ret = [];
    while (!temp.isEmpty()) {
        ret.push(temp.poll());
    }
    return ret;
}
Amorites commented 5 years ago

Maybe

fpq.kSmallest(fpq.size)

is better