KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > unimi > dsi > fastutil > PriorityQueue


1 package it.unimi.dsi.fastutil;
2
3 /*
4  * fastutil: Fast & compact type-specific collections for Java
5  *
6  * Copyright (C) 2003, 2004, 2005, 2006 Paolo Boldi and Sebastiano Vigna
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  */

23
24 import java.util.Comparator JavaDoc;
25 import java.util.NoSuchElementException JavaDoc;
26
27 /** A priority queue.
28  *
29  * <P>A priority queue provides a way to {@linkplain #enqueue(Object) enqueue}
30  * elements, and to {@linkplain #dequeue() dequeue} them in some specified
31  * order. Elements that are <em>smaller</em> in the specified order are
32  * dequeued first. It is also possible to get the {@linkplain #first() first
33  * element}, that is, the element that would be dequeued next.
34  *
35  * <P>Additionally, the queue may provide a method to peek at
36  * element that would be dequeued {@linkplain #last() last}.
37  *
38  * <P>The relative order of the elements enqueued should not change during
39  * queue operations. Nonetheless, some implementations may give the caller a
40  * way to notify the queue that the {@linkplain #changed() first element has
41  * changed its relative position in the order}.
42  */

43
44 public interface PriorityQueue<K> {
45
46     /** Enqueues a new element.
47      *
48      * @param x the element to enqueue..
49      */

50
51     void enqueue( K x );
52
53     /** Dequeues the {@link #first()} element from the queue.
54      *
55      * @return the dequeued element.
56      * @throws NoSuchElementException if the queue is empty.
57      */

58
59     K dequeue();
60
61     /** Checks whether the queue is empty.
62      *
63      * @return true if the queue is empty.
64      */

65
66     boolean isEmpty();
67
68     /** Returns the number of elements in this queue.
69      *
70      * @return the number of elements in this queue.
71      */

72
73     int size();
74
75     /** Removes all elements from this queue.
76      */

77
78     void clear();
79
80     /** Returns the first element of the queue.
81      *
82      * @return the first element.
83      * @throws NoSuchElementException if the queue is empty.
84      */

85
86     K first();
87
88     /** Returns the last element of the queue, that is, the element the would be dequeued last (optional operation).
89      *
90      * @return the last element.
91      * @throws NoSuchElementException if the queue is empty.
92      */

93
94     K last();
95
96     /** Notifies the queue that the {@linkplain #first() first element} has changed (optional operation).
97      */

98
99     void changed();
100
101     /** Returns the comparator associated with this queue, or <code>null</code> if it uses its elements' natural ordering.
102      *
103      * @return the comparator associated with this sorted set, or <code>null</code> if it uses its elements' natural ordering.
104      */

105     Comparator JavaDoc<? super K> comparator();
106 }
107
Popular Tags