priority-queue

When should I use a TreeMap over a PriorityQueue and vice versa?

Seems they both let you retrieve the minimum, which is what I need for Prim's algorithm, and force me to remove and reinsert a key to update its value. Is there any advantage of using one over the other, not just for this example, but generally speaking? ...

peek queue method

If a priority queue is being used for scheduling, in what situations does a scheduler use the peek method? As in, what is its purpose? ...

How to implement PriorityBlockingQueue with ThreadPoolExecutor and custom tasks

I've searched a lot but could not find a solutuion to my problem. I have my own class, BaseTask, that uses a ThreadPoolExecutor to handle tasks. If I don't want prioritization (i.e. using a LinkedBlockingQueue) this works just fine, but when I try to use a PriorityBlockingQueue I get ClassCastException because the ThreadPoolExecutor w...

Using an IntentService to do Prioritized Networking

I've been wondering if it is possible to use an IntentService to do some networking while keeping the queue of pending intents prioritized. My goal to be able to download some images in the background, add more if needed (send another Intent) and be able to reset the queue if necessary (preferably using a specific Intent). That is all po...

C# Generics: Inserting T as the where T : IComparable<T> interface conflict

This is a challenge for the C# generics / design patterns masters. I'm trying to implement a generic heap, and then a priority queue that uses the heap. My heap's signature is: class Heap<TKey, TValue> where TKey : IComparable<TKey> My priority queue class is: public delegate IComparable<T> Evaluator<T>(T item); class PriorityQueu...

Dispatcher vs Multithreading

According to Single-Threaded Application with Long-Running Calculation MSDN example, there is a possibility of creating a responsive GUI in just 1 thread. Thanks to the Dispatcher object, as we can set the Priority of work items. My question is, what sense does it have to do simple tasks (supposing we just have 1 single core cpu) in a ...

PriorityQueue of Objects from an Inner Class - Can't find constructor

Hi all, I need a priority queue of objects but I keep getting this error: symbol: constructor PriorityQueue(anonymous java.util.Comparator<map.Node>>) location: class java.util.PriorityQueue<map.Node> PriorityQueue<Node> pq = new PriorityQueue<Node>(new Comparator<Node>() Here an excerpt from my code: public class map { static ...

Priority Queue which can be stored in disk (JAVA )

I need to implement a application which has a priority queue which has more than 100M records .My problem is I am not able to keep all this data in memory i need to store it into disk . Is there any cache solution where I can store all this message into disk such Berkeley db cache . ...

Help with a task scheduling algorithm

I am working on an application in which thousands of tasks associated with hundreds of devices, each task requiring, < 5ms to begin execution, and taking on average 100ms to complete. The conditions are as such: Each device can only process a single task at a time, e.g., one task must finish running on its assigned device prior to ...

C++ priority_queue underlying vector container capacity resize

Hi all, I'm using priority_queue with a vector as an underlying container. However I expect the size of the heap to be very large. I'm aware of problems with dynamic vector capacity resize. So I'm looking for ways to initially allocate enough space for the underlying vector in my priority_queue. Are there any suggestions out there to ac...

Changing Java PriorityQueue to a Max PQ

The Priority Queue implementation in the Java standard library appears to be a min Priority Queue which I found somewhat confusing. In order to turn it into a max one I created a custom comparator object. Comparator<Integer> cmp = new Comparator<Integer>() { public int compare( Integer x, Integer y ) { return y - x; ...

What's faster: inserting into a priority queue, or sorting retrospectively?

What's faster: inserting into a priority queue, or sorting retrospectively? I am generating some items that I need to be sorted at the end. I was wondering, what is faster in terms of complexity: inserting them directly in a priority_queue or a similar data structure, or using a sort algorithm at end? ...

I need some help clearing up a problem with sorting a Priority Queue+linked list in Java.

Hello I am trying to implement a Priority Queue in Java from scratch with a linked list but I am having a problem sorting elements on insertion. Here is my program thus far, any help would be massively appreciated. import java.util.Scanner; public class T0 { public static void main(String args[]) { Scanner keyboard = new...

Priority Queue using MultiMap - Java

Hi. I have to implement Priority Queue using MultiMap. I use MultiMap from Google Collections. The following code creates a MultiMap and adds few elements into it. Multimap<Integer, String> multimap = HashMultimap.create(); multimap.put(5,"example"); multimap.put(1,"is"); multimap.put(1,"this"); multimap.put(4,"so...

Priority Queue with a find function - Fastest Implementation

Hi, 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 wit...

Priority Queue in Java

can you have 2 parameters? for instance, i want to add a string and a corresponding integer to a priority key. Then I am going to sort it by that integer. I know how to add either a string or a integer, but I dont know how to add both. Can someone please point me in the right direction and let me know if i am even going about this the ri...