Lines Matching refs:pArray

26 VBOXSADECL(int) CrSaInit(CR_SORTARRAY *pArray, uint32_t cInitBuffer)
28 pArray->cBufferSize = cInitBuffer;
29 pArray->cSize = 0;
32 pArray->pElements = (uint64_t*)RTMemAlloc(cInitBuffer * sizeof (pArray->pElements[0]));
33 if (!pArray->pElements)
37 pArray->cBufferSize = 0;
42 pArray->pElements = NULL;
47 VBOXSADECL(void) CrSaCleanup(CR_SORTARRAY *pArray)
49 if (pArray->pElements)
50 RTMemFree(pArray->pElements);
52 CrSaInit(pArray, 0);
55 static int crSaSearch(const CR_SORTARRAY *pArray, uint64_t element)
58 int iMax = pArray->cSize;
65 uint64_t el = pArray->pElements[i];
77 static void crSaDbgValidate(const CR_SORTARRAY *pArray)
79 Assert(pArray->cSize <= pArray->cBufferSize);
80 Assert(!pArray->pElements == !pArray->cBufferSize);
81 if (!pArray->cSize)
83 uint64_t cur = pArray->pElements[0];
84 for (uint32_t i = 1; i < pArray->cSize; ++i)
86 Assert(pArray->pElements[i] > cur);
87 cur = pArray->pElements[i];
97 static int crSaInsAt(CR_SORTARRAY *pArray, uint32_t iPos, uint64_t element)
99 if (pArray->cSize == pArray->cBufferSize)
101 uint32_t cNewBufferSize = pArray->cBufferSize + 16;
103 if (pArray->pElements)
104 pNew = (uint64_t*)RTMemRealloc(pArray->pElements, cNewBufferSize * sizeof (pArray->pElements[0]));
106 pNew = (uint64_t*)RTMemAlloc(cNewBufferSize * sizeof (pArray->pElements[0]));
113 pArray->pElements = pNew;
114 pArray->cBufferSize = cNewBufferSize;
115 crSaValidate(pArray);
118 for (int32_t i = (int32_t)pArray->cSize - 1; i >= (int32_t)iPos; --i)
120 pArray->pElements[i+1] = pArray->pElements[i];
123 pArray->pElements[iPos] = element;
124 ++pArray->cSize;
126 crSaValidate(pArray);
131 static void crSaDelAt(CR_SORTARRAY *pArray, uint32_t iPos)
133 Assert(pArray->cSize > iPos);
135 for (uint32_t i = iPos; i < pArray->cSize - 1; ++i)
137 pArray->pElements[i] = pArray->pElements[i+1];
140 --pArray->cSize;
143 static int crSaAdd(CR_SORTARRAY *pArray, uint64_t element)
146 int iMax = pArray->cSize;
151 return crSaInsAt(pArray, 0, element);
157 el = pArray->pElements[i];
167 return crSaInsAt(pArray, i+1, element);
168 return crSaInsAt(pArray, i, element);
171 static int crSaRemove(CR_SORTARRAY *pArray, uint64_t element)
173 int i = crSaSearch(pArray, element);
176 crSaDelAt(pArray, i);
184 VBOXSADECL(bool) CrSaContains(const CR_SORTARRAY *pArray, uint64_t element)
186 return crSaSearch(pArray, element) >= 0;
189 VBOXSADECL(int) CrSaAdd(CR_SORTARRAY *pArray, uint64_t element)
191 return crSaAdd(pArray, element);
194 VBOXSADECL(int) CrSaRemove(CR_SORTARRAY *pArray, uint64_t element)
196 return crSaRemove(pArray, element);