Home | History | Annotate | Download | only in coregrind

Lines Matching defs:xa

58    XArray* xa;
68 xa = alloc_fn( cc, sizeof(struct _XArray) );
69 xa->alloc_fn = alloc_fn;
70 xa->cc = cc;
71 xa->free_fn = free_fn;
72 xa->cmpFn = NULL;
73 xa->elemSzB = elemSzB;
74 xa->usedsizeE = 0;
75 xa->totsizeE = 0;
76 xa->sorted = False;
77 xa->arr = NULL;
78 return xa;
81 XArray* VG_(cloneXA)( const HChar* cc, const XArray* xa )
85 vg_assert(xa);
86 vg_assert(xa->alloc_fn);
87 vg_assert(xa->free_fn);
88 vg_assert(xa->elemSzB >= 1);
89 nyu_cc = cc ? cc : xa->cc;
90 nyu = xa->alloc_fn( nyu_cc, sizeof(struct _XArray) );
93 *nyu = *xa;
105 VG_(memcpy)( nyu->arr, xa->arr, nyu->totsizeE * nyu->elemSzB );
111 void VG_(deleteXA) ( XArray* xa )
113 vg_assert(xa);
114 vg_assert(xa->free_fn);
115 if (xa->arr)
116 xa->free_fn(xa->arr);
117 xa->free_fn(xa);
120 void VG_(setCmpFnXA) ( XArray* xa, XACmpFn_t compar )
122 vg_assert(xa);
124 xa->cmpFn = compar;
125 xa->sorted = False;
128 inline void* VG_(indexXA) ( const XArray* xa, Word n )
130 vg_assert(xa);
133 xa is modified. */
134 vg_assert((UWord)n < (UWord)xa->usedsizeE);
135 return ((char*)xa->arr) + n * xa->elemSzB;
138 void VG_(hintSizeXA) ( XArray* xa, Word n)
148 vg_assert(xa);
149 vg_assert(xa->usedsizeE == 0);
150 vg_assert(xa->totsizeE == 0);
151 vg_assert(!xa->arr);
152 xa->arr = xa->alloc_fn(xa->cc, n * xa->elemSzB);
153 xa->totsizeE = n;
156 static inline void ensureSpaceXA ( XArray* xa )
158 if (xa->usedsizeE == xa->totsizeE) {
161 if (xa->totsizeE == 0)
162 vg_assert(!xa->arr);
163 if (xa->totsizeE > 0)
164 vg_assert(xa->arr);
165 if (xa->totsizeE == 0) {
171 if (xa->elemSzB == 1) newsz = 8;
172 else if (xa->elemSzB == 2) newsz = 4;
175 newsz = 2 + (3 * xa->totsizeE) / 2; /* 2 * xa->totsizeE; */
177 if (0 && xa->totsizeE >= 10000)
179 xa->totsizeE, newsz);
180 tmp = xa->alloc_fn(xa->cc, newsz * xa->elemSzB);
181 if (xa->usedsizeE > 0)
182 VG_(memcpy)(tmp, xa->arr, xa->usedsizeE * xa->elemSzB);
183 if (xa->arr)
184 xa->free_fn(xa->arr);
185 xa->arr = tmp;
186 xa->totsizeE = newsz;
190 Word VG_(addToXA) ( XArray* xa, const void* elem )
192 vg_assert(xa);
194 vg_assert(xa->totsizeE >= 0);
195 vg_assert(xa->usedsizeE >= 0 && xa->usedsizeE <= xa->totsizeE);
196 ensureSpaceXA( xa );
197 vg_assert(xa->usedsizeE < xa->totsizeE);
198 vg_assert(xa->arr);
199 VG_(memcpy)( ((UChar*)xa->arr) + xa->usedsizeE * xa->elemSzB,
200 elem, xa->elemSzB );
201 xa->usedsizeE++;
202 xa->sorted = False;
203 return xa->usedsizeE-1;
206 Word VG_(addBytesToXA) ( XArray* xa, const void* bytesV, Word nbytes )
209 vg_assert(xa);
210 vg_assert(xa->elemSzB == 1);
212 vg_assert(xa->totsizeE >= 0);
213 vg_assert(xa->usedsizeE >= 0 && xa->usedsizeE <= xa->totsizeE);
214 r = xa->usedsizeE;
216 ensureSpaceXA( xa );
217 vg_assert(xa->usedsizeE < xa->totsizeE);
218 vg_assert(xa->arr);
219 * (((UChar*)xa->arr) + xa->usedsizeE) = ((const UChar*)bytesV)[i];
220 xa->usedsizeE++;
222 xa->sorted = False;
226 void VG_(sortXA) ( XArray* xa )
228 vg_assert(xa);
229 vg_assert(xa->cmpFn);
230 VG_(ssort)( xa->arr, xa->usedsizeE, xa->elemSzB, xa->cmpFn );
231 xa->sorted = True;
234 Bool VG_(lookupXA_UNSAFE) ( const XArray* xa, const void* key,
240 vg_assert(xa);
242 hi = xa->usedsizeE-1;
247 midv = VG_(indexXA)( xa, mid );
252 vg_assert(cmpFn( key, VG_(indexXA)(xa, lo) ) >= 0);
253 vg_assert(cmpFn( key, VG_(indexXA)(xa, hi) ) <= 0);
257 && 0 == cmpFn( key, VG_(indexXA)(xa, (*first)-1))) {
263 while (*last < xa->usedsizeE-1
264 && 0 == cmpFn( key, VG_(indexXA)(xa, (*last)+1))) {
272 Bool VG_(lookupXA) ( const XArray* xa, const void* key,
275 vg_assert(xa);
276 vg_assert(xa->cmpFn);
277 vg_assert(xa->sorted);
278 return VG_(lookupXA_UNSAFE)(xa, key, first, last, xa->cmpFn);
281 Word VG_(sizeXA) ( const XArray* xa )
283 vg_assert(xa);
284 return xa->usedsizeE;
287 void VG_(dropTailXA) ( XArray* xa, Word n )
289 vg_assert(xa);
291 vg_assert(n <= xa->usedsizeE);
292 xa->usedsizeE -= n;
295 void VG_(dropHeadXA) ( XArray* xa, Word n )
297 vg_assert(xa);
299 vg_assert(n <= xa->usedsizeE);
303 if (n == xa->usedsizeE) {
304 xa->usedsizeE = 0;
308 vg_assert(xa->usedsizeE - n > 0);
309 VG_(memcpy)( (char*)xa->arr,
310 ((char*)xa->arr) + n * xa->elemSzB,
311 (xa->usedsizeE - n) * xa->elemSzB );
312 xa->usedsizeE -= n;
315 void VG_(removeIndexXA)( XArray* xa, Word n )
317 vg_assert(xa);
319 vg_assert(n < xa->usedsizeE);
320 if (n+1 < xa->usedsizeE) {
321 VG_(memmove)( ((char*)xa->arr) + (n+0) * xa->elemSzB,
322 ((char*)xa->arr) + (n+1) * xa->elemSzB,
323 (xa->usedsizeE - n - 1) * xa->elemSzB );
325 xa->usedsizeE--;
328 void VG_(insertIndexXA)( XArray* xa, Word n, const void* elem )
330 vg_assert(xa);
332 vg_assert(n <= xa->usedsizeE);
333 vg_assert(xa->usedsizeE >= 0 && xa->usedsizeE <= xa->totsizeE);
334 ensureSpaceXA( xa );
335 vg_assert(xa->usedsizeE < xa->totsizeE);
336 vg_assert(xa->arr);
337 if (n < xa->usedsizeE) {
338 VG_(memmove) ( ((char*)xa->arr) + (n+1) * xa->elemSzB,
339 ((char*)xa->arr) + (n+0) * xa->elemSzB,
340 (xa->usedsizeE - n) * xa->elemSzB );
342 VG_(memcpy)( ((UChar*)xa->arr) + n * xa->elemSzB,
343 elem, xa->elemSzB );
344 xa->usedsizeE++;
345 xa->sorted = False;
348 void VG_(getContentsXA_UNSAFE)( XArray* xa,
352 vg_assert(xa);
353 *ctsP = (void*)xa->arr;
354 *usedP = xa->usedsizeE;