Skip to content

Commit a237dd2

Browse files
committed
Add missing intarray files.
1 parent a24c5a7 commit a237dd2

File tree

6 files changed

+2750
-0
lines changed

6 files changed

+2750
-0
lines changed

contrib/intarray/_int.h

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
#include "postgres.h"
2+
3+
#include <float.h>
4+
5+
#include "access/gist.h"
6+
#include "access/itup.h"
7+
#include "access/rtree.h"
8+
#include "catalog/pg_type.h"
9+
#include "utils/elog.h"
10+
#include "utils/palloc.h"
11+
#include "utils/array.h"
12+
#include "utils/builtins.h"
13+
#include "storage/bufpage.h"
14+
#include "lib/stringinfo.h"
15+
16+
/* number ranges for compression */
17+
#define MAXNUMRANGE 100
18+
19+
#define max(a,b) ((a) > (b) ? (a) : (b))
20+
#define min(a,b) ((a) <= (b) ? (a) : (b))
21+
#define abs(a) ((a) < (0) ? -(a) : (a))
22+
23+
/* dimension of array */
24+
#define NDIM 1
25+
26+
/*
27+
* flags for gist__int_ops, use ArrayType->flags
28+
* which is unused (see array.h)
29+
*/
30+
#define LEAFKEY (1<<31)
31+
#define ISLEAFKEY(x) ( ((ArrayType*)(x))->flags & LEAFKEY )
32+
33+
/* useful macros for accessing int4 arrays */
34+
#define ARRPTR(x) ( (int4 *) ARR_DATA_PTR(x) )
35+
#define ARRNELEMS(x) ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x))
36+
37+
#define ARRISVOID(x) ( (x) ? ( ( ARR_NDIM(x) == NDIM ) ? ( ( ARRNELEMS( x ) ) ? 0 : 1 ) : ( ( ARR_NDIM(x) ) ? (elog(ERROR,"Array is not one-dimensional: %d dimensions",ARRNELEMS( x )),1) : 0 ) ) : 0 )
38+
39+
#define SORT(x) \
40+
do { \
41+
if ( ARRNELEMS( x ) > 1 ) \
42+
isort( ARRPTR( x ), ARRNELEMS( x ) ); \
43+
} while(0)
44+
45+
#define PREPAREARR(x) \
46+
do { \
47+
if ( ARRNELEMS( x ) > 1 ) \
48+
if ( isort( ARRPTR( x ), ARRNELEMS( x ) ) ) \
49+
x = _int_unique( x ); \
50+
} while(0)
51+
52+
/* "wish" function */
53+
#define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
54+
55+
56+
/* bigint defines */
57+
#define BITBYTE 8
58+
#define SIGLENINT 63 /* >122 => key will toast, so very slow!!! */
59+
#define SIGLEN ( sizeof(int)*SIGLENINT )
60+
#define SIGLENBIT (SIGLEN*BITBYTE)
61+
62+
typedef char BITVEC[SIGLEN];
63+
typedef char *BITVECP;
64+
65+
#define SIGPTR(x) ( (BITVECP) ARR_DATA_PTR(x) )
66+
67+
68+
#define LOOPBYTE(a) \
69+
for(i=0;i<SIGLEN;i++) {\
70+
a;\
71+
}
72+
73+
#define LOOPBIT(a) \
74+
for(i=0;i<SIGLENBIT;i++) {\
75+
a;\
76+
}
77+
78+
/* beware of multiple evaluation of arguments to these macros! */
79+
#define GETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) / BITBYTE ) ) )
80+
#define GETBITBYTE(x,i) ( (*((char*)(x)) >> (i)) & 0x01 )
81+
#define CLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITBYTE ) )
82+
#define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) )
83+
#define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 )
84+
#define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
85+
#define HASH(sign, val) SETBIT((sign), HASHVAL(val))
86+
87+
/*
88+
* type of index key
89+
*/
90+
typedef struct
91+
{
92+
int4 len;
93+
int4 flag;
94+
char data[1];
95+
} GISTTYPE;
96+
97+
#define ALLISTRUE 0x04
98+
99+
#define ISALLTRUE(x) ( ((GISTTYPE*)x)->flag & ALLISTRUE )
100+
101+
#define GTHDRSIZE ( sizeof(int4)*2 )
102+
#define CALCGTSIZE(flag) ( GTHDRSIZE+(((flag) & ALLISTRUE) ? 0 : SIGLEN) )
103+
104+
#define GETSIGN(x) ( (BITVECP)( (char*)x+GTHDRSIZE ) )
105+
106+
/*
107+
** types for functions
108+
*/
109+
typedef ArrayType *(*formarray) (ArrayType *, ArrayType *);
110+
typedef void (*formfloat) (ArrayType *, float *);
111+
112+
/*
113+
** useful function
114+
*/
115+
bool isort(int4 *a, const int len);
116+
ArrayType *new_intArrayType(int num);
117+
ArrayType *copy_intArrayType(ArrayType *a);
118+
ArrayType *resize_intArrayType(ArrayType *a, int num);
119+
int internal_size(int *a, int len);
120+
ArrayType *_int_unique(ArrayType *a);
121+
int32 intarray_match_first(ArrayType *a, int32 elem);
122+
ArrayType *intarray_add_elem(ArrayType *a, int32 elem);
123+
ArrayType *intarray_concat_arrays(ArrayType *a, ArrayType *b);
124+
ArrayType *int_to_intset(int32 elem);
125+
bool inner_int_overlap(ArrayType *a, ArrayType *b);
126+
bool inner_int_contains(ArrayType *a, ArrayType *b);
127+
ArrayType * inner_int_union(ArrayType *a, ArrayType *b);
128+
ArrayType * inner_int_inter(ArrayType *a, ArrayType *b);
129+
void rt__int_size(ArrayType *a, float *size);
130+
void gensign(BITVEC sign, int *a, int len);
131+
132+
133+
/*****************************************************************************
134+
* Boolean Search
135+
*****************************************************************************/
136+
137+
#define BooleanSearchStrategy 20
138+
139+
/*
140+
* item in polish notation with back link
141+
* to left operand
142+
*/
143+
typedef struct ITEM
144+
{
145+
int2 type;
146+
int2 left;
147+
int4 val;
148+
} ITEM;
149+
150+
typedef struct
151+
{
152+
int4 len;
153+
int4 size;
154+
char data[1];
155+
} QUERYTYPE;
156+
157+
#define HDRSIZEQT ( 2*sizeof(int4) )
158+
#define COMPUTESIZE(size) ( HDRSIZEQT + size * sizeof(ITEM) )
159+
#define GETQUERY(x) (ITEM*)( (char*)(x)+HDRSIZEQT )
160+
161+
bool signconsistent(QUERYTYPE * query, BITVEC sign, bool calcnot);
162+
bool execconsistent(QUERYTYPE * query, ArrayType *array, bool calcnot);
163+
164+
165+
166+
int compASC(const void *a, const void *b);
167+
168+
int compDESC(const void *a, const void *b);
169+
170+
#define QSORT(a, direction) \
171+
if (ARRNELEMS(a) > 1) \
172+
qsort((void*)ARRPTR(a), ARRNELEMS(a),sizeof(int4), \
173+
(direction) ? compASC : compDESC )
174+
175+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy