summaryrefslogtreecommitdiffstats
path: root/DTArrays.c
diff options
context:
space:
mode:
Diffstat (limited to 'DTArrays.c')
-rw-r--r--DTArrays.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/DTArrays.c b/DTArrays.c
new file mode 100644
index 0000000..0b78ef4
--- /dev/null
+++ b/DTArrays.c
@@ -0,0 +1,52 @@
+#strict 2
+
+global func ArrayErase(array& arr, int index)
+{
+ if(index < GetLength(arr))
+ {
+ for(var i = index; i < GetLength(arr) - 1; ++i)
+ {
+ arr[i] = arr[i + 1];
+ }
+ SetLength(arr, GetLength(arr) - 1);
+ }
+}
+
+global func ArrayEraseItem(array& arr, item, bool multiple)
+{
+ var index, count = 0;
+ while((index = GetIndexOf2(item, arr)) != -1)
+ {
+ ArrayErase(arr, index);
+ if(!multiple)
+ {
+ return index;
+ }
+ ++count;
+ }
+ return (!multiple && -1) || count;
+}
+
+global func ArrayInsert(array& arr, int index, value)
+{
+ for(var i = GetLength(arr); i > index; --i)
+ {
+ arr[i] = arr[i - 1];
+ }
+ arr[index] = value;
+}
+
+global func ArrayAppend(array& arr, value)
+{
+ arr[GetLength(arr)] = value;
+}
+
+global func ArrayAppendArray(array& arr, array append)
+{
+ var i = GetLength(arr);
+ SetLength(arr, GetLength(arr) + GetLength(append));
+ for(var val in append)
+ {
+ arr[i++] = val;
+ }
+}