DayZ 1.24
Loading...
Searching...
No Matches
BitArray.c
Go to the documentation of this file.
1//this class allows for creation and manipulation of arrays which hold unique IDs, and allow for bitwise-like operation over these IDs
2//essentially, this extends single INT to any legth when it comes to holding and manipulating individual bits
3
4const int BIT_INT_SIZE = 32;
6{
7 static int IDToIndex(int id)
8 {
10 int index = (id - (m_NumOfItems * BIT_INT_SIZE)) - 1;
11 return index;
12 }
13
14 static int IDToMask(int id)
15 {
16 int index = BitArray.IDToIndex(id);
17 int bit = 1 << index;
18 return bit;
19 }
22 {
25
26 for (int i = 0; i <= m_NumOfItems; i++)
27 bit_array.Insert(0);
28
29 return bit_array;
30 }
33 {
34 return ((bit_array.Count()) * BIT_INT_SIZE);
35 }
36
38 static int IDToNumOfItems(int id)
39 {
40 int m_NumOfItems = id / BIT_INT_SIZE;
41 if (id % BIT_INT_SIZE == 0) m_NumOfItems--;
42 return m_NumOfItems;
43 }
44
46 {
47 int m_NumOfItems = BitArray.IDToNumOfItems(id);//TODO: check for too big id
48 int bit = BitArray.IDToMask(id);
49
51
52 for (int i = 0; i <= m_NumOfItems; i++)
53 bit_array.Insert(0);
55 return bit_array;
56 }
57
59 {
60 if (BitArray.IDToNumOfItems(id) > bit_array.Count())
61 return false;
62 else
63 {
67
69 return true;
70 else
71 return false;
72 }
73 }
74
75 static bool AddIDToMask(array<int> bit_array, int id)
76 {
77 if (BitArray.IDToNumOfItems(id) > bit_array.Count())
78 return false;
79 else
80 {
82 int bit = BitArray.IDToMask(id);
85 return true;
86 }
87 }
88};
const int BIT_INT_SIZE
Definition BitArray.c:4
static int IDToIndex(int id)
Definition BitArray.c:7
static bool AddIDToMask(array< int > bit_array, int id)
Definition BitArray.c:75
static array< int > CreateMaskArray(int size)
Creates an array which will be able to accomodate 'size' number of unique IDs.
Definition BitArray.c:21
static bool IsMaskContainID(array< int > bit_array, int id)
Definition BitArray.c:58
static int IDToNumOfItems(int id)
Returns number of INTs required to hold this ID minus 1(ie for 32, the result is 0,...
Definition BitArray.c:38
static int IDToMask(int id)
Definition BitArray.c:14
static array< int > CreateArrayWithID(int id)
Definition BitArray.c:45
static int GetBitCount(array< int > bit_array)
Returns number of bits this array can hold.
Definition BitArray.c:32