Growable generic array
OperationsCode 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();
}
Default constructor
New()
Copy constructor
New(values:H[])
Name | Type | Description |
---|---|---|
values | H | values to copy |
Copy constructor
New(values:Vector<H>)
Name | Type | Description |
---|---|---|
values | Vector<H> | values to copy |
Adds a value to the end
method : public : AddBack(value:H) ~ Nil
Name | Type | Description |
---|---|---|
value | H | value to append |
Compresses the Vector freeing unused memory
method : public : Compress() ~ Nil
Function called for each element
method : public : Each(f:(H)~Nil) ~ Vector<H>
Name | Type | Description |
---|---|---|
f | (H)~Nil | function called |
Clears the vector
method : public : Empty() ~ Nil
Gets the first value
method : public : First() ~ H
Type | Description |
---|---|
H | first value, or Nil if not set |
Gets an indexed value
method : public : Get(index:Int) ~ H
Name | Type | Description |
---|---|---|
index | Int | index |
Type | Description |
---|---|
H | value, or Nil if invalid index |
Checks to see if the vector is empty
method : public : IsEmpty() ~ Bool
Type | Description |
---|---|
Bool | true if empty, false otherwise |
Gets the last value
method : public : Last() ~ H
Type | Description |
---|---|
H | last value, or Nil if not set |
Returns a limited list
method : public : Limit(l:Int) ~ Vector<H>
Name | Type | Description |
---|---|---|
l | Int | limit |
Type | Description |
---|---|
Vector<H> | limited list |
Maps the given function to each value in the vector
method : public : Map(f:(H)~H) ~ Vector<H>
Name | Type | Description |
---|---|---|
f | (H)~H | function to apply |
Type | Description |
---|---|
Vector<H> | newly calculated vector |
Removes an indexed value
method : public : Remove(i:Int) ~ H
Name | Type | Description |
---|---|---|
i | Int | index |
Type | Description |
---|---|
H | value |
Removes the last value
method : public : RemoveBack() ~ H
Type | Description |
---|---|
H | value |
Reverses element order
method : public : Reverse() ~ Vector<H>
Type | Description |
---|---|
Vector<H> | reversed vector, if the vector is empty or hold 1 item then the original list is returned |
Sets an indexed value
method : public : Set(value:H, index:Int) ~ Bool
Name | Type | Description |
---|---|---|
value | H | value |
index | Int | index |
Size of vector
method : public : Size() ~ Int
Type | Description |
---|---|
Int | size of vector |
Swap two values in the vector
method : public : Swap(a:Int, b:Int) ~ Bool
Name | Type | Description |
---|---|---|
a | Int | first value |
b | Int | second value |
Type | Description |
---|---|
Bool | true if values were swapped |
Converts the vector into an object array
method : public : ToArray() ~ H[]
Type | Description |
---|---|
H | object array |
Formats the collection into a string. If an element implements the 'Stringify' interface, it's 'ToString()' is called.
method : public : ToString() ~ String
Type | Description |
---|---|
String | string representation |