diff options
author | Thomas Munro <tmunro@postgresql.org> | 2019-11-07 16:51:04 +1300 |
---|---|---|
committer | Thomas Munro <tmunro@postgresql.org> | 2019-11-07 17:00:48 +1300 |
commit | 7815e7efdb4ce9575b5d8460beb0dd2569d7ca3a (patch) | |
tree | dc3d1795259ab8c2dafc371cbd89725b43abc2da /src/backend/utils/adt/tsgistidx.c | |
parent | 3feb6ace7cfe8edbf6db702de06dc9295f307a8e (diff) |
Add reusable routine for making arrays unique.
Introduce qunique() and qunique_arg(), which can be used after qsort()
and qsort_arg() respectively to remove duplicate values. Use it where
appropriate.
Author: Thomas Munro
Reviewed-by: Tom Lane (in an earlier version)
Discussion: https://postgr.es/m/CAEepm%3D2vmFTNpAmwbGGD2WaryM6T3hSDVKQPfUwjdD_5XY6vAA%40mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/tsgistidx.c')
-rw-r--r-- | src/backend/utils/adt/tsgistidx.c | 29 |
1 files changed, 3 insertions, 26 deletions
diff --git a/src/backend/utils/adt/tsgistidx.c b/src/backend/utils/adt/tsgistidx.c index 6ff71a49b8f..af5b6809c50 100644 --- a/src/backend/utils/adt/tsgistidx.c +++ b/src/backend/utils/adt/tsgistidx.c @@ -16,6 +16,7 @@ #include "access/gist.h" #include "access/heaptoast.h" +#include "lib/qunique.h" #include "port/pg_bitutils.h" #include "tsearch/ts_utils.h" #include "utils/builtins.h" @@ -122,31 +123,6 @@ compareint(const void *va, const void *vb) return (a > b) ? 1 : -1; } -/* - * Removes duplicates from an array of int32. 'l' is - * size of the input array. Returns the new size of the array. - */ -static int -uniqueint(int32 *a, int32 l) -{ - int32 *ptr, - *res; - - if (l <= 1) - return l; - - ptr = res = a; - - qsort((void *) a, l, sizeof(int32), compareint); - - while (ptr - a < l) - if (*ptr != *res) - *(++res) = *ptr++; - else - ptr++; - return res + 1 - a; -} - static void makesign(BITVECP sign, SignTSVector *a) { @@ -193,7 +169,8 @@ gtsvector_compress(PG_FUNCTION_ARGS) ptr++; } - len = uniqueint(GETARR(res), val->size); + qsort(GETARR(res), val->size, sizeof(int), compareint); + len = qunique(GETARR(res), val->size, sizeof(int), compareint); if (len != val->size) { /* |