Deque
Object Hierarchy:
Description:
public class Deque<T> : Object
A double-ended queue (deque) that supports efficient insertion and removal at both ends.
Deque provides O(1) addFirst/addLast and removeFirst/removeLast. Inspired by Java's ArrayDeque.
For element comparison in contains(), pass an equality function to the constructor. For string elements, use GLib.str_equal.
Example:
var deque = new Deque<string> (GLib.str_equal);
deque.addLast ("a");
deque.addLast ("b");
deque.addFirst ("z");
assert (deque.peekFirst () == "z");
assert (deque.peekLast () == "b");
assert (deque.size () == 3);
Content:
Creation methods:
- public Deque (EqualFunc<T>? equal_func = null)
Creates an empty Deque.
Methods:
- public void addFirst (owned T element)
Adds an element to the front of the deque.
- public void addLast (owned T element)
Adds an element to the end of the deque.
- public void clear ()
Removes all elements from the deque.
- public bool contains (T element)
Returns whether the deque contains the specified element. Uses the
equality function provided in the constructor, or pointer equality if none was provided.
- public void forEach (owned ConsumerFunc<T> func)
Applies the given function to each element in the deque, from first to
last.
- public bool isEmpty ()
Returns whether the deque is empty.
- public T peekFirst ()
Returns the first element without removing it. Returns null if the
deque is empty.
- public T peekLast ()
Returns the last element without removing it. Returns null if the
deque is empty.
- public T removeFirst ()
Removes and returns the first element. Returns null if the deque is
empty.
- public T removeLast ()
Removes and returns the last element. Returns null if the deque is
empty.
- public uint size ()
Returns the number of elements in the deque.
- public T[] toArray ()
Returns the elements as a native array, from first to last.
Inherited Members:
All known members inherited from class GLib.Object
- @get
- @new
- @ref
- @set
- add_toggle_ref
- add_weak_pointer
- bind_property
- connect
- constructed
- disconnect
- dispose
- dup_data
- dup_qdata
- force_floating
- freeze_notify
- get_class
- get_data
- get_property
- get_qdata
- get_type
- getv
- interface_find_property
- interface_install_property
- interface_list_properties
- is_floating
- new_valist
- new_with_properties
- newv
- notify
- notify_property
- ref_count
- ref_sink
- remove_toggle_ref
- remove_weak_pointer
- replace_data
- replace_qdata
- set_data
- set_data_full
- set_property
- set_qdata
- set_qdata_full
- set_valist
- setv
- steal_data
- steal_qdata
- thaw_notify
- unref
- watch_closure
- weak_ref
- weak_unref