garro95 / priority-queue

A priority queue for Rust with efficient change function.
173 stars 29 forks source link

Feature Suggestion: DoublePriorityQueue with multiple priorities #45

Open Zannick opened 1 year ago

Zannick commented 1 year ago

Hey, I'm really appreciating the DoublePriorityQueue: it lets me easily remove entries from one end to avoid overfilling a constant size, kind of like a work-queue LRU cache.

Since the heap is internally just a heap of element indices, I've been pondering having a priority queue with two (or more) unrelated priority measures, stored in two different index heaps. That would add a constant factor to the O(log n) guarantees (based on arbitrary remove), but it'd unlock the ability for me to have two different strategies for the threads selecting work items from the queue. In particular, I'm performing a graph search where every work item has a few variables that I combine unscientifically into a "score", and rather than perfect an equation, I'd like to just use one variable independently as its own measure in one thread (without doing a linear map().min() over the whole heap).