priority-queue

Priority Queues in Java

java.util.PriorityQueue allows a Comparator to be passed at construction time. When inserting elements, they are ordered according to the priority specified by the comparator. What happens when the priority of an element changes after it has been inserted? When does the PriorityQueue reorder elements? Is it possible to poll an element ...

In a FIFO Qeueing system, what's the best way the to implement priority messaging.

For message-oriented middleware that does not consistently support priority messages (such as AMQP) what is the best way to implement priority consumption when queues have only FIFO semantics? The general use case would be a system in which consumers receive messages of a higher priority before messages of a lower priority when a large ...

position index for binary heap priority queues?

So let's say I have a priority queue of N items with priorities, where N is in the thousands, using a priority queue implemented with a binary heap. I understand the EXTRACT-MIN and INSERT primitives (see Cormen, Leiserson, Rivest which uses -MAX rather than -MIN). But DELETE and DECREASE-KEY both seem to require the priority queue to ...

Getting Message by priority from MSMQ

hi. i am sending messages in MSMQ by setting its priority. using C# can i get the message from MSMQ having high priority first? just like we get in Priority Queue. and one thing more.. suppose there are three priority level 0 - high 1- medium 2 - low the sequence in queue is 2001122221111100 now if i send message with high prior...

Java - Looking for something faster than PriorityQueue

Hi, i'm using java on a big amount of data. [i try to simplify the problem as much as possible] Actually i have a small class (Element) containing an int KEY and a double WEIGHT (with getters&setters). I read a lot of these objects from a file and i have to get the best (most weight) M objects. Actually i'm using a PriorityQueue wi...

Priority queue in Java?

Is it possible in Java to create a PriorityQueue of objects where the key that decides the priority is the member of the object? All the examples I see on net insert an integer into the PriorityQueue and retrieve them. I'm looking for an implementation that would insert an instance of an object and is retrieved based on one of its membe...

Database based Priority Queue

Hi, does anyone know of a good database based Priority Queue implementation? I'm dealing with large amounts of data so keeping it all in memory is unfeasible. Thanks! ...

STL Priority Queue on custom class

I'm having a lot of trouble getting my priority queue to recognize which parameter it should sort by. I've overloaded the less than operator in my custom class but it doesn't seem to use it. Here's the relevant code: Node.h class Node { public: Node(...); ~Node(); bool operator<(Node &aNode); ... } Node.cpp #include "...

concurrent queue - general question (description and usage)

Hello, I am having some trouble grasping the idea of a concurrent queue. I understand a queue is a FIFO, or first come first serve, data structure. Now when we add the concurrency part, which I interpret as thread safety (please let me know if that is incorrect) things get a bit fuzzy. By concurrency we mean the way various threads can...

Priority Queue in .Net

This question is similar, but i want to exactly know: Is there any class/struct/... in .Net for priority queue? Just like in STL that have priority_queue for this. It accepts a comparsion function to support customized sorts. The best thing i found in .Net is SortedList< Key, Value > that sorts it's values by Key. So one solution is ...

Java: Design Question - minimal pairs between sets

I have two sets of Animal objects. The distance between animals is defined using a specific algorithm that looks at their traits. I am trying to design a method to find the pair from the two sets (one from each) that minimizes the distance. One idea I had: create a parametrized Tuple class to pair up Animals. Create a PriorityQueue with...

Problem with priority_queue - Writing memory after heap

Hello again, I am trying to use priority_queue, and program constantly fails with error message HEAP CORRUPTION DETECTED. here are the snippets: class CQueue { ... priority_queue<Message, deque<Message>, less<deque<Message>::value_type> > m_messages; ...}; class Message has overloaded operators > and < Here I fill up ...

Implementing a Priority queue with a Conditional Variable in C

My current understanding of conditional variables is that all blocked (waiting) threads are inserted into a basic FIFO queue, the first item of which is awakened when signal() is called. Is there any way to modify this queue (or create a new structure) to perform as a priority queue instead? I've been thinking about it for a while, but...

How do I best prioritize HTTP requests on a web page?

I need to prioritize the downloading of (in my case) images. To do this I would prefer to use some kind of plugin (preferably for jQuery) that lets me do this without having to build my own downloadqueue mechanism. Consider this scenario: You have a web page. Your web page is able to show a given user three images. These images are on...

Java: Access local variables from anon inner class? (PriorityQueue)

I want to use a PriorityQueue to do a topological sort on a graph. For brevity, I'd like to use an anonymous inner class for the comparator. However, I need access to the graph g in order to determine the in degree of the nodes I'm looking at. Is this possible? /** * topological sort * @param g must be a dag */ public static Queue<...

Running time of minimum spanning tree? ( Prim method )

I have written a code that solves MST using Prim method. I read that this kind of implementation(using priority queue) should have O(E + VlogV) = O(VlogV) where E is the number of edges and V number of Edges but when I look at my code it simply doesn't look that way.I would appreciate it if someone could clear this up for me. To me it s...

How java priority Queue is suppose to work?

Short story, I'm implementing a graph and now I'm working on the Kruskal, I need a priority queue. My definition of a priority queue is that the element with the smallest key would come first? Is this wrong? Because when I insert the weighted edges(or numbers) in the queue they don't end up sorted. PriorityQueue<Integer> tja = new Prio...

PostMessage with priority?

Is it possible to prioritize a message sent with PostMessage (or any of the other related methods)? IIRC, the WM_PAINT message, for instance, is only processed when there are no other messages in the queue. Is it possible to achieve a similiar behavior with custom messages? If I use WM_PAINT with special parameters in order to deliver ...

Java PriorityQueue with fixed size

Hi folks, I am calculating a large number of possible resulting combinations of an algortihm. To sort this combinations I rate them with a double value und store them in PriorityQueue. Currently, there are about 200k items in that queue which is pretty much memory intesive. Acutally, I only need lets say the best 1000 or 100 of all ite...

Is there a Queue (PriorityQueue) implementation which is also a Set?

I'm looking for a PriorityQueue implementation which is also a Set. The compareTo implementation if its elements must not have the requirement to be consistent with the implementation of equals. Is there somewhere such a implementation for java? Update: I implemented it now using a SortedSet as the internal collection. So I only had t...