mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
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
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
|
||||
#include "_int.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "lib/qunique.h"
|
||||
|
||||
/* arguments are assumed sorted & unique-ified */
|
||||
bool
|
||||
@ -308,23 +309,13 @@ internal_size(int *a, int len)
|
||||
ArrayType *
|
||||
_int_unique(ArrayType *r)
|
||||
{
|
||||
int *tmp,
|
||||
*dr,
|
||||
*data;
|
||||
int num = ARRNELEMS(r);
|
||||
bool duplicates_found; /* not used */
|
||||
|
||||
if (num < 2)
|
||||
return r;
|
||||
num = qunique_arg(ARRPTR(r), num, sizeof(int), isort_cmp,
|
||||
&duplicates_found);
|
||||
|
||||
data = tmp = dr = ARRPTR(r);
|
||||
while (tmp - data < num)
|
||||
{
|
||||
if (*tmp != *dr)
|
||||
*(++dr) = *tmp++;
|
||||
else
|
||||
tmp++;
|
||||
}
|
||||
return resize_intArrayType(r, dr + 1 - ARRPTR(r));
|
||||
return resize_intArrayType(r, num);
|
||||
}
|
||||
|
||||
void
|
||||
|
Reference in New Issue
Block a user