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} ||
49 public interface Gee.Deque<G> : Queue<G> {
51 * Offers the specified element to the head of this deque.
53 * @param element the element to offer to the queue
55 * @return ``true`` if the element was added to the queue
57 public abstract bool offer_head (G element);
60 * Peeks (retrieves, but not remove) an element from this queue.
62 * @return the element peeked from the queue (or ``null`` if none was
65 public abstract G? peek_head ();
68 * Polls (retrieves and remove) an element from the head of this queue.
70 * @return the element polled from the queue (or ``null`` if none was
73 public abstract G? poll_head ();
76 * Drains the specified amount of elements from the head of this queue in
77 * the specified recipient collection.
79 * @param recipient the recipient collection to drain the elements to
80 * @param amount the amount of elements to drain
82 * @return the amount of elements that were actually drained
84 public abstract int drain_head (Collection<G> recipient, int amount = -1);
87 * Offers the specified element to the tail of this deque
89 * @param element the element to offer to the queue
91 * @return ``true`` if the element was added to the queue
93 public abstract bool offer_tail (G element);
96 * Peeks (retrieves, but not remove) an element from the tail of this
99 * @return the element peeked from the queue (or ``null`` if none was
102 public abstract G? peek_tail ();
105 * Polls (retrieves and remove) an element from the tail of this queue.
107 * @return the element polled from the queue (or ``null`` if none was
110 public abstract G? poll_tail ();
113 * Drains the specified amount of elements from the tail of this queue in
114 * the specified recipient collection.
116 * @param recipient the recipient collection to drain the elements to
117 * @param amount the amount of elements to drain
119 * @return the amount of elements that were actually drained
121 public abstract int drain_tail (Collection<G> recipient, int amount = -1);