| 434 | */ |
| 435 | |
| 436 | void * /* O - Element found or @code NULL@ */ |
| 437 | cupsArrayFind(cups_array_t *a, /* I - Array */ |
| 438 | void *e) /* I - Element */ |
| 439 | { |
| 440 | int current, /* Current element */ |
| 441 | diff, /* Difference */ |
| 442 | hash; /* Hash index */ |
| 443 | |
| 444 | |
| 445 | /* |
| 446 | * Range check input... |
| 447 | */ |
| 448 | |
| 449 | if (!a || !e) |
| 450 | return (NULL); |
| 451 | |
| 452 | /* |
| 453 | * See if we have any elements... |
| 454 | */ |
| 455 | |
| 456 | if (!a->num_elements) |
| 457 | return (NULL); |
| 458 | |
| 459 | /* |
| 460 | * Yes, look for a match... |
| 461 | */ |
| 462 | |
| 463 | if (a->hash) |
| 464 | { |
| 465 | hash = (*(a->hashfunc))(e, a->data); |
| 466 | |
| 467 | if (hash < 0 || hash >= a->hashsize) |
| 468 | { |
| 469 | current = a->current; |
| 470 | hash = -1; |
| 471 | } |
| 472 | else |
| 473 | { |
| 474 | current = a->hash[hash]; |
| 475 | |
| 476 | if (current < 0 || current >= a->num_elements) |
| 477 | current = a->current; |
| 478 | } |
| 479 | } |
| 480 | else |
| 481 | { |
| 482 | current = a->current; |
| 483 | hash = -1; |
| 484 | } |
| 485 | |
| 486 | current = cups_array_find(a, e, current, &diff); |
| 487 | if (!diff) |
| 488 | { |
| 489 | /* |
| 490 | * Found a match! If the array does not contain unique values, find |
| 491 | * the first element that is the same... |
| 492 | */ |
| 493 | |