* Remove duplicates from a pre-sorted array, according to a user-supplied * comparator. Usually the array should have been sorted with qsort() using * the same arguments. Return the new size. */
| 18 | * the same arguments. Return the new size. |
| 19 | */ |
| 20 | static inline size_t |
| 21 | qunique(void *array, size_t elements, size_t width, |
| 22 | int (*compare) (const void *, const void *)) |
| 23 | { |
| 24 | char *bytes = (char *) array; |
| 25 | size_t i, |
| 26 | j; |
| 27 | |
| 28 | if (elements <= 1) |
| 29 | return elements; |
| 30 | |
| 31 | for (i = 1, j = 0; i < elements; ++i) |
| 32 | { |
| 33 | if (compare(bytes + i * width, bytes + j * width) != 0 && |
| 34 | ++j != i) |
| 35 | memcpy(bytes + j * width, bytes + i * width, width); |
| 36 | } |
| 37 | |
| 38 | return j + 1; |
| 39 | } |
| 40 | |
| 41 | /* |
| 42 | * Like qunique(), but takes a comparator with an extra user data argument |
no test coverage detected