A queue is a First-In-First-Out (FIFO) data structure

The first element added to the queue will be the first one to be removed.

The "opposite" of a queue is a stack.

Methods

back ():T

Returns the element at the back of the queue.

This is the "newest" element.

dequeue ():T

Removes and returns the element at the front of the queue.

enqueue (val:T):Void

Inserts val at the back of the queue.

peek ():T

Returns the element at the front of the queue.

This is the "oldest" element.

Inherited Variables

Defined by Collection

read onlysize:Int

The total number of elements in this collection.

Defined by Hashable

read onlykey:Int

A unique, unsigned 32-bit integer key.

A hash table transforms this key into an index of an array element by using a hash function.

Inherited Methods

Defined by Collection

@:value({ gc : false })clear (gc:Bool = false):Void

Removes all elements from this collection.

For performance reasons, elements are not nullified upon removal.

This means that elements won't be available for the garbage collector immediately unless gc is true.

Parameters:

gc

if true, elements are nullifies upon removal (slower).

@:value({ copier : null, byRef : true })clone (byRef:Bool = true, ?copier:T ‑> T):Collection<T>

Duplicates this collection.

Supports shallow (structure only) and deep copies (structure & elements).

Example:

class Element implements polygonal.ds.Cloneable<Element> {
    public var val:Int;
    public function new(val:Int) {
        this.val = val;
    }
    public function clone():Element {
        return new Element(val);
    }
}

...

var c:Collection<Element> = new Array2<Element>(...);

//shallow copy
var o = c.clone(true);

//deep copy
var o = c.clone(false);

//deep copy using a custom function
var o = c.clone(false, function(x) return new Element(x.val));

If byRef is true, primitive elements are copied by value whereas objects are copied by reference.

If byRef is false, the copier function is used for copying elements. If omitted, clone() is called on each element assuming all elements implement Cloneable.

contains (val:T):Bool

Returns true if this collection contains val.

free ():Void

Disposes this collection by explicitly nullifying all internal references for GC'ing used resources.

Improves GC efficiency/performance (optional).

isEmpty ():Bool

Returns true if this collection is empty.

iterator ():Itr<T>

Iterates over all elements in this collection.

Example:

var c = new ArrayList<String>();
for (element in c) trace(element);

//or
var c = new ArrayList<String>();
var itr = c.iterator();
while (itr.hasNext()) trace(itr.next());

//inline hasNext() and next()
var c = new ArrayList<String>();
var itr:ArrayListIterator<String> = cast c.iterator();
while (itr.hasNext()) trace(itr.next());

See:

remove (val:T):Bool

Removes all occurrences of val.

Returns:

true if at least one occurrence of val was removed.

toArray ():Array<T>

Returns an array storing all elements in this collection.