priority-queue

Self updating Java PriorityQueue

I'm trying to use a PriorityQueue to order objects using a Comparator. This can be achieved easily, but the objects class variables (with which the comparator calculates priority) may change after the initial insertion. Most people have suggested the simple solution of removing the object, updating the values and reinserting it again, a...

Why doesn't the .Net framework have a priority queue class?

There are some threads on Stack Overflow dealing with implementing priority queues in .Net and C#. My issue is of a more basic nature: Why isn't there a priority queue out of the box in the .Net framework? Even the C++ Standard Library has one. ...

Is insertion time complexity of sorted-list implementation of priority queue O(n)?

From wikipedia: Sorted list implementation: Like a checkout line at the supermarket, but where important people get to "cut" in front of less important people. (O(n) insertion time, O(1) get-next time, O(n*log(n)) to build) I think if searching the insert position with binary search algorithm,the insertion time complexity...

C# XNA equivalent of Java's PriorityQueue with Comparator?

I'm implementing Dijkstra's on a board of tiles. I want to store all the tiles in a Priority Queue, sorted by their distance from the starting location. In Java, this would be something like: Queue<Point> pq = new PriorityQueue<Point>(new Comparator() { /* sort by distance from start */ }); What would the equivalent by in C# XNA? C# ha...

How to use iterators in java?

I have implemented Priority Queue interface for making heap. Can you tell me how to implement an iterator on the top of that? point me to some apropriate tutorial,i am new to java and on a very short deadline here. Actually i need a method to find and modify an object from heap on the basis of Object.id. I dont care if it is O(n). publi...

The built-in iterator for java's PriorityQueue does not traverse the data structure in any particular order. Why?

This is straight from the Java Docs: This class and its iterator implement all of the optional methods of the Collection and Iterator interfaces. The Iterator provided in method iterator() is not guaranteed to traverse the elements of the priority queue in any particular order. If you need ordered traversal, consider using Arrays.so...

Priority queue with dynamic item priorities.

I need to implement a priority queue where the priority of an item in the queue can change and the queue adjusts itself so that items are always removed in the correct order. I have some ideas of how I could implement this but I'm sure this is quite a common data structure so I'm hoping I can use an implementation by someone smarter than...

Bounded PriorityBlockingQueue

PriorityBlockingQueue is unbounded, but I need to bound it somehow. What is the best way to achieve that? For information, the bounded PriorityBlockingQueue will be used in a ThreadPoolExecutor. NB: By bounded I don't want to throw Exception if that happens, I want to put the object in the queue and then cut it based on its priority va...

Which data structure(s) to back a Final Fantasy ATB-style queue? (a delay queue)

Situation: There are several entities in a simulated environment, which has an artificial notion of time called "ticks", which has no link to real time. Each entity takes it in turns to move, but some are faster than others. This is expressed by a delay, in ticks. So entity A might have a delay of 10, and B 25. In this case the turn orde...

Is priority queue a non-linear data structure?

If yes then why priority queue is a non-linear data structure? Does non-linear data sturctures are bad in performance as compared to linear ones? If yes then why? Please explain in detail. ...

How can I create Min stl priority_queue?

The default stl priority queue is a Max one (Top function returns the largest element). Say, for simplicity, that it is a priority queue of int values. ...

How to iterate on boost::mutable_queue

Hello, I need a priority queue where I can increase or decrease the priority key. So boost::mutable_queue seemed perfect despite the lack of documentation. The problem is that I need to iterate at some point over all the elements in the queue. How can I do that? Or is there an othe data structure that would work (preferably in boost)?...

Using a priority queue in Java

Forgive me if this is a tried question, but I'm having a little difficulty figuring it out. I currently have a class Node, and each 'node' is a square in a maze. I'm trying to implement the A* algorithm, so each of these nodes will have an f-cost (int) data member inside of it. I was wondering if there's a way that I can create a priori...

C++: A variation of priority queue

I need some kind of priority queue to store pairs <key, value>. Values are unique, but keys aren't. I will be performing the following operations (most common first): random insertion; retrieving (and removing) all elements with the least key. random removal (by value); I can't use std::priority_queue because it only supports removin...

Bad_alloc exception when using new for a struct c++

Hi, I am writing a query processor which allocates large amounts of memory and tries to find matching documents. Whenever I find a match, I create a structure to hold two variables describing the document and add it to a priority queue. Since there is no way of knowing how many times I will do this, I tried creating my structs dynamical...

c++ stl priority queue insert bad_alloc exception

Hi, I am working on a query processor that reads in long lists of document id's from memory and looks for matching id's. When it finds one, it creates a DOC struct containing the docid (an int) and the document's rank (a double) and pushes it on to a priority queue. My problem is that when the word(s) searched for has a long list, when ...

What happens to my PriorityQueue if my Comparator throws an exception while it's busy bubbling up or down?

Hi, I'm trying order pairs of integers ascendantly where a pair is considered less than another pair if both its entries are strictly less than those of the other pair, and larger than the other pair if both its entries are strictly larger than those of the other pair. All other cases are considered incomparable. They way I want to sol...

C++ priority queue structure used ?

While searching for some functions in C++ STL documentation I read that push and pop for priority queues needs constant time. http://www.cplusplus.com/reference/stl/priority_queue/push/ "Constant (in the priority_queue). Although notice that push_heap operates in logarithmic time." My question is what kind of data structure is used...

PHP Priority Queue Implementation

I just finished coding a complex job assignment application where a lot of the work was done using priority queues. When I deployed, however, I discovered the web server ran PHP 5.2. Has there been an implementation for PHP<5.3 that can server as a drop-in replacement for SPLPriorityQueue? ...

NullPointerException when trying to add an object to a PriorityQueue

i keep getting a null pointer exception when trying to add an object to a priority queue i initialize the queue: private PriorityQueue<NodeObject> nodes; and here i try to add to it: NodeObject childNode = new NodeObject(child, 1); nodes.add(childNode); why doesn't this work? i know my NodeObject is not null because i create it ri...