3 * Copyright (C) 2009 Didier Villevalois
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Didier 'Ptitjes Villevalois <ptitjes@free.fr>
24 * A double-ended queue.
26 * A deque can be used either as a queue (First-In-First-Out behavior) or as a
27 * stack (Last-In-First-Out behavior).
29 * The methods defined by this interface behaves exactely in the same way as
30 * the {@link Queue} methods with respect to capacity bounds.
32 * The Deque interface inherits from the {@link Queue} interface. Thus, to use
33 * a deque as a queue, you can equivalently use the folowing method set:
35 * ||<)(> ''Queue method'' ||<)(> ''Deque method'' ||
36 * || {@link Queue.offer} || {@link offer_tail} ||
37 * || {@link Queue.peek} || {@link peek_head} ||
38 * || {@link Queue.poll} || {@link poll_head} ||
39 * || {@link Queue.drain} || {@link drain_head} ||
41 * To use a deque as a stack, just use the method set that acts at the head of
44 * ||<)(> ''Operation'' ||<)(> ''Deque method'' ||
45 * || push an element || {@link offer_head} ||
46 * || peek an element || {@link peek_head} ||
47 * || pop an element || {@link poll_head} ||
50 public interface Gee.Deque<G> : Queue<G> {
52 * Offers the specified element to the head of this deque.
54 * @param element the element to offer to the queue
56 * @return ``true`` if the element was added to the queue
58 public abstract bool offer_head (G element);
61 * Peeks (retrieves, but not remove) an element from this queue.
63 * @return the element peeked from the queue (or ``null`` if none was
66 public abstract G? peek_head ();
69 * Polls (retrieves and remove) an element from the head of this queue.
71 * @return the element polled from the queue (or ``null`` if none was
74 public abstract G? poll_head ();
77 * Drains the specified amount of elements from the head of this queue in
78 * the specified recipient collection.
80 * @param recipient the recipient collection to drain the elements to
81 * @param amount the amount of elements to drain
83 * @return the amount of elements that were actually drained
85 public abstract int drain_head (Collection<G> recipient, int amount = -1);
88 * Offers the specified element to the tail of this deque
90 * @param element the element to offer to the queue
92 * @return ``true`` if the element was added to the queue
94 public abstract bool offer_tail (G element);
97 * Peeks (retrieves, but not remove) an element from the tail of this
100 * @return the element peeked from the queue (or ``null`` if none was
103 public abstract G? peek_tail ();
106 * Polls (retrieves and remove) an element from the tail of this queue.
108 * @return the element polled from the queue (or ``null`` if none was
111 public abstract G? poll_tail ();
114 * Drains the specified amount of elements from the tail of this queue in
115 * the specified recipient collection.
117 * @param recipient the recipient collection to drain the elements to
118 * @param amount the amount of elements to drain
120 * @return the amount of elements that were actually drained
122 public abstract int drain_tail (Collection<G> recipient, int amount = -1);