2008-05-17 09:28:26 +08:00
|
|
|
/*
|
2010-09-21 04:08:53 +08:00
|
|
|
* contrib/intarray/_int_tool.c
|
2008-05-17 09:28:26 +08:00
|
|
|
*/
|
2008-05-12 08:00:54 +08:00
|
|
|
#include "postgres.h"
|
|
|
|
|
2018-11-24 07:56:39 +08:00
|
|
|
#include <limits.h>
|
|
|
|
|
2003-06-12 03:31:05 +08:00
|
|
|
#include "_int.h"
|
2019-10-23 11:56:22 +08:00
|
|
|
#include "catalog/pg_type.h"
|
2019-11-07 11:51:04 +08:00
|
|
|
#include "lib/qunique.h"
|
2003-06-12 03:31:05 +08:00
|
|
|
|
2011-01-09 13:39:21 +08:00
|
|
|
/* arguments are assumed sorted & unique-ified */
|
2003-06-12 03:31:05 +08:00
|
|
|
bool
|
|
|
|
inner_int_contains(ArrayType *a, ArrayType *b)
|
|
|
|
{
|
|
|
|
int na,
|
|
|
|
nb;
|
|
|
|
int i,
|
|
|
|
j,
|
|
|
|
n;
|
|
|
|
int *da,
|
|
|
|
*db;
|
|
|
|
|
|
|
|
na = ARRNELEMS(a);
|
|
|
|
nb = ARRNELEMS(b);
|
|
|
|
da = ARRPTR(a);
|
|
|
|
db = ARRPTR(b);
|
|
|
|
|
|
|
|
i = j = n = 0;
|
|
|
|
while (i < na && j < nb)
|
2011-01-09 13:39:21 +08:00
|
|
|
{
|
2003-06-12 03:31:05 +08:00
|
|
|
if (da[i] < db[j])
|
|
|
|
i++;
|
|
|
|
else if (da[i] == db[j])
|
|
|
|
{
|
|
|
|
n++;
|
|
|
|
i++;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
else
|
2011-01-09 13:39:21 +08:00
|
|
|
break; /* db[j] is not in da */
|
|
|
|
}
|
2003-06-12 03:31:05 +08:00
|
|
|
|
2021-09-08 08:44:04 +08:00
|
|
|
return (n == nb);
|
2003-06-12 03:31:05 +08:00
|
|
|
}
|
|
|
|
|
2011-01-09 13:39:21 +08:00
|
|
|
/* arguments are assumed sorted */
|
2003-06-12 03:31:05 +08:00
|
|
|
bool
|
|
|
|
inner_int_overlap(ArrayType *a, ArrayType *b)
|
|
|
|
{
|
|
|
|
int na,
|
|
|
|
nb;
|
|
|
|
int i,
|
|
|
|
j;
|
|
|
|
int *da,
|
|
|
|
*db;
|
|
|
|
|
|
|
|
na = ARRNELEMS(a);
|
|
|
|
nb = ARRNELEMS(b);
|
|
|
|
da = ARRPTR(a);
|
|
|
|
db = ARRPTR(b);
|
|
|
|
|
|
|
|
i = j = 0;
|
|
|
|
while (i < na && j < nb)
|
2011-01-09 13:39:21 +08:00
|
|
|
{
|
2003-06-12 03:31:05 +08:00
|
|
|
if (da[i] < db[j])
|
|
|
|
i++;
|
|
|
|
else if (da[i] == db[j])
|
2017-08-16 12:22:32 +08:00
|
|
|
return true;
|
2003-06-12 03:31:05 +08:00
|
|
|
else
|
|
|
|
j++;
|
2011-01-09 13:39:21 +08:00
|
|
|
}
|
2003-06-12 03:31:05 +08:00
|
|
|
|
2017-08-16 12:22:32 +08:00
|
|
|
return false;
|
2003-06-12 03:31:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ArrayType *
|
|
|
|
inner_int_union(ArrayType *a, ArrayType *b)
|
|
|
|
{
|
|
|
|
ArrayType *r = NULL;
|
|
|
|
|
2005-11-19 11:00:09 +08:00
|
|
|
CHECKARRVALID(a);
|
|
|
|
CHECKARRVALID(b);
|
|
|
|
|
2011-01-09 13:39:21 +08:00
|
|
|
if (ARRISEMPTY(a) && ARRISEMPTY(b))
|
2003-06-12 03:31:05 +08:00
|
|
|
return new_intArrayType(0);
|
2011-01-09 13:39:21 +08:00
|
|
|
if (ARRISEMPTY(a))
|
2003-06-12 03:31:05 +08:00
|
|
|
r = copy_intArrayType(b);
|
2011-01-09 13:39:21 +08:00
|
|
|
if (ARRISEMPTY(b))
|
2003-06-12 03:31:05 +08:00
|
|
|
r = copy_intArrayType(a);
|
|
|
|
|
2006-05-10 19:39:12 +08:00
|
|
|
if (!r)
|
2003-06-12 03:31:05 +08:00
|
|
|
{
|
2006-05-10 19:39:12 +08:00
|
|
|
int na = ARRNELEMS(a),
|
|
|
|
nb = ARRNELEMS(b);
|
|
|
|
int *da = ARRPTR(a),
|
|
|
|
*db = ARRPTR(b);
|
|
|
|
int i,
|
|
|
|
j,
|
|
|
|
*dr;
|
2003-06-12 03:31:05 +08:00
|
|
|
|
|
|
|
r = new_intArrayType(na + nb);
|
|
|
|
dr = ARRPTR(r);
|
|
|
|
|
|
|
|
/* union */
|
|
|
|
i = j = 0;
|
2006-05-10 19:39:12 +08:00
|
|
|
while (i < na && j < nb)
|
|
|
|
{
|
|
|
|
if (da[i] == db[j])
|
|
|
|
{
|
|
|
|
*dr++ = da[i++];
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
else if (da[i] < db[j])
|
2003-06-12 03:31:05 +08:00
|
|
|
*dr++ = da[i++];
|
|
|
|
else
|
|
|
|
*dr++ = db[j++];
|
2006-05-10 19:39:12 +08:00
|
|
|
}
|
2003-06-12 03:31:05 +08:00
|
|
|
|
|
|
|
while (i < na)
|
|
|
|
*dr++ = da[i++];
|
|
|
|
while (j < nb)
|
|
|
|
*dr++ = db[j++];
|
|
|
|
|
2006-05-10 19:39:12 +08:00
|
|
|
r = resize_intArrayType(r, dr - ARRPTR(r));
|
2003-06-12 03:31:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ARRNELEMS(r) > 1)
|
|
|
|
r = _int_unique(r);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayType *
|
|
|
|
inner_int_inter(ArrayType *a, ArrayType *b)
|
|
|
|
{
|
|
|
|
ArrayType *r;
|
|
|
|
int na,
|
|
|
|
nb;
|
|
|
|
int *da,
|
|
|
|
*db,
|
|
|
|
*dr;
|
|
|
|
int i,
|
2012-02-17 09:00:11 +08:00
|
|
|
j,
|
|
|
|
k;
|
2003-06-12 03:31:05 +08:00
|
|
|
|
2011-01-09 13:39:21 +08:00
|
|
|
if (ARRISEMPTY(a) || ARRISEMPTY(b))
|
2003-06-12 03:31:05 +08:00
|
|
|
return new_intArrayType(0);
|
|
|
|
|
|
|
|
na = ARRNELEMS(a);
|
|
|
|
nb = ARRNELEMS(b);
|
|
|
|
da = ARRPTR(a);
|
|
|
|
db = ARRPTR(b);
|
2004-10-22 03:28:36 +08:00
|
|
|
r = new_intArrayType(Min(na, nb));
|
2003-06-12 03:31:05 +08:00
|
|
|
dr = ARRPTR(r);
|
|
|
|
|
2012-02-17 09:00:11 +08:00
|
|
|
i = j = k = 0;
|
2003-06-12 03:31:05 +08:00
|
|
|
while (i < na && j < nb)
|
2011-01-09 13:39:21 +08:00
|
|
|
{
|
2003-06-12 03:31:05 +08:00
|
|
|
if (da[i] < db[j])
|
|
|
|
i++;
|
|
|
|
else if (da[i] == db[j])
|
|
|
|
{
|
2012-02-17 09:00:11 +08:00
|
|
|
if (k == 0 || dr[k - 1] != db[j])
|
|
|
|
dr[k++] = db[j];
|
2003-06-12 03:31:05 +08:00
|
|
|
i++;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
j++;
|
2011-01-09 13:39:21 +08:00
|
|
|
}
|
2003-06-12 03:31:05 +08:00
|
|
|
|
2012-02-17 09:00:11 +08:00
|
|
|
if (k == 0)
|
2003-06-12 03:31:05 +08:00
|
|
|
{
|
|
|
|
pfree(r);
|
|
|
|
return new_intArrayType(0);
|
|
|
|
}
|
|
|
|
else
|
2012-02-17 09:00:11 +08:00
|
|
|
return resize_intArrayType(r, k);
|
2003-06-12 03:31:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rt__int_size(ArrayType *a, float *size)
|
|
|
|
{
|
|
|
|
*size = (float) ARRNELEMS(a);
|
|
|
|
}
|
|
|
|
|
2015-03-16 11:22:03 +08:00
|
|
|
/* qsort_arg comparison function for isort() */
|
|
|
|
static int
|
|
|
|
isort_cmp(const void *a, const void *b, void *arg)
|
|
|
|
{
|
|
|
|
int32 aval = *((const int32 *) a);
|
|
|
|
int32 bval = *((const int32 *) b);
|
|
|
|
|
|
|
|
if (aval < bval)
|
|
|
|
return -1;
|
|
|
|
if (aval > bval)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report if we have any duplicates. If there are equal keys, qsort must
|
|
|
|
* compare them at some point, else it wouldn't know whether one should go
|
|
|
|
* before or after the other.
|
|
|
|
*/
|
|
|
|
*((bool *) arg) = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-09 13:39:21 +08:00
|
|
|
/* Sort the given data (len >= 2). Return true if any duplicates found */
|
2003-06-12 03:31:05 +08:00
|
|
|
bool
|
2012-06-25 06:51:46 +08:00
|
|
|
isort(int32 *a, int len)
|
2003-06-12 03:31:05 +08:00
|
|
|
{
|
2015-03-16 11:22:03 +08:00
|
|
|
bool r = false;
|
2003-06-12 03:31:05 +08:00
|
|
|
|
2015-03-16 11:22:03 +08:00
|
|
|
qsort_arg(a, len, sizeof(int32), isort_cmp, (void *) &r);
|
2003-06-12 03:31:05 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-01-09 13:39:21 +08:00
|
|
|
/* Create a new int array with room for "num" elements */
|
2003-06-12 03:31:05 +08:00
|
|
|
ArrayType *
|
|
|
|
new_intArrayType(int num)
|
|
|
|
{
|
|
|
|
ArrayType *r;
|
2018-07-10 02:28:04 +08:00
|
|
|
int nbytes;
|
|
|
|
|
|
|
|
/* if no elements, return a zero-dimensional array */
|
|
|
|
if (num <= 0)
|
|
|
|
{
|
2018-11-24 07:56:39 +08:00
|
|
|
Assert(num == 0);
|
2018-07-10 02:28:04 +08:00
|
|
|
r = construct_empty_array(INT4OID);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
nbytes = ARR_OVERHEAD_NONULLS(1) + sizeof(int) * num;
|
2003-06-12 03:31:05 +08:00
|
|
|
|
|
|
|
r = (ArrayType *) palloc0(nbytes);
|
|
|
|
|
2007-02-28 07:48:10 +08:00
|
|
|
SET_VARSIZE(r, nbytes);
|
2011-01-09 13:39:21 +08:00
|
|
|
ARR_NDIM(r) = 1;
|
2005-11-18 06:14:56 +08:00
|
|
|
r->dataoffset = 0; /* marker for no null bitmap */
|
2003-06-12 03:31:05 +08:00
|
|
|
ARR_ELEMTYPE(r) = INT4OID;
|
2011-01-09 13:39:21 +08:00
|
|
|
ARR_DIMS(r)[0] = num;
|
|
|
|
ARR_LBOUND(r)[0] = 1;
|
2003-06-12 03:31:05 +08:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayType *
|
|
|
|
resize_intArrayType(ArrayType *a, int num)
|
|
|
|
{
|
2018-07-10 02:28:04 +08:00
|
|
|
int nbytes;
|
2011-01-09 13:39:21 +08:00
|
|
|
int i;
|
2003-06-12 03:31:05 +08:00
|
|
|
|
2013-09-07 23:44:33 +08:00
|
|
|
/* if no elements, return a zero-dimensional array */
|
2018-07-10 02:28:04 +08:00
|
|
|
if (num <= 0)
|
2013-09-07 23:44:33 +08:00
|
|
|
{
|
2018-11-24 07:56:39 +08:00
|
|
|
Assert(num == 0);
|
Fix intarray's GiST opclasses to not fail for empty arrays with <@.
contrib/intarray considers "arraycol <@ constant-array" to be indexable,
but its GiST opclass code fails to reliably find index entries for empty
array values (which of course should trivially match such queries).
This is because the test condition to see whether we should descend
through a non-leaf node is wrong.
Unfortunately, empty array entries could be anywhere in the index,
as these index opclasses are currently designed. So there's no way
to fix this except by lobotomizing <@ indexscans to scan the whole
index ... which is what this patch does. That's pretty unfortunate:
the performance is now actually worse than a seqscan, in most cases.
We'd be better off to remove <@ from the GiST opclasses entirely,
and perhaps a future non-back-patchable patch will do so.
In the meantime, applications whose performance is adversely impacted
have a couple of options. They could switch to a GIN index, which
doesn't have this bug, or they could replace "arraycol <@ constant-array"
with "arraycol <@ constant-array AND arraycol && constant-array".
That will provide about the same performance as before, and it will find
all non-empty subsets of the given constant-array, which is all that
could reliably be expected of the query before.
While at it, add some more regression test cases to improve code
coverage of contrib/intarray.
In passing, adjust resize_intArrayType so that when it's returning an
empty array, it uses construct_empty_array for that rather than
cowboy hacking on the input array. While the hack produces an array
that looks valid for most purposes, it isn't bitwise equal to empty
arrays produced by other code paths, which could have subtle odd
effects. I don't think this code path is performance-critical
enough to justify such shortcuts. (Back-patch this part only as far
as v11; before commit 01783ac36 we were not careful about this in
other intarray code paths either.)
Back-patch the <@ fixes to all supported versions, since this was
broken from day one.
Patch by me; thanks to Alexander Korotkov for review.
Discussion: https://postgr.es/m/458.1565114141@sss.pgh.pa.us
2019-08-07 06:04:51 +08:00
|
|
|
a = construct_empty_array(INT4OID);
|
2013-09-07 23:44:33 +08:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2003-06-12 03:31:05 +08:00
|
|
|
if (num == ARRNELEMS(a))
|
|
|
|
return a;
|
|
|
|
|
2018-07-10 02:28:04 +08:00
|
|
|
nbytes = ARR_DATA_OFFSET(a) + sizeof(int) * num;
|
|
|
|
|
2003-06-12 03:31:05 +08:00
|
|
|
a = (ArrayType *) repalloc(a, nbytes);
|
|
|
|
|
2007-02-28 07:48:10 +08:00
|
|
|
SET_VARSIZE(a, nbytes);
|
2011-01-09 13:39:21 +08:00
|
|
|
/* usually the array should be 1-D already, but just in case ... */
|
|
|
|
for (i = 0; i < ARR_NDIM(a); i++)
|
|
|
|
{
|
|
|
|
ARR_DIMS(a)[i] = num;
|
|
|
|
num = 1;
|
|
|
|
}
|
2003-06-12 03:31:05 +08:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayType *
|
|
|
|
copy_intArrayType(ArrayType *a)
|
|
|
|
{
|
|
|
|
ArrayType *r;
|
2011-01-09 13:39:21 +08:00
|
|
|
int n = ARRNELEMS(a);
|
2003-06-12 03:31:05 +08:00
|
|
|
|
2011-01-09 13:39:21 +08:00
|
|
|
r = new_intArrayType(n);
|
2012-06-25 06:51:46 +08:00
|
|
|
memcpy(ARRPTR(r), ARRPTR(a), n * sizeof(int32));
|
2003-06-12 03:31:05 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* num for compressed key */
|
|
|
|
int
|
|
|
|
internal_size(int *a, int len)
|
|
|
|
{
|
2018-11-24 07:56:39 +08:00
|
|
|
int i;
|
|
|
|
int64 size = 0;
|
2003-06-12 03:31:05 +08:00
|
|
|
|
|
|
|
for (i = 0; i < len; i += 2)
|
2011-01-09 13:39:21 +08:00
|
|
|
{
|
2003-06-12 03:31:05 +08:00
|
|
|
if (!i || a[i] != a[i - 1]) /* do not count repeated range */
|
2018-11-24 07:56:39 +08:00
|
|
|
size += (int64) (a[i + 1]) - (int64) (a[i]) + 1;
|
2011-01-09 13:39:21 +08:00
|
|
|
}
|
2003-06-12 03:31:05 +08:00
|
|
|
|
2018-11-24 07:56:39 +08:00
|
|
|
if (size > (int64) INT_MAX || size < (int64) INT_MIN)
|
|
|
|
return -1; /* overflow */
|
|
|
|
return (int) size;
|
2003-06-12 03:31:05 +08:00
|
|
|
}
|
|
|
|
|
2011-01-09 13:39:21 +08:00
|
|
|
/* unique-ify elements of r in-place ... r must be sorted already */
|
2003-06-12 03:31:05 +08:00
|
|
|
ArrayType *
|
|
|
|
_int_unique(ArrayType *r)
|
|
|
|
{
|
|
|
|
int num = ARRNELEMS(r);
|
2019-11-07 11:51:04 +08:00
|
|
|
bool duplicates_found; /* not used */
|
2003-06-12 03:31:05 +08:00
|
|
|
|
2019-11-07 11:51:04 +08:00
|
|
|
num = qunique_arg(ARRPTR(r), num, sizeof(int), isort_cmp,
|
|
|
|
&duplicates_found);
|
2003-06-12 03:31:05 +08:00
|
|
|
|
2019-11-07 11:51:04 +08:00
|
|
|
return resize_intArrayType(r, num);
|
2003-06-12 03:31:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
Implement operator class parameters
PostgreSQL provides set of template index access methods, where opclasses have
much freedom in the semantics of indexing. These index AMs are GiST, GIN,
SP-GiST and BRIN. There opclasses define representation of keys, operations on
them and supported search strategies. So, it's natural that opclasses may be
faced some tradeoffs, which require user-side decision. This commit implements
opclass parameters allowing users to set some values, which tell opclass how to
index the particular dataset.
This commit doesn't introduce new storage in system catalog. Instead it uses
pg_attribute.attoptions, which is used for table column storage options but
unused for index attributes.
In order to evade changing signature of each opclass support function, we
implement unified way to pass options to opclass support functions. Options
are set to fn_expr as the constant bytea expression. It's possible due to the
fact that opclass support functions are executed outside of expressions, so
fn_expr is unused for them.
This commit comes with some examples of opclass options usage. We parametrize
signature length in GiST. That applies to multiple opclasses: tsvector_ops,
gist__intbig_ops, gist_ltree_ops, gist__ltree_ops, gist_trgm_ops and
gist_hstore_ops. Also we parametrize maximum number of integer ranges for
gist__int_ops. However, the main future usage of this feature is expected
to be json, where users would be able to specify which way to index particular
json parts.
Catversion is bumped.
Discussion: https://postgr.es/m/d22c3a18-31c7-1879-fc11-4c1ce2f5e5af%40postgrespro.ru
Author: Nikita Glukhov, revised by me
Reviwed-by: Nikolay Shaplov, Robert Haas, Tom Lane, Tomas Vondra, Alvaro Herrera
2020-03-31 00:17:11 +08:00
|
|
|
gensign(BITVECP sign, int *a, int len, int siglen)
|
2003-06-12 03:31:05 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* we assume that the sign vector is previously zeroed */
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
Implement operator class parameters
PostgreSQL provides set of template index access methods, where opclasses have
much freedom in the semantics of indexing. These index AMs are GiST, GIN,
SP-GiST and BRIN. There opclasses define representation of keys, operations on
them and supported search strategies. So, it's natural that opclasses may be
faced some tradeoffs, which require user-side decision. This commit implements
opclass parameters allowing users to set some values, which tell opclass how to
index the particular dataset.
This commit doesn't introduce new storage in system catalog. Instead it uses
pg_attribute.attoptions, which is used for table column storage options but
unused for index attributes.
In order to evade changing signature of each opclass support function, we
implement unified way to pass options to opclass support functions. Options
are set to fn_expr as the constant bytea expression. It's possible due to the
fact that opclass support functions are executed outside of expressions, so
fn_expr is unused for them.
This commit comes with some examples of opclass options usage. We parametrize
signature length in GiST. That applies to multiple opclasses: tsvector_ops,
gist__intbig_ops, gist_ltree_ops, gist__ltree_ops, gist_trgm_ops and
gist_hstore_ops. Also we parametrize maximum number of integer ranges for
gist__int_ops. However, the main future usage of this feature is expected
to be json, where users would be able to specify which way to index particular
json parts.
Catversion is bumped.
Discussion: https://postgr.es/m/d22c3a18-31c7-1879-fc11-4c1ce2f5e5af%40postgrespro.ru
Author: Nikita Glukhov, revised by me
Reviwed-by: Nikolay Shaplov, Robert Haas, Tom Lane, Tomas Vondra, Alvaro Herrera
2020-03-31 00:17:11 +08:00
|
|
|
HASH(sign, *a, siglen);
|
2003-06-12 03:31:05 +08:00
|
|
|
a++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
|
|
|
intarray_match_first(ArrayType *a, int32 elem)
|
|
|
|
{
|
|
|
|
int32 *aa,
|
|
|
|
c,
|
|
|
|
i;
|
|
|
|
|
2005-11-19 11:00:09 +08:00
|
|
|
CHECKARRVALID(a);
|
|
|
|
c = ARRNELEMS(a);
|
2003-06-12 03:31:05 +08:00
|
|
|
aa = ARRPTR(a);
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
if (aa[i] == elem)
|
|
|
|
return (i + 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayType *
|
|
|
|
intarray_add_elem(ArrayType *a, int32 elem)
|
|
|
|
{
|
|
|
|
ArrayType *result;
|
|
|
|
int32 *r;
|
2005-11-19 11:00:09 +08:00
|
|
|
int32 c;
|
2003-06-12 03:31:05 +08:00
|
|
|
|
2005-11-19 11:00:09 +08:00
|
|
|
CHECKARRVALID(a);
|
2011-01-09 13:39:21 +08:00
|
|
|
c = ARRNELEMS(a);
|
2003-06-12 03:31:05 +08:00
|
|
|
result = new_intArrayType(c + 1);
|
|
|
|
r = ARRPTR(result);
|
|
|
|
if (c > 0)
|
|
|
|
memcpy(r, ARRPTR(a), c * sizeof(int32));
|
|
|
|
r[c] = elem;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayType *
|
|
|
|
intarray_concat_arrays(ArrayType *a, ArrayType *b)
|
|
|
|
{
|
|
|
|
ArrayType *result;
|
2011-01-09 13:39:21 +08:00
|
|
|
int32 ac = ARRNELEMS(a);
|
|
|
|
int32 bc = ARRNELEMS(b);
|
2003-06-12 03:31:05 +08:00
|
|
|
|
2005-11-19 11:00:09 +08:00
|
|
|
CHECKARRVALID(a);
|
|
|
|
CHECKARRVALID(b);
|
2003-06-12 03:31:05 +08:00
|
|
|
result = new_intArrayType(ac + bc);
|
|
|
|
if (ac)
|
|
|
|
memcpy(ARRPTR(result), ARRPTR(a), ac * sizeof(int32));
|
|
|
|
if (bc)
|
|
|
|
memcpy(ARRPTR(result) + ac, ARRPTR(b), bc * sizeof(int32));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayType *
|
|
|
|
int_to_intset(int32 n)
|
|
|
|
{
|
|
|
|
ArrayType *result;
|
|
|
|
int32 *aa;
|
|
|
|
|
|
|
|
result = new_intArrayType(1);
|
|
|
|
aa = ARRPTR(result);
|
|
|
|
aa[0] = n;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
compASC(const void *a, const void *b)
|
|
|
|
{
|
2012-06-25 06:51:46 +08:00
|
|
|
if (*(const int32 *) a == *(const int32 *) b)
|
2003-06-12 03:31:05 +08:00
|
|
|
return 0;
|
2012-06-25 06:51:46 +08:00
|
|
|
return (*(const int32 *) a > *(const int32 *) b) ? 1 : -1;
|
2003-06-12 03:31:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
compDESC(const void *a, const void *b)
|
|
|
|
{
|
2012-06-25 06:51:46 +08:00
|
|
|
if (*(const int32 *) a == *(const int32 *) b)
|
2003-06-12 03:31:05 +08:00
|
|
|
return 0;
|
2012-06-25 06:51:46 +08:00
|
|
|
return (*(const int32 *) a < *(const int32 *) b) ? 1 : -1;
|
2003-06-12 03:31:05 +08:00
|
|
|
}
|