Click or drag to resize
Accord.NET (logo)

PriorityQueueT Class

Priority queue.
Inheritance Hierarchy
SystemObject
  Accord.CollectionsPriorityQueueT

Namespace:  Accord.Collections
Assembly:  Accord (in Accord.dll) Version: 3.8.0
Syntax
[SerializableAttribute]
public sealed class PriorityQueue<T> : IEnumerable
Request Example View Source

Type Parameters

T
The values in the queue.

The PriorityQueueT type exposes the following members.

Constructors
  NameDescription
Public methodPriorityQueueT
Initializes a new instance of the PriorityQueueT class.
Top
Properties
  NameDescription
Public propertyCapacity
Gets the current capacity of this queue.
Public propertyCount
Gets the number of nodes in the queue. This is an O(1) operation.
Public propertyFirst
Returns the head of the queue, without removing it (use Dequeue() for that). If the queue is empty, behavior is undefined. This is an O(1) operation.
Public propertyIsReadOnly
Gets a value indicating whether this instance is read only (returns false).
Public propertyOrder
Top
Methods
  NameDescription
Public methodClear
Removes every node from the queue. This is an O(1) operation.
Public methodContains
Returns whether the given node is in the queue. This is an O(1) operation.
Public methodDequeue
Removes the head of the queue (node with minimum priority; ties are broken by order of insertion), and returns it. This is an O(log n) operation.
Public methodEnqueue
Enqueue a node to the priority queue. Lower values are placed in front. Ties are broken by first-in-first-out. This is an O(log n) operation.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetEnumerator
Returns an enumerator that iterates through the collection.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodIsValidQueue
Checks to make sure the queue is still in a valid state.
Public methodRemove
Removes a node from the queue. The node does not need to be the head of the queue. This is an O(log n) operation.
Public methodResize
Resize the queue so it can accept more nodes. All currently enqueued nodes are kept. Attempting to decrease the queue size to a size too small to hold the existing nodes results in undefined behavior. This is an O(n) operation.
Public methodToArray
Returns an array containing the items in this list, optionally in in priority order.
Public methodToString
Returns a String that represents this instance.
(Overrides ObjectToString.)
Public methodUpdatePriority
This method must be called on a node every time its priority changes while it is in the queue. Forgetting to call this method will result in a corrupted queue!. This is an O(log n) operation.
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodSetEqualsPriorityQueueNodeT
Compares two enumerables for set equality. Two enumerables are set equal if they contain the same elements, but not necessarily in the same order.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks
The code for this class has been based on the original "High-speed Priority Queue" project originally developed by Daniel "Blue Raja" Pflughoeft. It was originally shared under a free MIT license, as shown below:
The MIT License (MIT)

Copyright (c) 2013 Daniel "BlueRaja" Pflughoeft
https://github.com/BlueRaja/High-Speed-Priority-Queue-for-C-Sharp

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
See Also