Iqueue

Source: Internet
Author: User
Keywords iqueue

An unbounded priority IQueue based on a priority heap. This queue orders elements according to an order specified at construction time, which is specified either according to their natural order (see IComparable, or according to a IComparer, depending on which constructor is used. A priority queue does not permit elements. A priority queue relying on natural ordering also does not permit insertion of non-comparable objects (doing so will result InvalidCastException.


The head of this queue is the lowest element with respect to the specified ordering. If multiple elements are tied for lowest value, the head is one of those elements -- ties are broken arbitrarily.


A priority queue is unbounded, but has an internal capacity governing the size of an array used to store the elements on the queue. It is always at least as large as the queue size. As elements are added to a priority queue, its capacity grows automatically. The details of the growth policy are not specified.


This class and its enumerator implement all of the optional methods of the ICollection and IEnumerator interfaces. The enumerator provided in method GetEnumerator is not guaranteed to traverse the elements of the PriorityQueue in any particular order.


Note that this implementation is NOT synchronized. Multiple threads should not access a PriorityQueue instance concurrently if any of the threads modifies the list structurally. Instead, use the thread-safe PriorityBlockingQueue.

Besides basic ICollection operations, queues provide additional insertion, extraction, and inspection operations.

Each of these methods exists in two forms: one throws an exception if the operation fails, the other returns a special value (either or , depending on the operation). The latter form of the insert operation is designed specifically for use with capacity-restricted IQueue implementations; in most implementations, insert operations cannot fail.

Queues typically, but do not necessarily, order elements in a FIFO (first-in-first-out) manner. Among the exceptions are priority queues, which order elements according to a supplied comparator, or the elements' natural ordering, and LIFO queues (or stacks) which order the elements LIFO (last-in-first-out). Whatever the ordering used, the head of the queue is that element which would be removed by a call to Remove or Poll. In a FIFO queue, all new elements are inserted at the tail of the queue. Other kinds of queues may use different placement rules. Every IQueue implementation must specify its ordering properties.

The Offer method inserts an element if possible, otherwise returning . This differs from the Add method, which can fail to add an element only by throwing an exception. The Offer method is designed for use when failure is a normal, rather than exceptional occurrence, for example, in fixed-capacity (or "bounded" queues.

The RemovePoll methods remove and return the head of the queue. Exactly which element is removed from the queue is a function of the queue's ordering policy, which differs from implementation to implementation. The Remove and Poll methods differ only in their behavior when the queue is empty: the Remove method throws an exception, while the Poll method returns .

The Element and Peek methods return, but do not remove, the head of the queue.

The IQueue interface does not define the blocking queue methods, which are common in concurrent programming.

IQueue implementations generally do not allow insertion of elements, although some implementations, such as a linked list, do not prohibit the insertion of . Even in the implementations that permit it, should not be inserted into a IQueue, as is also used as a special return value by the Poll method to indicate that the queue contains no elements.

IQueue implementations generally do not define element-based versions of methods Equals and GetHashCode, but instead inherit the identity based versions from the class object, because element-based equality is not always well-defined for queues with the same elements but different ordering properties.

Based on the back port of JCP JSR-166.

Syntax
public interface IQueue : IDestination, IDisposable, 
IEndpoint

The IQueue type exposes the following members.


Properties

Name Description
Durable When true, the endpoint's life span is independent of the corresponding IFlow or ISession.
(Inherited from IEndpoint.)

Name
Represents the physical name of a destination.
(Inherited from IDestination.)
Temporary
Indicates whether this is a temporary destination.
Temporary destinations are used mostly for request/reply message exchange patterns. Its scope and lifetime is that of the containing session.
(Inherited from IDestination.)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.