All Bundles

Vector<H>

Growable generic array

Operations

Code example:

function : Example() ~ Nil {
   # insert elements
   vector := Collection.Vector->New()<IntRef>;
   vector->AddBack(4);
   vector->AddBack(1);
   vector->AddBack(5);
   vector->AddBack(1);
   vector->AddBack(0);
   
   # remove last item
   vector->RemoveBack();
   
   # get size
   vector->Size()->PrintLine();
   
   # get elements
   (vector->Get(0) + vector->Get(1))->PrintLine();
   
   # print all items with a loop
   each(item := vector) {
   item->PrintLine();
   };
   
   # print all items with a function
   vector->Each(Show(IntRef) ~ Nil);
}

function : Show(value : IntRef) ~ Nil {
   value->PrintLine();
}

New

Default constructor

New()

Copy constructor

New(values:H[])
Parameters
NameTypeDescription
valuesHvalues to copy

Copy constructor

New(values:Vector<H>)
Parameters
NameTypeDescription
valuesVector<H>values to copy

AddBack

Adds a value to the end

method : public : AddBack(value:H) ~ Nil
Parameters
NameTypeDescription
valueHvalue to append

Compress

Compresses the Vector freeing unused memory

method : public : Compress() ~ Nil

Each

Function called for each element

method : public : Each(f:(H)~Nil) ~ Vector<H>
Parameters
NameTypeDescription
f(H)~Nilfunction called

Empty

Clears the vector

method : public : Empty() ~ Nil

Get

Gets an indexed value

method : public : Get(index:Int) ~ H
Parameters
NameTypeDescription
indexIntindex

Return
TypeDescription
Hvalue

IsEmpty

Checks to see if the vector is empty

method : public : IsEmpty() ~ Bool
Return
TypeDescription
Booltrue if empty, false otherwise

Limit

Returns a limited list

method : public : Limit(l:Int) ~ Vector<H>
Parameters
NameTypeDescription
lIntlimit

Return
TypeDescription
Vector<H>limited list

Map

Maps the given function to each value in the vector

method : public : Map(f:(H)~H) ~ Vector<H>
Parameters
NameTypeDescription
f(H)~Hfunction to apply

Return
TypeDescription
Vector<H>newly calculated vector

Remove

Removes an indexed value

method : public : Remove(i:Int) ~ H
Parameters
NameTypeDescription
iIntindex

Return
TypeDescription
Hvalue

RemoveBack

Removes the last value

method : public : RemoveBack() ~ H
Return
TypeDescription
Hvalue

Set

Sets an indexed value

method : public : Set(value:H, index:Int) ~ Bool
Parameters
NameTypeDescription
valueHvalue
indexIntindex

Size

Size of vector

method : public : Size() ~ Int
Return
TypeDescription
Intsize of vector

Swap

Swap two values in the vector

method : public : Swap(a:Int, b:Int) ~ Bool
Parameters
NameTypeDescription
aIntfirst value
bIntsecond value

Return
TypeDescription
Booltrue if values were swapped

ToArray

Converts the vector into an object array

method : public : ToArray() ~ H[]
Return
TypeDescription
Hobject array

ToString

Formats the collection into a string. If an element implements the 'Stringify' interface, it's 'ToString()' is called.

method : public : ToString() ~ String
Return
TypeDescription
Stringstring representation