A collection is an object that stores other objects (its elements)

Variables

read onlysize:Int

The total number of elements in this collection.

Methods

@: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.

Inherited Variables

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