26 #define SIGLEN ( sizeof(int32) * SIGLENINT )
27 #define SIGLENBIT (SIGLEN * BITS_PER_BYTE)
35 #define GETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) / BITS_PER_BYTE ) ) )
36 #define GETBITBYTE(x,i) ( ((char)(x)) >> (i) & 0x01 )
37 #define CLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITS_PER_BYTE ) )
38 #define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITS_PER_BYTE ) )
39 #define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITS_PER_BYTE )) & 0x01 )
41 #define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
42 #define HASH(sign, val) SETBIT((sign), HASHVAL(val))
44 #define GETENTRY(vec,pos) ((SignTSVector *) DatumGetPointer((vec)->vector[(pos)].key))
54 char data[FLEXIBLE_ARRAY_MEMBER];
59 #define ALLISTRUE 0x04
61 #define ISARRKEY(x) ( ((SignTSVector*)(x))->flag & ARRKEY )
62 #define ISSIGNKEY(x) ( ((SignTSVector*)(x))->flag & SIGNKEY )
63 #define ISALLTRUE(x) ( ((SignTSVector*)(x))->flag & ALLISTRUE )
65 #define GTHDRSIZE ( VARHDRSZ + sizeof(int32) )
66 #define CALCGTSIZE(flag, len) ( GTHDRSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(int32)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) )
68 #define GETSIGN(x) ( (BITVECP)( (char*)(x)+GTHDRSIZE ) )
69 #define GETARR(x) ( (int32*)( (char*)(x)+GTHDRSIZE ) )
70 #define ARRNELEM(x) ( ( VARSIZE(x) - GTHDRSIZE )/sizeof(int32) )
74 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
75 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
76 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
77 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
78 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
79 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
80 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
81 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
82 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
83 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
84 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
85 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
86 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
87 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
88 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
89 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
98 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
99 errmsg(
"gtsvector_in not implemented")));
103 #define SINGOUTSTR "%d true bits, %d false bits"
104 #define ARROUTSTR "%d unique words"
105 #define EXTRALEN ( 2*13 )
140 return (a > b) ? 1 : -1;
176 for (k = 0; k < len; k++)
193 char *words =
STRPTR(val);
209 *arr = *(
int32 *) &c;
215 if (len != val->
size)
254 if ((sign[i] & 0xff) != 0xff)
315 while (StopLow < StopHigh)
317 StopMiddle = StopLow + (StopHigh - StopLow) / 2;
318 if (*StopMiddle == val->
valcrc)
320 else if (*StopMiddle < val->valcrc)
321 StopLow = StopMiddle + 1;
323 StopHigh = StopMiddle;
376 (
void *) &chkval,
true,
420 for (i = 0; i < entryvec->
n; i++)
436 memcpy((
void *)
GETSIGN(result), (
void *) base,
sizeof(
BITVEC));
487 for (i = 0; i < lena; i++)
488 if (ptra[i] != ptrb[i])
519 diff = (
unsigned char) (a[i] ^ b[i]);
565 *penalty =
hemdist(origval, newval);
587 #define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
603 return (a->
cost > b->
cost) ? 1 : -1;
649 maxoff = entryvec->
n - 2;
661 if (k == FirstOffsetNumber)
665 if (size_waste > waste)
679 if (seed_1 == 0 || seed_2 == 0)
686 if (cache[seed_1].allistrue)
699 if (cache[seed_2].allistrue)
721 costvector[j - 1].
pos = j;
722 size_alpha =
hemdistcache(&(cache[seed_1]), &(cache[j]));
723 size_beta =
hemdistcache(&(cache[seed_2]), &(cache[j]));
724 costvector[j - 1].
cost =
Abs(size_alpha - size_beta);
728 for (k = 0; k < maxoff; k++)
730 j = costvector[k].
pos;
737 else if (j == seed_2)
744 if (
ISALLTRUE(datum_l) || cache[j].allistrue)
746 if (
ISALLTRUE(datum_l) && cache[j].allistrue)
756 if (
ISALLTRUE(datum_r) || cache[j].allistrue)
758 if (
ISALLTRUE(datum_r) && cache[j].allistrue)
770 if (
ISALLTRUE(datum_l) || cache[j].allistrue)
779 union_l[
i] |= ptr[
i];
786 if (
ISALLTRUE(datum_r) || cache[j].allistrue)
795 union_r[
i] |= ptr[
i];
static int hemdist(SignTSVector *a, SignTSVector *b)
#define PG_RETURN_POINTER(x)
#define INIT_LEGACY_CRC32(crc)
static int compareint(const void *va, const void *vb)
Datum gtsvector_penalty(PG_FUNCTION_ARGS)
static bool checkcondition_bit(void *checkval, QueryOperand *val, ExecPhraseData *data)
Datum gtsvector_same(PG_FUNCTION_ARGS)
#define PointerGetDatum(X)
#define PG_GETARG_TSQUERY(n)
int errcode(int sqlerrcode)
#define MemSet(start, val, len)
#define PG_GETARG_POINTER(n)
static int comparecost(const void *va, const void *vb)
#define FIN_LEGACY_CRC32(crc)
bool TS_execute(QueryItem *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, QueryOperand *val, ExecPhraseData *data))
static int hemdistsign(BITVECP a, BITVECP b)
static void makesign(BITVECP sign, SignTSVector *a)
#define CALCGTSIZE(flag, len)
#define FirstOffsetNumber
#define GETENTRY(vec, pos)
#define DatumGetTSVector(X)
#define ereport(elevel, rest)
static bool checkcondition_arr(void *checkval, QueryOperand *val, ExecPhraseData *data)
Datum gtsvector_union(PG_FUNCTION_ARGS)
static const uint8 number_of_ones[256]
#define PG_RETURN_BOOL(x)
#define PG_RETURN_DATUM(x)
#define TOAST_INDEX_TARGET
static int hemdistcache(CACHESIGN *a, CACHESIGN *b)
Datum gtsvector_consistent_oldsig(PG_FUNCTION_ARGS)
#define gistentryinit(e, k, r, pg, o, l)
#define OffsetNumberNext(offsetNumber)
Datum gtsvector_consistent(PG_FUNCTION_ARGS)
Datum gtsvectorout(PG_FUNCTION_ARGS)
#define PG_FREE_IF_COPY(ptr, n)
void * repalloc(void *pointer, Size size)
#define DatumGetPointer(X)
int errmsg(const char *fmt,...)
Datum gtsvector_picksplit(PG_FUNCTION_ARGS)
#define COMP_LEGACY_CRC32(crc, data, len)
static int32 sizebitvec(BITVECP sign)
#define PG_DETOAST_DATUM(datum)
#define SET_VARSIZE(PTR, len)
#define qsort(a, b, c, d)
static int uniqueint(int32 *a, int32 l)
static int32 unionkey(BITVECP sbase, SignTSVector *add)
Datum gtsvector_compress(PG_FUNCTION_ARGS)
Datum gtsvector_decompress(PG_FUNCTION_ARGS)
static void fillcache(CACHESIGN *item, SignTSVector *key)
Datum gtsvectorin(PG_FUNCTION_ARGS)