MCPcopy Create free account
hub / github.com/OpenPrinting/cups / cups_array_find

Function cups_array_find

cups/array.c:1190–1320  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1188 */
1189
1190static int /* O - Index of match */
1191cups_array_find(cups_array_t *a, /* I - Array */
1192 void *e, /* I - Element */
1193 int prev, /* I - Previous index */
1194 int *rdiff) /* O - Difference of match */
1195{
1196 int left, /* Left side of search */
1197 right, /* Right side of search */
1198 current, /* Current element */
1199 diff; /* Comparison with current element */
1200
1201
1202 DEBUG_printf(("7cups_array_find(a=%p, e=%p, prev=%d, rdiff=%p)", (void *)a, e, prev, (void *)rdiff));
1203
1204 if (a->compare)
1205 {
1206 /*
1207 * Do a binary search for the element...
1208 */
1209
1210 DEBUG_puts("9cups_array_find: binary search");
1211
1212 if (prev >= 0 && prev < a->num_elements)
1213 {
1214 /*
1215 * Start search on either side of previous...
1216 */
1217
1218 if ((diff = (*(a->compare))(e, a->elements[prev], a->data)) == 0 ||
1219 (diff < 0 && prev == 0) ||
1220 (diff > 0 && prev == (a->num_elements - 1)))
1221 {
1222 /*
1223 * Exact or edge match, return it!
1224 */
1225
1226 DEBUG_printf(("9cups_array_find: Returning %d, diff=%d", prev, diff));
1227
1228 *rdiff = diff;
1229
1230 return (prev);
1231 }
1232 else if (diff < 0)
1233 {
1234 /*
1235 * Start with previous on right side...
1236 */
1237
1238 left = 0;
1239 right = prev;
1240 }
1241 else
1242 {
1243 /*
1244 * Start with previous on left side...
1245 */
1246
1247 left = prev;

Callers 3

cupsArrayFindFunction · 0.85
cupsArrayRemoveFunction · 0.85
cups_array_addFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected