Containers are an essencial part of every programming language and used on a daily basis, sadly Galaxy Script does not provide many useful native containers. The only container classes available are vectors like objects for units (Unit Group) and players (Player Group). However, for all other datatypes its necessary to use arrays with a fixed size to manage collections of elements.
This often leads to wasted memory capacity and very time consuming and tideous array management, which is why i decided to start working on a container library for my own use aswell as for the community.
The following container types are currently supported:
Vector
A vector is an array-like object which allows dynamic addition and removal of elements, as well as indexed access.
Available functions:
int [Vector] Create()
Creates a new vector and returns its unique ID. Vectors should be destroyed after usage to free memory. Please note that empty vectors still exist and need to be manually destroyed.
Complexity: O(1)
int [Vector] Create With Initial Size(int size)
Creates a new vector and returns its unique ID. The vector will be initialized to initially have the specified size. This can lead to performance improvements because it allows initializing vector values by using the set instead of the add method (See changelog for more details on this). The vector values will not be initialized after calling the constructor and return their default values when retrieved. The vector will grow once using the add method. Vectors should be destroyed after usage to free memory. Please note that empty vectors still exist and need to be manually destroyed.
Complexity: O(1)
bool [Vector] Exists(int Vector ID)
Checks if the specified vector exists. Vectors should be destroyed after usage to free memory. Please note that empty vectors still exist and need to be manually destroyed.
Complexity: O(1)
int [Vector] Get Element Count(int Vector ID)
Returns the number of elements within the vector.
Complexity: O(1)
DataType [Vector] Get Element Type(int Vector ID, int Element ID)
Returns the type of the specified element ID. Vectors can store multiple different data types at the same time, so this function may be useful to filter them later.
Complexity: O(1)
int [Vector] Get Last Element ID(int Vector ID)
Returns the last valid element ID of the specified vector for usage in range based for loops. The last valid element ID equals the element count - 1.
Complexity: O(1)
int [Vector] Get Active Vector Count()
Returns the total amount of active (non destroyed) vectors. Useful for debugging purposes.
Complexity: O(1)
<datatype>[Vector] Get (<datatype>)(int Vector ID, int Element ID)
Returns the element value at the specified index. <datatype> stands for one of the supported data types for the vector container.
Complexity: O(1)
int [Vector] Get Vector Attached To Unit(unit u)
Returns the vector attached to the specified unit via the "[Vector] Attach To Unit" function. Will return invalid container id if no vector is currently linked to the specified unit.
Complexity: O(1)
Available actions:
void [Vector] Remove Element(int Vector ID, int Element ID)
Removes the element at the specified index and moves all elements after it. Removing elements from very large vectors may impact performance. Please note that empty vectors still exist and need to be manually destroyed.
Complexity: O(n), where n = number of elements after the removed element.
void [Vector] Destroy(int Vector ID)
Destroys the specified vector and frees all used up memory. Vectors should be destroyed after usage to free memory. Please note that empty vectors still exist and need to be manually destroyed.
Complexity: O(n), where n = the size of the vector.
void [Vector] Print(int Vector ID)
Prints a debug output for the specified vector.
Complexity: O(n), where n = the size of the vector.
void [Vector] Add (<datatype>)(int Vector ID, <datatype> Value)
Adds a new element to the specified vector. <datatype> stands for one of the supported data types for the vector container.
Complexity: O(1)
void [Vector] Set (<datatype>)(int Vector ID, int Element ID, <datatype> Value)
Sets the element value at the specified index. Does nothing if the element ID is not part of the vector. <datatype> stands for one of the supported data types for the vector container.
Complexity: O(1)
void [Vector] Clear(int Vector ID)
Removes all elements of the specified vector without destroying the vector itself.
Complexity: O(n), where n = the size of the vector.
void [Vector] Attach To Unit(int vectorID, unit u)
Attaches the specified vector to the specified unit. Will do nothing if the vector does not exist.
Please note that a vector attached to a unit will not get destroyed once the unit dies or gets removed from the game. You will have to manually unattach AND destroy the vector on unit death if wanted to prevent data table value leaks.
Complexity: O(1)
void [Vector] Remove Attached Vector From Unit(unit u)
Removes the attached vector from the specified unit. This method should be called everytime the unit dies or gets removed from the game to prevent memory leaks.
Complexity: O(1)
Queue
A queue is a FIFO (First in first out) data structure. In comparison to the vector container, the queue allows removing the first element with O(1) complexity and without copying all following entries. However, a queue does not allow index based element access or removal of elements at a specific point.
Available functions:
Just as the vector container, the queue has its own versions of the Create, Exists, Get Element Count and Get Active Queue Count functions which work similar to the vector counterparts.
The following methods are unique to the queue container:
DataType [Queue] Get First Element Type(int QueueID)
Returns the data type of the first element within the queue. Returns a default value if the accessed value does not exist.
Complexity: O(1)
<datatype> [Queue] Get First (<datatype>)(int QueueID)
Returns the first element of the queue. <datatype> stands for one of the supported data types for the queue container. Returns a default value if the accessed value does not exist.
Complexity: O(1)
Available actions:
Just as the vector container, the queue has its own versions of the Destroy, Clear and Print functions which work similar to the vector counterparts.
The following methods are unique to the queue container:
void [Queue] Remove First(int QueueID)
Removes the first element of the queue. Does nothing if the container is empty or doesnt exist.
Complexity: O(1)
void [Queue] Add (<datatype>)(int QueueID, <datatype> Value)
Adds a new element to the end of the queue. <datatype> stands for one of the supported data types for the queue container. Does nothing if the container doesnt exist.
Complexity: O(1)
The following data types are currently supported:
Actor
Bank
Boolean
Camera Object
Color
Integer
Order
Player Group
Point
Real
Region
String
Text Tag
Text
Timer
Trigger
Unit Group
Dialog
Dialog Item
Sound
Sound Link
Unit
Possible issues:
Since all containers are based on data tables it is mandatory NOT to clear the global data table at any point in time to avoid data loss and corruption of the library.
In the very rare case of key name conflics you may edit the data table key prefixes within the "Containers - > <Container Type> -> Vars -> Constants" folder to match your needs.
Changelog:
v0.6
- Added a new constructor for the vector container, allowing to create a vector with an initial size. The constructor retains O(1) complexity regardless of the initial vector size and does not initialize the vector members to any value. This can lead to significant performance improvements because it makes it possible to use [Vector] Set instead of [Vector] Add to initialize vector values.
For example, lets say you wanted to initialize a vector with integers from 1 to 10 you can now do it like this:
Note that a vector initialized with a size of 10 can still grow to a size of 11 and beyond when using [Vector] Add.
- Added the possibility to link vectors to units by using the new "[Vector] Attach To Unit" function. This allows linking all sorts of metadata to a unit, without the limitation of only 64 custom values or 64 behaviors. It also allows attaching and mixing any supported data types since the vector container can store multiple data types at once. Added vectors can be removed and retrieved by "[Vector] Remove Attached Vector From Unit" and "[Vector] Get Vector Attached To Unit" functions. Note that you still need to unattach and destroy attached vectors once the unit dies or gets removed from the game, otherwise you will get datatable value leaks.
- The vector container now supports the "Unit" data type.
v0.5
- Performance improvements by applying micro optimizations to the internal workings of the library. Optimizations focused on removal of sub function calls and minimizing the amount of String concatinations, achieving 1.4x - 2.5x speedup for most functions.
v0.4
- Added Queue container
v0.3
- Performance improvements
- Memory usage has been decreased significantly
- Source code size reduced
- New action: "void [Vector] Clear(int Vector ID" has been added to the vector container
v0.2
- Added "void [Vector] Set (<datatype>(*))(int Vector ID, int Element ID, <datatype>(*) Value)" action.
FAQ:
Q: Where are stack and map?
A: Map is already available in form of data tables. A stack can easily be implemented by using the vector container (Just add elements at the end and get + remove the last element). A direct stack implementation within the library would not make sense since it could not be more efficient than the current vector implementation.
Q: How much overhead does importing and using the container library cause?
A: The source code of the library is relatively small (Approx 1000 lines), and the size is only because it needs wrappers for every data type. The library only defines a minimal amount of global variables and has no triggers.
The performance of the containers itself is optimized as far as possible, but will always be slower than using native implementations, like Unit Group. Its also slower than using arrays.
Q: Can a container store multiple different data types at once?
A: Yes. Even though its probably not necessary to do that very often it can still be a very mighty instrument in conjunction with the Get Element Type() method. For example it can allow you to return multiple values from a function into a vector buffer.
Q: Whats the purpose of the "Get Vector Count" method?
A: This method returns the currently active amount of vectors. It can be useful to find out if you forgot to destroy any vectors using the [Vector] Destroy method.
Q: Why arent there more supportive methods, such as "[Vector] Contains"?
A: It would not be possible to implement methods of this kind in an efficient matter because a vector can store multiple different data types at once, which, for example, would require a wrapper for every data type which is supposed to work with this method.
However, you can easily implement a method like this by yourself for your own needs, for example by guarantying that the specified vector contains integers only.
Examples of usage:
Vector:
vectordemoEventsGame-MapinitializationLocalVariables-------creatingtwovectorsvec1=([Vector] Create()) <Integer>
vec 2 = ([Vector] Create()) <Integer>
i = 0 <Integer>
sum = 0.0 <Real>
Conditions
Actions
------- adding numbers 1-10 to vector 1
General - For each integer i from 1 to 10 with increment 1, do (Actions)
Actions
[Vector] Add (Integer)(vec 1, i)
------- printing vector 1
[Vector] Print(vec 1)
------- adding reals to vector 2
General - For each integer i from 10 to 50 with increment 10, do (Actions)
Actions
[Vector] Add (Real)(vec 2, (i * 1.5454))
------- printing vector 2
[Vector] Print(vec 2)
------- adding a different data type to vector 2
[Vector] Add (Point)(vec 2, (Point(12.0, 34.0)))
[Vector] Add (Player Group)(vec 2, (All players))
[Vector] Add (Trigger)(vec 2, vector demo)
------- print again
[Vector] Print(vec 2)
------- remove first three values from vector 1
General - Repeat (Actions) 3 times
Actions
[Vector] Remove Element(vec 1, 0)
------- printing vector 1
[Vector] Print(vec 1)
------- deleting vector 1. vectors need to be deleted by hand to free memory.
[Vector] Destroy(vec 1)
------- printing vector 1
[Vector] Print(vec 1)
------- printing vector 2
[Vector] Print(vec 2)
------- vectors can easily be passed to other functions since they are just represented by their ids...
do stuff with vector(vec 2)
------- interate through vector elements and calculate sum
General - For each integer i from 0 to ([Vector] Get Last Element ID(vec 2)) with increment 1, do (Actions)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
------- we do not want to add points or unit groups to reals, so we check for value type.
([Vector] Get Element Type(vec 2, i)) == Fixed
Then
Variable - Modify sum: + ([Vector] Get (Real)(vec 2, i))
Else
Debug - Display (Text(sum) with Any Precision decimal places) as debug output using Type 01, and Do display it in the game window
------- remember deleting vectors after use!
[Vector] Destroy(vec 2)
------- printing vector 2
[Vector] Print(vec 2)
The example produces the following output:
Quote:
00:00:00.00 Vector (ID: 1) with 10 elements: (There is a total of 2 active vectors)
00:00:00.00 0: 1
00:00:00.00 1: 2
00:00:00.00 2: 3
00:00:00.00 3: 4
00:00:00.00 4: 5
00:00:00.00 5: 6
00:00:00.00 6: 7
00:00:00.00 7: 8
00:00:00.00 8: 9
00:00:00.00 9: 10
00:00:00.00 Vector (ID: 2) with 5 elements: (There is a total of 2 active vectors)
00:00:00.00 0: 15.4541
00:00:00.00 1: 30.9082
00:00:00.00 2: 46.3623
00:00:00.00 3: 61.8164
00:00:00.00 4: 77.2705
00:00:00.00 Vector (ID: 2) with 8 elements: (There is a total of 2 active vectors)
00:00:00.00 0: 15.4541
00:00:00.00 1: 30.9082
00:00:00.00 2: 46.3623
00:00:00.00 3: 61.8164
00:00:00.00 4: 77.2705
00:00:00.00 5: Point [x: 12.00, y: 34.00, z: 0.00]
00:00:00.00 6: Player Group: { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
00:00:00.00 7: Trigger: libCONT_gt_vectordemo_Func
00:00:00.00 Vector (ID: 1) with 7 elements: (There is a total of 2 active vectors)
00:00:00.00 0: 4
00:00:00.00 1: 5
00:00:00.00 2: 6
00:00:00.00 3: 7
00:00:00.00 4: 8
00:00:00.00 5: 9
00:00:00.00 6: 10
00:00:00.00 Vector does not exist. (There is a total of 1 active vectors)
00:00:00.00 Vector (ID: 2) with 8 elements: (There is a total of 1 active vectors)
00:00:00.00 0: 15.4541
00:00:00.00 1: 30.9082
00:00:00.00 2: 46.3623
00:00:00.00 3: 61.8164
00:00:00.00 4: 77.2705
00:00:00.00 5: Point [x: 12.00, y: 34.00, z: 0.00]
00:00:00.00 6: Player Group: { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
00:00:00.00 7: Trigger: libCONT_gt_vectordemo_Func
00:00:00.00 231.8115
00:00:00.00 Vector does not exist. (There is a total of 0 active vectors)
Released Version 0.4, adding the Queue container type!
Queue
A queue is a FIFO (First in first out) data structure. In comparison to the vector container, the queue allows removing the first element with O(1) complexity and without copying all following entries. However, a queue does not allow index based element access or removal of elements at a specific point.
Available functions:
Just as the vector container, the queue has its own versions of the Create, Exists, Get Element Count and Get Active Queue Count functions which work similar to the vector counterparts.
The following methods are unique to the queue container:
DataType [Queue] Get First Element Type(int QueueID)
Returns the data type of the first element within the queue. Returns a default value if the accessed value does not exist.
Complexity: O(1)
<datatype> [Queue] Get First (<datatype>)(int QueueID)
Returns the first element of the queue. <datatype> stands for one of the supported data types for the queue container. Returns a default value if the accessed value does not exist.
Complexity: O(1)
Available actions:
Just as the vector container, the queue has its own versions of the Destroy, Clear and Print functions which work similar to the vector counterparts.
The following methods are unique to the queue container:
void [Queue] Remove First(int QueueID)
Removes the first element of the queue. Does nothing if the container is empty or doesnt exist.
Complexity: O(1)
void [Queue] Add (<datatype>)(int QueueID, <datatype> Value)
Adds a new element to the end of the queue. <datatype> stands for one of the supported data types for the queue container. Does nothing if the container doesnt exist.
Complexity: O(1)
New Version 0.5 available. As long as there are no bugs this should be the last version for now. :)
v0.5
- Performance improvements by applying micro optimizations to the internal workings of the library. Optimizations focused on removal of sub function calls and minimizing the amount of String concatinations, achieving 1.4x - 2.5x speedup for most functions.
New Version 0.6 available! This version brings a couple of lightweight but useful new features!
v0.6
- Added a new constructor for the vector container, allowing to create a vector with an initial size. The constructor retains O(1) complexity regardless of the initial vector size and does not initialize the vector members to any value. This can lead to significant performance improvements because it makes it possible to use [Vector] Set instead of [Vector] Add to initialize vector values.
For example, lets say you wanted to initialize a vector with integers from 1 to 10 you can now do it like this:
Note that a vector initialized with a size of 10 can still grow to a size of 11 and beyond when using [Vector] Add.
- Added the possibility to link vectors to units by using the new "[Vector] Attach To Unit" function. This allows linking all sorts of metadata to a unit, without the limitation of only 64 custom values or 64 behaviors. It also allows attaching and mixing any supported data types since the vector container can store multiple data types at once. Added vectors can be removed and retrieved by "[Vector] Remove Attached Vector From Unit" and "[Vector] Get Vector Attached To Unit" functions. Note that you still need to unattach and destroy attached vectors once the unit dies or gets removed from the game, otherwise you will get datatable value leaks.
- The vector container now supports the "Unit" data type.
Generic Container Library
Containers are an essencial part of every programming language and used on a daily basis, sadly Galaxy Script does not provide many useful native containers. The only container classes available are vectors like objects for units (Unit Group) and players (Player Group). However, for all other datatypes its necessary to use arrays with a fixed size to manage collections of elements.
This often leads to wasted memory capacity and very time consuming and tideous array management, which is why i decided to start working on a container library for my own use aswell as for the community.
The following container types are currently supported:
Vector
A vector is an array-like object which allows dynamic addition and removal of elements, as well as indexed access.
Available functions:
int [Vector] Create()
Creates a new vector and returns its unique ID. Vectors should be destroyed after usage to free memory. Please note that empty vectors still exist and need to be manually destroyed.
Complexity: O(1)
int [Vector] Create With Initial Size(int size)
Creates a new vector and returns its unique ID. The vector will be initialized to initially have the specified size. This can lead to performance improvements because it allows initializing vector values by using the set instead of the add method (See changelog for more details on this). The vector values will not be initialized after calling the constructor and return their default values when retrieved. The vector will grow once using the add method. Vectors should be destroyed after usage to free memory. Please note that empty vectors still exist and need to be manually destroyed.
Complexity: O(1)
bool [Vector] Exists(int Vector ID)
Checks if the specified vector exists. Vectors should be destroyed after usage to free memory. Please note that empty vectors still exist and need to be manually destroyed.
Complexity: O(1)
int [Vector] Get Element Count(int Vector ID)
Returns the number of elements within the vector.
Complexity: O(1)
DataType [Vector] Get Element Type(int Vector ID, int Element ID)
Returns the type of the specified element ID. Vectors can store multiple different data types at the same time, so this function may be useful to filter them later.
Complexity: O(1)
int [Vector] Get Last Element ID(int Vector ID)
Returns the last valid element ID of the specified vector for usage in range based for loops. The last valid element ID equals the element count - 1.
Complexity: O(1)
int [Vector] Get Active Vector Count()
Returns the total amount of active (non destroyed) vectors. Useful for debugging purposes.
Complexity: O(1)
<datatype>[Vector] Get (<datatype>)(int Vector ID, int Element ID)
Returns the element value at the specified index. <datatype> stands for one of the supported data types for the vector container.
Complexity: O(1)
int [Vector] Get Vector Attached To Unit(unit u)
Returns the vector attached to the specified unit via the "[Vector] Attach To Unit" function. Will return invalid container id if no vector is currently linked to the specified unit.
Complexity: O(1)
Available actions:
void [Vector] Remove Element(int Vector ID, int Element ID)
Removes the element at the specified index and moves all elements after it. Removing elements from very large vectors may impact performance. Please note that empty vectors still exist and need to be manually destroyed.
Complexity: O(n), where n = number of elements after the removed element.
void [Vector] Destroy(int Vector ID)
Destroys the specified vector and frees all used up memory. Vectors should be destroyed after usage to free memory. Please note that empty vectors still exist and need to be manually destroyed.
Complexity: O(n), where n = the size of the vector.
void [Vector] Print(int Vector ID)
Prints a debug output for the specified vector.
Complexity: O(n), where n = the size of the vector.
void [Vector] Add (<datatype>)(int Vector ID, <datatype> Value)
Adds a new element to the specified vector. <datatype> stands for one of the supported data types for the vector container.
Complexity: O(1)
void [Vector] Set (<datatype>)(int Vector ID, int Element ID, <datatype> Value)
Sets the element value at the specified index. Does nothing if the element ID is not part of the vector. <datatype> stands for one of the supported data types for the vector container.
Complexity: O(1)
void [Vector] Clear(int Vector ID)
Removes all elements of the specified vector without destroying the vector itself.
Complexity: O(n), where n = the size of the vector.
void [Vector] Attach To Unit(int vectorID, unit u)
Attaches the specified vector to the specified unit. Will do nothing if the vector does not exist.
Please note that a vector attached to a unit will not get destroyed once the unit dies or gets removed from the game. You will have to manually unattach AND destroy the vector on unit death if wanted to prevent data table value leaks.
Complexity: O(1)
void [Vector] Remove Attached Vector From Unit(unit u)
Removes the attached vector from the specified unit. This method should be called everytime the unit dies or gets removed from the game to prevent memory leaks.
Complexity: O(1)
Queue
A queue is a FIFO (First in first out) data structure. In comparison to the vector container, the queue allows removing the first element with O(1) complexity and without copying all following entries. However, a queue does not allow index based element access or removal of elements at a specific point.
Available functions:
Just as the vector container, the queue has its own versions of the Create, Exists, Get Element Count and Get Active Queue Count functions which work similar to the vector counterparts.
The following methods are unique to the queue container:
DataType [Queue] Get First Element Type(int QueueID)
Returns the data type of the first element within the queue. Returns a default value if the accessed value does not exist.
Complexity: O(1)
<datatype> [Queue] Get First (<datatype>)(int QueueID)
Returns the first element of the queue. <datatype> stands for one of the supported data types for the queue container. Returns a default value if the accessed value does not exist.
Complexity: O(1)
Available actions:
Just as the vector container, the queue has its own versions of the Destroy, Clear and Print functions which work similar to the vector counterparts.
The following methods are unique to the queue container:
void [Queue] Remove First(int QueueID)
Removes the first element of the queue. Does nothing if the container is empty or doesnt exist.
Complexity: O(1)
void [Queue] Add (<datatype>)(int QueueID, <datatype> Value)
Adds a new element to the end of the queue. <datatype> stands for one of the supported data types for the queue container. Does nothing if the container doesnt exist.
Complexity: O(1)
The following data types are currently supported:
Actor
Bank
Boolean
Camera Object
Color
Integer
Order
Player Group
Point
Real
Region
String
Text Tag
Text
Timer
Trigger
Unit Group
Dialog
Dialog Item
Sound
Sound Link
Unit
Possible issues:
Since all containers are based on data tables it is mandatory NOT to clear the global data table at any point in time to avoid data loss and corruption of the library.
In the very rare case of key name conflics you may edit the data table key prefixes within the "Containers - > <Container Type> -> Vars -> Constants" folder to match your needs.
Changelog:
v0.6
- Added a new constructor for the vector container, allowing to create a vector with an initial size. The constructor retains O(1) complexity regardless of the initial vector size and does not initialize the vector members to any value. This can lead to significant performance improvements because it makes it possible to use [Vector] Set instead of [Vector] Add to initialize vector values.
For example, lets say you wanted to initialize a vector with integers from 1 to 10 you can now do it like this:
Note that a vector initialized with a size of 10 can still grow to a size of 11 and beyond when using [Vector] Add.
- Added the possibility to link vectors to units by using the new "[Vector] Attach To Unit" function. This allows linking all sorts of metadata to a unit, without the limitation of only 64 custom values or 64 behaviors. It also allows attaching and mixing any supported data types since the vector container can store multiple data types at once. Added vectors can be removed and retrieved by "[Vector] Remove Attached Vector From Unit" and "[Vector] Get Vector Attached To Unit" functions. Note that you still need to unattach and destroy attached vectors once the unit dies or gets removed from the game, otherwise you will get datatable value leaks.
- The vector container now supports the "Unit" data type.
v0.5
- Performance improvements by applying micro optimizations to the internal workings of the library. Optimizations focused on removal of sub function calls and minimizing the amount of String concatinations, achieving 1.4x - 2.5x speedup for most functions.
v0.4
- Added Queue container
v0.3
- Performance improvements
- Memory usage has been decreased significantly
- Source code size reduced
- New action: "void [Vector] Clear(int Vector ID" has been added to the vector container
v0.2
- Added "void [Vector] Set (<datatype>(*))(int Vector ID, int Element ID, <datatype>(*) Value)" action.
FAQ:
Q: Where are stack and map?
A: Map is already available in form of data tables. A stack can easily be implemented by using the vector container (Just add elements at the end and get + remove the last element). A direct stack implementation within the library would not make sense since it could not be more efficient than the current vector implementation.
Q: How much overhead does importing and using the container library cause?
A: The source code of the library is relatively small (Approx 1000 lines), and the size is only because it needs wrappers for every data type. The library only defines a minimal amount of global variables and has no triggers.
The performance of the containers itself is optimized as far as possible, but will always be slower than using native implementations, like Unit Group. Its also slower than using arrays.
Q: Can a container store multiple different data types at once?
A: Yes. Even though its probably not necessary to do that very often it can still be a very mighty instrument in conjunction with the Get Element Type() method. For example it can allow you to return multiple values from a function into a vector buffer.
Q: Whats the purpose of the "Get Vector Count" method?
A: This method returns the currently active amount of vectors. It can be useful to find out if you forgot to destroy any vectors using the [Vector] Destroy method.
Q: Why arent there more supportive methods, such as "[Vector] Contains"?
A: It would not be possible to implement methods of this kind in an efficient matter because a vector can store multiple different data types at once, which, for example, would require a wrapper for every data type which is supposed to work with this method.
However, you can easily implement a method like this by yourself for your own needs, for example by guarantying that the specified vector contains integers only.
Examples of usage:
Vector:
The example produces the following output:
Nice. This could come in handy for some of those bigger, more complex maps that need better memory management.
Released version 0.3 and added FAQ.
Please let me know if you guys encounter any bugs or have any questions. :)
Released Version 0.4, adding the Queue container type!
Queue
A queue is a FIFO (First in first out) data structure. In comparison to the vector container, the queue allows removing the first element with O(1) complexity and without copying all following entries. However, a queue does not allow index based element access or removal of elements at a specific point.
Available functions:
Just as the vector container, the queue has its own versions of the Create, Exists, Get Element Count and Get Active Queue Count functions which work similar to the vector counterparts.
The following methods are unique to the queue container:
DataType [Queue] Get First Element Type(int QueueID)
Returns the data type of the first element within the queue. Returns a default value if the accessed value does not exist.
Complexity: O(1)
<datatype> [Queue] Get First (<datatype>)(int QueueID)
Returns the first element of the queue. <datatype> stands for one of the supported data types for the queue container. Returns a default value if the accessed value does not exist.
Complexity: O(1)
Available actions:
Just as the vector container, the queue has its own versions of the Destroy, Clear and Print functions which work similar to the vector counterparts.
The following methods are unique to the queue container:
void [Queue] Remove First(int QueueID)
Removes the first element of the queue. Does nothing if the container is empty or doesnt exist.
Complexity: O(1)
void [Queue] Add (<datatype>)(int QueueID, <datatype> Value)
Adds a new element to the end of the queue. <datatype> stands for one of the supported data types for the queue container. Does nothing if the container doesnt exist.
Complexity: O(1)
New Version 0.5 available. As long as there are no bugs this should be the last version for now. :)
v0.5
- Performance improvements by applying micro optimizations to the internal workings of the library. Optimizations focused on removal of sub function calls and minimizing the amount of String concatinations, achieving 1.4x - 2.5x speedup for most functions.
New Version 0.6 available! This version brings a couple of lightweight but useful new features!
v0.6
- Added a new constructor for the vector container, allowing to create a vector with an initial size. The constructor retains O(1) complexity regardless of the initial vector size and does not initialize the vector members to any value. This can lead to significant performance improvements because it makes it possible to use [Vector] Set instead of [Vector] Add to initialize vector values.
For example, lets say you wanted to initialize a vector with integers from 1 to 10 you can now do it like this:
Note that a vector initialized with a size of 10 can still grow to a size of 11 and beyond when using [Vector] Add.
- Added the possibility to link vectors to units by using the new "[Vector] Attach To Unit" function. This allows linking all sorts of metadata to a unit, without the limitation of only 64 custom values or 64 behaviors. It also allows attaching and mixing any supported data types since the vector container can store multiple data types at once. Added vectors can be removed and retrieved by "[Vector] Remove Attached Vector From Unit" and "[Vector] Get Vector Attached To Unit" functions. Note that you still need to unattach and destroy attached vectors once the unit dies or gets removed from the game, otherwise you will get datatable value leaks.
- The vector container now supports the "Unit" data type.