lemire / FastPriorityQueue.js

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

Iterate #10

Closed sm2017 closed 7 years ago

sm2017 commented 7 years ago

How can I iterate over queue? I have a scenario when I lost connection I must iterate over queue and remove some items (Not all)

lemire commented 7 years ago

Can you elaborate?

Some pointers:

sm2017 commented 7 years ago

I have object={ priority:integer , durable:boolean} , I add object to queue and poll it when I need Sometimes , I must get and remove all objects with durable=false from queue , How can I do this?

lemire commented 7 years ago

Create two priority queues, one for durable elements and one for those that aren't durable. Instead of polling just one queue, peek two queues, polling the best one. When you add elements, make sure they get added to the right queue.

sm2017 commented 7 years ago

@lemire but it is not solution because each time I just peek one item from queue and if I have two queue it is not clear that with queue has priority

lemire commented 7 years ago

If you can write better approach, please issue a pull request.