summaryrefslogtreecommitdiffstats
path: root/DTArrays.c
blob: 99088de31f7d6da4ae35f4afae1720a94705668f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#strict 3

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 = GetIndexOf(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;
}

// only here for backwards compatibility; use arr[] = value directly
global func ArrayAppend(array& arr, value)
{
	arr[] = value;
}

// only here for backwards compatibility; use arr ..= append directly
global func ArrayAppendArray(array& arr, array append)
{
	arr ..= append;
}