/src/postgres/src/include/lib/qunique.h
Line | Count | Source |
1 | | /*------------------------------------------------------------------------- |
2 | | * |
3 | | * qunique.h |
4 | | * inline array unique functions |
5 | | * Portions Copyright (c) 2019-2026, PostgreSQL Global Development Group |
6 | | * |
7 | | * IDENTIFICATION |
8 | | * src/include/lib/qunique.h |
9 | | *------------------------------------------------------------------------- |
10 | | */ |
11 | | |
12 | | #ifndef QUNIQUE_H |
13 | | #define QUNIQUE_H |
14 | | |
15 | | /* |
16 | | * Remove duplicates from a pre-sorted array, according to a user-supplied |
17 | | * comparator. Usually the array should have been sorted with qsort() using |
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 | 0 | { |
24 | 0 | char *bytes = (char *) array; |
25 | 0 | size_t i, |
26 | 0 | j; |
27 | |
|
28 | 0 | if (elements <= 1) |
29 | 0 | return elements; |
30 | | |
31 | 0 | for (i = 1, j = 0; i < elements; ++i) |
32 | 0 | { |
33 | 0 | if (compare(bytes + i * width, bytes + j * width) != 0 && |
34 | 0 | ++j != i) |
35 | 0 | memcpy(bytes + j * width, bytes + i * width, width); |
36 | 0 | } |
37 | |
|
38 | 0 | return j + 1; |
39 | 0 | } Unexecuted instantiation: ginutil.c:qunique Unexecuted instantiation: nbtinsert.c:qunique Unexecuted instantiation: nbtpreprocesskeys.c:qunique Unexecuted instantiation: nbtutils.c:qunique Unexecuted instantiation: nodeTidscan.c:qunique Unexecuted instantiation: acl.c:qunique Unexecuted instantiation: tsgistidx.c:qunique Unexecuted instantiation: tsquery_op.c:qunique Unexecuted instantiation: tsvector_op.c:qunique Unexecuted instantiation: xid8funcs.c:qunique Unexecuted instantiation: syscache.c:qunique |
40 | | |
41 | | /* |
42 | | * Like qunique(), but takes a comparator with an extra user data argument |
43 | | * which is passed through, for compatibility with qsort_arg(). |
44 | | */ |
45 | | static inline size_t |
46 | | qunique_arg(void *array, size_t elements, size_t width, |
47 | | int (*compare) (const void *, const void *, void *), |
48 | | void *arg) |
49 | 0 | { |
50 | 0 | char *bytes = (char *) array; |
51 | 0 | size_t i, |
52 | 0 | j; |
53 | |
|
54 | 0 | if (elements <= 1) |
55 | 0 | return elements; |
56 | | |
57 | 0 | for (i = 1, j = 0; i < elements; ++i) |
58 | 0 | { |
59 | 0 | if (compare(bytes + i * width, bytes + j * width, arg) != 0 && |
60 | 0 | ++j != i) |
61 | 0 | memcpy(bytes + j * width, bytes + i * width, width); |
62 | 0 | } |
63 | |
|
64 | 0 | return j + 1; |
65 | 0 | } Unexecuted instantiation: ginutil.c:qunique_arg Unexecuted instantiation: nbtinsert.c:qunique_arg Unexecuted instantiation: nbtpreprocesskeys.c:qunique_arg Unexecuted instantiation: nbtutils.c:qunique_arg Unexecuted instantiation: nodeTidscan.c:qunique_arg Unexecuted instantiation: acl.c:qunique_arg Unexecuted instantiation: tsgistidx.c:qunique_arg Unexecuted instantiation: tsquery_op.c:qunique_arg Unexecuted instantiation: tsvector_op.c:qunique_arg Unexecuted instantiation: xid8funcs.c:qunique_arg Unexecuted instantiation: syscache.c:qunique_arg |
66 | | |
67 | | #endif /* QUNIQUE_H */ |