priority-queue

Priority Queue with a find function - Fastest Implementation

无人久伴 提交于 2020-06-09 16:59:10
问题 I am looking at implementing a priority queue with an added requirement, a find/search function which will tell whether an item is anywhere within the queue. So the functions will be: insert, del-min and find. I am unsure whether I should use a Heap or a Self-balancing binary search tree. It appears PQs are usually implemented with a Heap, but I am wondering if there is any advantage in using a binary search tree since I also need that find function. Furthermore, on average I'll be doing more

How to implement a priority queue using SQS(Amazon simple queue service)

给你一囗甜甜゛ 提交于 2020-05-14 17:18:38
问题 I have a situation when a msg fails and I would like to replay that msg with the highest priority using python boto package so he will be taken first. If I'm not wrong SQS queue does not support priority queue, so I would like to implement something simple. Important note : when a msg fails I no longer have the message object, I only persist the receipt_handle so I can delete the message(if there was more than x retries) / change timeout visibility in order to push him back to queue. Thanks!

How to poll the RabbitMQ to get messages in order of priority continuously?

假如想象 提交于 2020-02-02 13:12:33
问题 We could make RabbitMQ a distributed priority queue by installing the plugin rabbitmq-priority-queue from https://www.rabbitmq.com/community-plugins.html. I push elements into the queue (each element is pushed with a priority) and I am able to receive the contents of queue in a consumer as desired - higher priority element comes out first. The issue is that the priority polling concept is not working when this happens continuously: Run a publisher to populate 3 items with different priorities

How to poll the RabbitMQ to get messages in order of priority continuously?

与世无争的帅哥 提交于 2020-02-02 13:12:07
问题 We could make RabbitMQ a distributed priority queue by installing the plugin rabbitmq-priority-queue from https://www.rabbitmq.com/community-plugins.html. I push elements into the queue (each element is pushed with a priority) and I am able to receive the contents of queue in a consumer as desired - higher priority element comes out first. The issue is that the priority polling concept is not working when this happens continuously: Run a publisher to populate 3 items with different priorities

Using queue.PriorityQueue, not caring about comparisons

﹥>﹥吖頭↗ 提交于 2020-01-25 03:04:07
问题 I'm trying to use queue.PriorityQueue in Python 3(.6). I would like to store objects with a given priority. But if two objects have the same priority, I don't mind PriorityQueue.get to return either. In other words, my objects can't be compared at integers, it won't make sense to allow them to be, I just care about the priority. In Python 3.7's documentation, there's a solution involving dataclasses . And I quote: If the data elements are not comparable, the data can be wrapped in a class

Finding the Minimum in a Priority Queue (heap)

亡梦爱人 提交于 2020-01-16 00:38:51
问题 I am trying to learn the how to use Priority Queues, and there is one method I do not fully understand and would like some help as to how it works. That method is findMin. The part I want to understand is why the biggest number ends up in location 0 of the array? Then, since the list is sorted, its easy to find the smallest number in location [1] of the array. But why? Here is all the code I am looking at: public class BinaryHeap<AnyType extends Comparable<? super AnyType>> { /** * Construct

Warnings in boost::priority_queue

丶灬走出姿态 提交于 2020-01-15 12:23:29
问题 When I try to build "priority_queue_example.cpp" it get these warnings(and so errors) pointing to "priority_queue_example.h" on the line where my priority_queue is declared. The warnings are, 1> priority_queue_example.cpp 1>c:\Projects\lib\boost\boost\heap\detail\stable_heap.hpp(102): error C2220: warning treated as error - no 'object' file generated 1>c:\Projects\lib\boost\boost\heap\detail\stable_heap.hpp(102): warning C4100: 'rhs' : unreferenced formal parameter 1> c:\Projects\lib\boost

When could std::priority_queue::pop throw an exception

我怕爱的太早我们不能终老 提交于 2020-01-14 12:44:49
问题 The pop() method of std::priority_queue is not declared noexcept , so in theory could throw an exception. But when might it throw an exception, and what might those exceptions be? 回答1: It could be marked nothrow , but isn't. Why std::priority_queue::pop could * not throw void pop(); Removes the top element from the priority queue. Effectively calls std::pop_heap(c.begin(), c.end(), comp); c.pop_back(); c is by default an std::vector . [vector.modifiers]/4&5 void pop_back(); 4/ Complexity :

PriorityQueue returning elements in wrong order [duplicate]

拟墨画扇 提交于 2020-01-14 03:39:05
问题 This question already has answers here : The built-in iterator for java's PriorityQueue does not traverse the data structure in any particular order. Why? (5 answers) Sorting Priority Queue in Java [duplicate] (5 answers) Closed 7 days ago . I have a class Person which has two attributes Name( String ) and Weight( Integer ). I want to store elements in PriorityQueue according to their weight in descending order, i.e. higher the weight the top the element is in the queue. I have tried this so

Why heap is better than binary tree to represent a priority queue?

心已入冬 提交于 2020-01-12 05:29:06
问题 In a (max) heap it is easy to find the biggest item in O(1) time, but to actually remove it you need complexity of O(log(n)) . So if the insertion and deletion from a heap is both O(log(n)) , what are the advantages of a heap over binary tree for representing a priority queue? 回答1: Heaps use less memory. They can be implemented as arrays and thus there is no overhead for storing pointers. (A binary tree CAN be implemented as an array, but there is likely to be many empty "gaps" which could