PostgreSQL Source Code  git master
tsgistidx.c File Reference
#include "postgres.h"
#include "access/gist.h"
#include "access/heaptoast.h"
#include "port/pg_bitutils.h"
#include "tsearch/ts_utils.h"
#include "utils/builtins.h"
#include "utils/pg_crc.h"
Include dependency graph for tsgistidx.c:

Go to the source code of this file.

Data Structures

struct  SignTSVector
 
struct  CHKVAL
 
struct  CACHESIGN
 
struct  SPLITCOST
 

Macros

#define SIGLENINT
 
#define SIGLEN   ( sizeof(int32) * SIGLENINT )
 
#define SIGLENBIT   (SIGLEN * BITS_PER_BYTE)
 
#define LOOPBYTE   for(i=0;i<SIGLEN;i++)
 
#define GETBYTE(x, i)   ( *( (BITVECP)(x) + (int)( (i) / BITS_PER_BYTE ) ) )
 
#define GETBITBYTE(x, i)   ( ((char)(x)) >> (i) & 0x01 )
 
#define CLRBIT(x, i)   GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITS_PER_BYTE ) )
 
#define SETBIT(x, i)   GETBYTE(x,i) |= ( 0x01 << ( (i) % BITS_PER_BYTE ) )
 
#define GETBIT(x, i)   ( (GETBYTE(x,i) >> ( (i) % BITS_PER_BYTE )) & 0x01 )
 
#define HASHVAL(val)   (((unsigned int)(val)) % SIGLENBIT)
 
#define HASH(sign, val)   SETBIT((sign), HASHVAL(val))
 
#define GETENTRY(vec, pos)   ((SignTSVector *) DatumGetPointer((vec)->vector[(pos)].key))
 
#define ARRKEY   0x01
 
#define SIGNKEY   0x02
 
#define ALLISTRUE   0x04
 
#define ISARRKEY(x)   ( ((SignTSVector*)(x))->flag & ARRKEY )
 
#define ISSIGNKEY(x)   ( ((SignTSVector*)(x))->flag & SIGNKEY )
 
#define ISALLTRUE(x)   ( ((SignTSVector*)(x))->flag & ALLISTRUE )
 
#define GTHDRSIZE   ( VARHDRSZ + sizeof(int32) )
 
#define CALCGTSIZE(flag, len)   ( GTHDRSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(int32)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) )
 
#define GETSIGN(x)   ( (BITVECP)( (char*)(x)+GTHDRSIZE ) )
 
#define GETARR(x)   ( (int32*)( (char*)(x)+GTHDRSIZE ) )
 
#define ARRNELEM(x)   ( ( VARSIZE(x) - GTHDRSIZE )/sizeof(int32) )
 
#define SINGOUTSTR   "%d true bits, %d false bits"
 
#define ARROUTSTR   "%d unique words"
 
#define EXTRALEN   ( 2*13 )
 
#define WISH_F(a, b, c)   (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
 

Typedefs

typedef char BITVEC[SIGLEN]
 
typedef char * BITVECP
 

Functions

static int32 sizebitvec (BITVECP sign)
 
Datum gtsvectorin (PG_FUNCTION_ARGS)
 
Datum gtsvectorout (PG_FUNCTION_ARGS)
 
static int compareint (const void *va, const void *vb)
 
static int uniqueint (int32 *a, int32 l)
 
static void makesign (BITVECP sign, SignTSVector *a)
 
Datum gtsvector_compress (PG_FUNCTION_ARGS)
 
Datum gtsvector_decompress (PG_FUNCTION_ARGS)
 
static bool checkcondition_arr (void *checkval, QueryOperand *val, ExecPhraseData *data)
 
static bool checkcondition_bit (void *checkval, QueryOperand *val, ExecPhraseData *data)
 
Datum gtsvector_consistent (PG_FUNCTION_ARGS)
 
static int32 unionkey (BITVECP sbase, SignTSVector *add)
 
Datum gtsvector_union (PG_FUNCTION_ARGS)
 
Datum gtsvector_same (PG_FUNCTION_ARGS)
 
static int hemdistsign (BITVECP a, BITVECP b)
 
static int hemdist (SignTSVector *a, SignTSVector *b)
 
Datum gtsvector_penalty (PG_FUNCTION_ARGS)
 
static void fillcache (CACHESIGN *item, SignTSVector *key)
 
static int comparecost (const void *va, const void *vb)
 
static int hemdistcache (CACHESIGN *a, CACHESIGN *b)
 
Datum gtsvector_picksplit (PG_FUNCTION_ARGS)
 
Datum gtsvector_consistent_oldsig (PG_FUNCTION_ARGS)
 

Variables

static int outbuf_maxlen = 0
 

Macro Definition Documentation

◆ ALLISTRUE

#define ALLISTRUE   0x04

Definition at line 61 of file tsgistidx.c.

Referenced by gtsvector_compress(), gtsvector_picksplit(), and gtsvector_union().

◆ ARRKEY

#define ARRKEY   0x01

Definition at line 59 of file tsgistidx.c.

Referenced by gtsvector_compress().

◆ ARRNELEM

#define ARRNELEM (   x)    ( ( VARSIZE(x) - GTHDRSIZE )/sizeof(int32) )

Definition at line 72 of file tsgistidx.c.

Referenced by gtsvector_consistent(), gtsvector_same(), gtsvectorout(), makesign(), and unionkey().

◆ ARROUTSTR

#define ARROUTSTR   "%d unique words"

Definition at line 86 of file tsgistidx.c.

Referenced by gtsvectorout().

◆ CALCGTSIZE

#define CALCGTSIZE (   flag,
  len 
)    ( GTHDRSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(int32)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) )

Definition at line 68 of file tsgistidx.c.

Referenced by gtsvector_compress(), gtsvector_picksplit(), and gtsvector_union().

◆ CLRBIT

#define CLRBIT (   x,
  i 
)    GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITS_PER_BYTE ) )

Definition at line 39 of file tsgistidx.c.

◆ EXTRALEN

#define EXTRALEN   ( 2*13 )

Definition at line 87 of file tsgistidx.c.

Referenced by gtsvectorout().

◆ GETARR

#define GETARR (   x)    ( (int32*)( (char*)(x)+GTHDRSIZE ) )

◆ GETBIT

#define GETBIT (   x,
  i 
)    ( (GETBYTE(x,i) >> ( (i) % BITS_PER_BYTE )) & 0x01 )

Definition at line 41 of file tsgistidx.c.

Referenced by checkcondition_bit().

◆ GETBITBYTE

#define GETBITBYTE (   x,
  i 
)    ( ((char)(x)) >> (i) & 0x01 )

Definition at line 38 of file tsgistidx.c.

◆ GETBYTE

#define GETBYTE (   x,
  i 
)    ( *( (BITVECP)(x) + (int)( (i) / BITS_PER_BYTE ) ) )

Definition at line 37 of file tsgistidx.c.

◆ GETENTRY

#define GETENTRY (   vec,
  pos 
)    ((SignTSVector *) DatumGetPointer((vec)->vector[(pos)].key))

Definition at line 46 of file tsgistidx.c.

Referenced by gtsvector_picksplit(), and gtsvector_union().

◆ GETSIGN

◆ GTHDRSIZE

#define GTHDRSIZE   ( VARHDRSZ + sizeof(int32) )

Definition at line 67 of file tsgistidx.c.

◆ HASH

#define HASH (   sign,
  val 
)    SETBIT((sign), HASHVAL(val))

Definition at line 44 of file tsgistidx.c.

Referenced by makesign(), and unionkey().

◆ HASHVAL

#define HASHVAL (   val)    (((unsigned int)(val)) % SIGLENBIT)

Definition at line 43 of file tsgistidx.c.

Referenced by checkcondition_bit().

◆ ISALLTRUE

◆ ISARRKEY

#define ISARRKEY (   x)    ( ((SignTSVector*)(x))->flag & ARRKEY )

Definition at line 63 of file tsgistidx.c.

Referenced by fillcache(), gtsvector_penalty(), and gtsvectorout().

◆ ISSIGNKEY

#define ISSIGNKEY (   x)    ( ((SignTSVector*)(x))->flag & SIGNKEY )

Definition at line 64 of file tsgistidx.c.

Referenced by gtsvector_compress(), gtsvector_consistent(), gtsvector_same(), and unionkey().

◆ LOOPBYTE

#define LOOPBYTE   for(i=0;i<SIGLEN;i++)

◆ SETBIT

#define SETBIT (   x,
  i 
)    GETBYTE(x,i) |= ( 0x01 << ( (i) % BITS_PER_BYTE ) )

Definition at line 40 of file tsgistidx.c.

◆ SIGLEN

#define SIGLEN   ( sizeof(int32) * SIGLENINT )

Definition at line 28 of file tsgistidx.c.

Referenced by sizebitvec().

◆ SIGLENBIT

#define SIGLENBIT   (SIGLEN * BITS_PER_BYTE)

◆ SIGLENINT

#define SIGLENINT
Value:
31 /* >121 => key will toast, so it will not work
* !!! */

Definition at line 25 of file tsgistidx.c.

◆ SIGNKEY

#define SIGNKEY   0x02

Definition at line 60 of file tsgistidx.c.

Referenced by gtsvector_compress(), gtsvector_picksplit(), and gtsvector_union().

◆ SINGOUTSTR

#define SINGOUTSTR   "%d true bits, %d false bits"

Definition at line 85 of file tsgistidx.c.

Referenced by gtsvectorout().

◆ WISH_F

#define WISH_F (   a,
  b,
  c 
)    (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )

Definition at line 568 of file tsgistidx.c.

Referenced by gtsvector_picksplit().

Typedef Documentation

◆ BITVEC

typedef char BITVEC[SIGLEN]

Definition at line 31 of file tsgistidx.c.

◆ BITVECP

typedef char* BITVECP

Definition at line 32 of file tsgistidx.c.

Function Documentation

◆ checkcondition_arr()

static bool checkcondition_arr ( void *  checkval,
QueryOperand val,
ExecPhraseData data 
)
static

Definition at line 287 of file tsgistidx.c.

References QueryOperand::prefix, and QueryOperand::valcrc.

Referenced by gtsvector_consistent().

288 {
289  int32 *StopLow = ((CHKVAL *) checkval)->arrb;
290  int32 *StopHigh = ((CHKVAL *) checkval)->arre;
291  int32 *StopMiddle;
292 
293  /* Loop invariant: StopLow <= val < StopHigh */
294 
295  /*
296  * we are not able to find a prefix by hash value
297  */
298  if (val->prefix)
299  return true;
300 
301  while (StopLow < StopHigh)
302  {
303  StopMiddle = StopLow + (StopHigh - StopLow) / 2;
304  if (*StopMiddle == val->valcrc)
305  return true;
306  else if (*StopMiddle < val->valcrc)
307  StopLow = StopMiddle + 1;
308  else
309  StopHigh = StopMiddle;
310  }
311 
312  return false;
313 }
signed int int32
Definition: c.h:346
int32 valcrc
Definition: ts_type.h:151
bool prefix
Definition: ts_type.h:150

◆ checkcondition_bit()

static bool checkcondition_bit ( void *  checkval,
QueryOperand val,
ExecPhraseData data 
)
static

Definition at line 316 of file tsgistidx.c.

References GETBIT, HASHVAL, QueryOperand::prefix, and QueryOperand::valcrc.

Referenced by gtsvector_consistent().

317 {
318  /*
319  * we are not able to find a prefix in signature tree
320  */
321  if (val->prefix)
322  return true;
323  return GETBIT(checkval, HASHVAL(val->valcrc));
324 }
int32 valcrc
Definition: ts_type.h:151
#define GETBIT(x, i)
Definition: tsgistidx.c:41
#define HASHVAL(val)
Definition: tsgistidx.c:43
bool prefix
Definition: ts_type.h:150

◆ comparecost()

static int comparecost ( const void *  va,
const void *  vb 
)
static

Definition at line 576 of file tsgistidx.c.

References SPLITCOST::cost.

Referenced by gtsvector_picksplit().

577 {
578  const SPLITCOST *a = (const SPLITCOST *) va;
579  const SPLITCOST *b = (const SPLITCOST *) vb;
580 
581  if (a->cost == b->cost)
582  return 0;
583  else
584  return (a->cost > b->cost) ? 1 : -1;
585 }
int32 cost
Definition: hstore_gist.c:321

◆ compareint()

static int compareint ( const void *  va,
const void *  vb 
)
static

Definition at line 115 of file tsgistidx.c.

Referenced by uniqueint().

116 {
117  int32 a = *((const int32 *) va);
118  int32 b = *((const int32 *) vb);
119 
120  if (a == b)
121  return 0;
122  return (a > b) ? 1 : -1;
123 }
signed int int32
Definition: c.h:346

◆ fillcache()

static void fillcache ( CACHESIGN item,
SignTSVector key 
)
static

Definition at line 557 of file tsgistidx.c.

References CACHESIGN::allistrue, GETSIGN, ISALLTRUE, ISARRKEY, makesign(), and CACHESIGN::sign.

Referenced by gtsvector_picksplit().

558 {
559  item->allistrue = false;
560  if (ISARRKEY(key))
561  makesign(item->sign, key);
562  else if (ISALLTRUE(key))
563  item->allistrue = true;
564  else
565  memcpy((void *) item->sign, (void *) GETSIGN(key), sizeof(BITVEC));
566 }
#define ISARRKEY(x)
Definition: tsgistidx.c:63
static void makesign(BITVECP sign, SignTSVector *a)
Definition: tsgistidx.c:151
BITVEC sign
Definition: trgm_gist.c:711
char BITVEC[SIGLEN]
Definition: tsgistidx.c:31
#define GETSIGN(x)
Definition: tsgistidx.c:70
#define ISALLTRUE(x)
Definition: tsgistidx.c:65
bool allistrue
Definition: trgm_gist.c:710

◆ gtsvector_compress()

Datum gtsvector_compress ( PG_FUNCTION_ARGS  )

Definition at line 163 of file tsgistidx.c.

References ALLISTRUE, ARRKEY, ARRPTR, CALCGTSIZE, COMP_LEGACY_CRC32, DatumGetPointer, DatumGetTSVector, FIN_LEGACY_CRC32, SignTSVector::flag, GETARR, GETSIGN, gistentryinit, i, INIT_LEGACY_CRC32, ISALLTRUE, ISSIGNKEY, GISTENTRY::key, GISTENTRY::leafkey, WordEntry::len, LOOPBYTE, makesign(), GISTENTRY::offset, GISTENTRY::page, palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, WordEntry::pos, GISTENTRY::rel, repalloc(), SET_VARSIZE, sign, SIGNKEY, TSVectorData::size, STRPTR, TOAST_INDEX_TARGET, uniqueint(), val, and VARSIZE.

164 {
165  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
166  GISTENTRY *retval = entry;
167 
168  if (entry->leafkey)
169  { /* tsvector */
170  SignTSVector *res;
171  TSVector val = DatumGetTSVector(entry->key);
172  int32 len;
173  int32 *arr;
174  WordEntry *ptr = ARRPTR(val);
175  char *words = STRPTR(val);
176 
177  len = CALCGTSIZE(ARRKEY, val->size);
178  res = (SignTSVector *) palloc(len);
179  SET_VARSIZE(res, len);
180  res->flag = ARRKEY;
181  arr = GETARR(res);
182  len = val->size;
183  while (len--)
184  {
185  pg_crc32 c;
186 
188  COMP_LEGACY_CRC32(c, words + ptr->pos, ptr->len);
189  FIN_LEGACY_CRC32(c);
190 
191  *arr = *(int32 *) &c;
192  arr++;
193  ptr++;
194  }
195 
196  len = uniqueint(GETARR(res), val->size);
197  if (len != val->size)
198  {
199  /*
200  * there is a collision of hash-function; len is always less than
201  * val->size
202  */
203  len = CALCGTSIZE(ARRKEY, len);
204  res = (SignTSVector *) repalloc((void *) res, len);
205  SET_VARSIZE(res, len);
206  }
207 
208  /* make signature, if array is too long */
209  if (VARSIZE(res) > TOAST_INDEX_TARGET)
210  {
211  SignTSVector *ressign;
212 
213  len = CALCGTSIZE(SIGNKEY, 0);
214  ressign = (SignTSVector *) palloc(len);
215  SET_VARSIZE(ressign, len);
216  ressign->flag = SIGNKEY;
217  makesign(GETSIGN(ressign), res);
218  res = ressign;
219  }
220 
221  retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
222  gistentryinit(*retval, PointerGetDatum(res),
223  entry->rel, entry->page,
224  entry->offset, false);
225  }
226  else if (ISSIGNKEY(DatumGetPointer(entry->key)) &&
227  !ISALLTRUE(DatumGetPointer(entry->key)))
228  {
229  int32 i,
230  len;
231  SignTSVector *res;
233 
234  LOOPBYTE
235  {
236  if ((sign[i] & 0xff) != 0xff)
237  PG_RETURN_POINTER(retval);
238  }
239 
240  len = CALCGTSIZE(SIGNKEY | ALLISTRUE, 0);
241  res = (SignTSVector *) palloc(len);
242  SET_VARSIZE(res, len);
243  res->flag = SIGNKEY | ALLISTRUE;
244 
245  retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
246  gistentryinit(*retval, PointerGetDatum(res),
247  entry->rel, entry->page,
248  entry->offset, false);
249  }
250  PG_RETURN_POINTER(retval);
251 }
Relation rel
Definition: gist.h:132
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define INIT_LEGACY_CRC32(crc)
Definition: pg_crc.h:79
#define GETARR(x)
Definition: tsgistidx.c:71
#define VARSIZE(PTR)
Definition: postgres.h:303
#define PointerGetDatum(X)
Definition: postgres.h:556
uint32 len
Definition: ts_type.h:44
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
#define FIN_LEGACY_CRC32(crc)
Definition: pg_crc.h:80
#define LOOPBYTE
Definition: tsgistidx.c:34
signed int int32
Definition: c.h:346
Page page
Definition: gist.h:133
#define TOAST_INDEX_TARGET
Definition: heaptoast.h:68
static void makesign(BITVECP sign, SignTSVector *a)
Definition: tsgistidx.c:151
#define CALCGTSIZE(flag, len)
Definition: tsgistidx.c:68
char sign
Definition: informix.c:688
Datum key
Definition: gist.h:131
char * c
int32 size
Definition: ts_type.h:93
int32 flag
Definition: tsgistidx.c:55
#define ARRKEY
Definition: tsgistidx.c:59
#define DatumGetTSVector(X)
Definition: ts_type.h:117
bool leafkey
Definition: gist.h:135
#define GETSIGN(x)
Definition: tsgistidx.c:70
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:215
uint32 pos
Definition: ts_type.h:44
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1069
#define SIGNKEY
Definition: tsgistidx.c:60
#define DatumGetPointer(X)
Definition: postgres.h:549
void * palloc(Size size)
Definition: mcxt.c:949
#define STRPTR(x)
Definition: hstore.h:76
#define COMP_LEGACY_CRC32(crc, data, len)
Definition: pg_crc.h:81
int i
#define ISALLTRUE(x)
Definition: tsgistidx.c:65
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
char * BITVECP
Definition: hstore_gist.c:20
uint32 pg_crc32
Definition: pg_crc.h:37
#define ARRPTR(x)
Definition: cube.c:25
static int uniqueint(int32 *a, int32 l)
Definition: tsgistidx.c:130
OffsetNumber offset
Definition: gist.h:134
#define ISSIGNKEY(x)
Definition: tsgistidx.c:64
#define ALLISTRUE
Definition: tsgistidx.c:61
long val
Definition: informix.c:684

◆ gtsvector_consistent()

Datum gtsvector_consistent ( PG_FUNCTION_ARGS  )

Definition at line 327 of file tsgistidx.c.

References CHKVAL::arrb, CHKVAL::arre, ARRNELEM, checkcondition_arr(), checkcondition_bit(), DatumGetPointer, GETARR, GETQUERY, GETSIGN, ISALLTRUE, ISSIGNKEY, sort-test::key, GISTENTRY::key, PG_GETARG_POINTER, PG_GETARG_TSQUERY, PG_RETURN_BOOL, TSQueryData::size, TS_EXEC_CALC_NOT, TS_EXEC_PHRASE_NO_POS, and TS_execute().

Referenced by gtsvector_consistent_oldsig().

328 {
329  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
330  TSQuery query = PG_GETARG_TSQUERY(1);
331 
332  /* StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); */
333  /* Oid subtype = PG_GETARG_OID(3); */
334  bool *recheck = (bool *) PG_GETARG_POINTER(4);
336 
337  /* All cases served by this function are inexact */
338  *recheck = true;
339 
340  if (!query->size)
341  PG_RETURN_BOOL(false);
342 
343  if (ISSIGNKEY(key))
344  {
345  if (ISALLTRUE(key))
346  PG_RETURN_BOOL(true);
347 
348  /* since signature is lossy, cannot specify CALC_NOT here */
350  (void *) GETSIGN(key),
353  }
354  else
355  { /* only leaf pages */
356  CHKVAL chkval;
357 
358  chkval.arrb = GETARR(key);
359  chkval.arre = chkval.arrb + ARRNELEM(key);
361  (void *) &chkval,
364  }
365 }
bool TS_execute(QueryItem *curitem, void *arg, uint32 flags, TSExecuteCallback chkcond)
Definition: tsvector_op.c:1814
#define GETARR(x)
Definition: tsgistidx.c:71
static bool checkcondition_bit(void *checkval, QueryOperand *val, ExecPhraseData *data)
Definition: tsgistidx.c:316
#define TS_EXEC_CALC_NOT
Definition: ts_utils.h:183
#define PG_GETARG_TSQUERY(n)
Definition: ts_type.h:238
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
#define GETQUERY(x)
Definition: _int.h:136
int32 * arrb
Definition: _int_bool.c:228
Datum key
Definition: gist.h:131
static bool checkcondition_arr(void *checkval, QueryOperand *val, ExecPhraseData *data)
Definition: tsgistidx.c:287
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define GETSIGN(x)
Definition: tsgistidx.c:70
#define TS_EXEC_PHRASE_NO_POS
Definition: ts_utils.h:190
#define ARRNELEM(x)
Definition: tsgistidx.c:72
#define DatumGetPointer(X)
Definition: postgres.h:549
int32 * arre
Definition: _int_bool.c:229
int32 size
Definition: ts_type.h:208
#define ISALLTRUE(x)
Definition: tsgistidx.c:65
#define ISSIGNKEY(x)
Definition: tsgistidx.c:64

◆ gtsvector_consistent_oldsig()

Datum gtsvector_consistent_oldsig ( PG_FUNCTION_ARGS  )

Definition at line 798 of file tsgistidx.c.

References gtsvector_consistent().

799 {
800  return gtsvector_consistent(fcinfo);
801 }
Datum gtsvector_consistent(PG_FUNCTION_ARGS)
Definition: tsgistidx.c:327

◆ gtsvector_decompress()

Datum gtsvector_decompress ( PG_FUNCTION_ARGS  )

Definition at line 254 of file tsgistidx.c.

References DatumGetPointer, gistentryinit, sort-test::key, GISTENTRY::key, GISTENTRY::offset, GISTENTRY::page, palloc(), PG_DETOAST_DATUM, PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, and GISTENTRY::rel.

255 {
256  /*
257  * We need to detoast the stored value, because the other gtsvector
258  * support functions don't cope with toasted values.
259  */
260  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
262 
263  if (key != (SignTSVector *) DatumGetPointer(entry->key))
264  {
265  GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
266 
267  gistentryinit(*retval, PointerGetDatum(key),
268  entry->rel, entry->page,
269  entry->offset, false);
270 
271  PG_RETURN_POINTER(retval);
272  }
273 
274  PG_RETURN_POINTER(entry);
275 }
Relation rel
Definition: gist.h:132
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
Page page
Definition: gist.h:133
Datum key
Definition: gist.h:131
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:215
#define DatumGetPointer(X)
Definition: postgres.h:549
void * palloc(Size size)
Definition: mcxt.c:949
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:235
OffsetNumber offset
Definition: gist.h:134

◆ gtsvector_penalty()

Datum gtsvector_penalty ( PG_FUNCTION_ARGS  )

Definition at line 523 of file tsgistidx.c.

References DatumGetPointer, GETSIGN, hemdist(), hemdistsign(), ISALLTRUE, ISARRKEY, GISTENTRY::key, makesign(), newval, PG_GETARG_POINTER, PG_RETURN_POINTER, SIGLENBIT, sign, and sizebitvec().

524 {
525  GISTENTRY *origentry = (GISTENTRY *) PG_GETARG_POINTER(0); /* always ISSIGNKEY */
526  GISTENTRY *newentry = (GISTENTRY *) PG_GETARG_POINTER(1);
527  float *penalty = (float *) PG_GETARG_POINTER(2);
528  SignTSVector *origval = (SignTSVector *) DatumGetPointer(origentry->key);
530  BITVECP orig = GETSIGN(origval);
531 
532  *penalty = 0.0;
533 
534  if (ISARRKEY(newval))
535  {
536  BITVEC sign;
537 
538  makesign(sign, newval);
539 
540  if (ISALLTRUE(origval))
541  *penalty = ((float) (SIGLENBIT - sizebitvec(sign))) / (float) (SIGLENBIT + 1);
542  else
543  *penalty = hemdistsign(sign, orig);
544  }
545  else
546  *penalty = hemdist(origval, newval);
547  PG_RETURN_POINTER(penalty);
548 }
static int hemdist(SignTSVector *a, SignTSVector *b)
Definition: tsgistidx.c:507
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define ISARRKEY(x)
Definition: tsgistidx.c:63
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
static int hemdistsign(BITVECP a, BITVECP b)
Definition: tsgistidx.c:491
static void makesign(BITVECP sign, SignTSVector *a)
Definition: tsgistidx.c:151
char sign
Definition: informix.c:688
Datum key
Definition: gist.h:131
char BITVEC[SIGLEN]
Definition: tsgistidx.c:31
#define GETSIGN(x)
Definition: tsgistidx.c:70
#define newval
#define DatumGetPointer(X)
Definition: postgres.h:549
#define SIGLENBIT
Definition: tsgistidx.c:29
static int32 sizebitvec(BITVECP sign)
Definition: tsgistidx.c:485
#define ISALLTRUE(x)
Definition: tsgistidx.c:65
char * BITVECP
Definition: hstore_gist.c:20

◆ gtsvector_picksplit()

Datum gtsvector_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 605 of file tsgistidx.c.

References Abs, ALLISTRUE, CALCGTSIZE, comparecost(), SPLITCOST::cost, fillcache(), FirstOffsetNumber, SignTSVector::flag, GETENTRY, GETSIGN, hemdistcache(), hemdistsign(), i, ISALLTRUE, LOOPBYTE, MemSet, GistEntryVector::n, OffsetNumberNext, palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, SPLITCOST::pos, qsort, SET_VARSIZE, SIGLENBIT, sign, CACHESIGN::sign, SIGNKEY, sizebitvec(), GIST_SPLITVEC::spl_ldatum, GIST_SPLITVEC::spl_left, GIST_SPLITVEC::spl_nleft, GIST_SPLITVEC::spl_nright, GIST_SPLITVEC::spl_rdatum, GIST_SPLITVEC::spl_right, and WISH_F.

606 {
609  OffsetNumber k,
610  j;
611  SignTSVector *datum_l,
612  *datum_r;
613  BITVECP union_l,
614  union_r;
615  int32 size_alpha,
616  size_beta;
617  int32 size_waste,
618  waste = -1;
619  int32 nbytes;
620  OffsetNumber seed_1 = 0,
621  seed_2 = 0;
622  OffsetNumber *left,
623  *right;
624  OffsetNumber maxoff;
625  BITVECP ptr;
626  int i;
627  CACHESIGN *cache;
628  SPLITCOST *costvector;
629 
630  maxoff = entryvec->n - 2;
631  nbytes = (maxoff + 2) * sizeof(OffsetNumber);
632  v->spl_left = (OffsetNumber *) palloc(nbytes);
633  v->spl_right = (OffsetNumber *) palloc(nbytes);
634 
635  cache = (CACHESIGN *) palloc(sizeof(CACHESIGN) * (maxoff + 2));
636  fillcache(&cache[FirstOffsetNumber], GETENTRY(entryvec, FirstOffsetNumber));
637 
638  for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k))
639  {
640  for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j))
641  {
642  if (k == FirstOffsetNumber)
643  fillcache(&cache[j], GETENTRY(entryvec, j));
644 
645  size_waste = hemdistcache(&(cache[j]), &(cache[k]));
646  if (size_waste > waste)
647  {
648  waste = size_waste;
649  seed_1 = k;
650  seed_2 = j;
651  }
652  }
653  }
654 
655  left = v->spl_left;
656  v->spl_nleft = 0;
657  right = v->spl_right;
658  v->spl_nright = 0;
659 
660  if (seed_1 == 0 || seed_2 == 0)
661  {
662  seed_1 = 1;
663  seed_2 = 2;
664  }
665 
666  /* form initial .. */
667  if (cache[seed_1].allistrue)
668  {
669  datum_l = (SignTSVector *) palloc(CALCGTSIZE(SIGNKEY | ALLISTRUE, 0));
670  SET_VARSIZE(datum_l, CALCGTSIZE(SIGNKEY | ALLISTRUE, 0));
671  datum_l->flag = SIGNKEY | ALLISTRUE;
672  }
673  else
674  {
675  datum_l = (SignTSVector *) palloc(CALCGTSIZE(SIGNKEY, 0));
676  SET_VARSIZE(datum_l, CALCGTSIZE(SIGNKEY, 0));
677  datum_l->flag = SIGNKEY;
678  memcpy((void *) GETSIGN(datum_l), (void *) cache[seed_1].sign, sizeof(BITVEC));
679  }
680  if (cache[seed_2].allistrue)
681  {
682  datum_r = (SignTSVector *) palloc(CALCGTSIZE(SIGNKEY | ALLISTRUE, 0));
683  SET_VARSIZE(datum_r, CALCGTSIZE(SIGNKEY | ALLISTRUE, 0));
684  datum_r->flag = SIGNKEY | ALLISTRUE;
685  }
686  else
687  {
688  datum_r = (SignTSVector *) palloc(CALCGTSIZE(SIGNKEY, 0));
689  SET_VARSIZE(datum_r, CALCGTSIZE(SIGNKEY, 0));
690  datum_r->flag = SIGNKEY;
691  memcpy((void *) GETSIGN(datum_r), (void *) cache[seed_2].sign, sizeof(BITVEC));
692  }
693 
694  union_l = GETSIGN(datum_l);
695  union_r = GETSIGN(datum_r);
696  maxoff = OffsetNumberNext(maxoff);
697  fillcache(&cache[maxoff], GETENTRY(entryvec, maxoff));
698  /* sort before ... */
699  costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff);
700  for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
701  {
702  costvector[j - 1].pos = j;
703  size_alpha = hemdistcache(&(cache[seed_1]), &(cache[j]));
704  size_beta = hemdistcache(&(cache[seed_2]), &(cache[j]));
705  costvector[j - 1].cost = Abs(size_alpha - size_beta);
706  }
707  qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
708 
709  for (k = 0; k < maxoff; k++)
710  {
711  j = costvector[k].pos;
712  if (j == seed_1)
713  {
714  *left++ = j;
715  v->spl_nleft++;
716  continue;
717  }
718  else if (j == seed_2)
719  {
720  *right++ = j;
721  v->spl_nright++;
722  continue;
723  }
724 
725  if (ISALLTRUE(datum_l) || cache[j].allistrue)
726  {
727  if (ISALLTRUE(datum_l) && cache[j].allistrue)
728  size_alpha = 0;
729  else
730  size_alpha = SIGLENBIT - sizebitvec(
731  (cache[j].allistrue) ? GETSIGN(datum_l) : GETSIGN(cache[j].sign)
732  );
733  }
734  else
735  size_alpha = hemdistsign(cache[j].sign, GETSIGN(datum_l));
736 
737  if (ISALLTRUE(datum_r) || cache[j].allistrue)
738  {
739  if (ISALLTRUE(datum_r) && cache[j].allistrue)
740  size_beta = 0;
741  else
742  size_beta = SIGLENBIT - sizebitvec(
743  (cache[j].allistrue) ? GETSIGN(datum_r) : GETSIGN(cache[j].sign)
744  );
745  }
746  else
747  size_beta = hemdistsign(cache[j].sign, GETSIGN(datum_r));
748 
749  if (size_alpha < size_beta + WISH_F(v->spl_nleft, v->spl_nright, 0.1))
750  {
751  if (ISALLTRUE(datum_l) || cache[j].allistrue)
752  {
753  if (!ISALLTRUE(datum_l))
754  MemSet((void *) GETSIGN(datum_l), 0xff, sizeof(BITVEC));
755  }
756  else
757  {
758  ptr = cache[j].sign;
759  LOOPBYTE
760  union_l[i] |= ptr[i];
761  }
762  *left++ = j;
763  v->spl_nleft++;
764  }
765  else
766  {
767  if (ISALLTRUE(datum_r) || cache[j].allistrue)
768  {
769  if (!ISALLTRUE(datum_r))
770  MemSet((void *) GETSIGN(datum_r), 0xff, sizeof(BITVEC));
771  }
772  else
773  {
774  ptr = cache[j].sign;
775  LOOPBYTE
776  union_r[i] |= ptr[i];
777  }
778  *right++ = j;
779  v->spl_nright++;
780  }
781  }
782 
783  *right = *left = FirstOffsetNumber;
784  v->spl_ldatum = PointerGetDatum(datum_l);
785  v->spl_rdatum = PointerGetDatum(datum_r);
786 
788 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
OffsetNumber pos
Definition: hstore_gist.c:320
#define PointerGetDatum(X)
Definition: postgres.h:556
OffsetNumber * spl_left
Definition: gist.h:113
Datum spl_rdatum
Definition: gist.h:120
int32 n
Definition: gist.h:206
#define MemSet(start, val, len)
Definition: c.h:955
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
int spl_nleft
Definition: gist.h:114
static int comparecost(const void *va, const void *vb)
Definition: tsgistidx.c:576
#define LOOPBYTE
Definition: tsgistidx.c:34
signed int int32
Definition: c.h:346
int32 cost
Definition: hstore_gist.c:321
uint16 OffsetNumber
Definition: off.h:24
#define Abs(x)
Definition: c.h:910
#define WISH_F(a, b, c)
Definition: tsgistidx.c:568
static int hemdistsign(BITVECP a, BITVECP b)
Definition: tsgistidx.c:491
#define CALCGTSIZE(flag, len)
Definition: tsgistidx.c:68
int spl_nright
Definition: gist.h:119
BITVEC sign
Definition: trgm_gist.c:711
char sign
Definition: informix.c:688
#define FirstOffsetNumber
Definition: off.h:27
int32 flag
Definition: tsgistidx.c:55
#define GETENTRY(vec, pos)
Definition: tsgistidx.c:46
char BITVEC[SIGLEN]
Definition: tsgistidx.c:31
static int hemdistcache(CACHESIGN *a, CACHESIGN *b)
Definition: tsgistidx.c:589
Datum spl_ldatum
Definition: gist.h:115
#define GETSIGN(x)
Definition: tsgistidx.c:70
#define OffsetNumberNext(offsetNumber)
Definition: off.h:52
OffsetNumber * spl_right
Definition: gist.h:118
#define SIGNKEY
Definition: tsgistidx.c:60
#define SIGLENBIT
Definition: tsgistidx.c:29
void * palloc(Size size)
Definition: mcxt.c:949
int i
static int32 sizebitvec(BITVECP sign)
Definition: tsgistidx.c:485
#define ISALLTRUE(x)
Definition: tsgistidx.c:65
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
char * BITVECP
Definition: hstore_gist.c:20
#define qsort(a, b, c, d)
Definition: port.h:492
#define ALLISTRUE
Definition: tsgistidx.c:61
static void fillcache(CACHESIGN *item, SignTSVector *key)
Definition: tsgistidx.c:557

◆ gtsvector_same()

Datum gtsvector_same ( PG_FUNCTION_ARGS  )

Definition at line 427 of file tsgistidx.c.

References ARRNELEM, GETARR, GETSIGN, i, ISALLTRUE, ISSIGNKEY, LOOPBYTE, PG_GETARG_POINTER, and PG_RETURN_POINTER.

428 {
431  bool *result = (bool *) PG_GETARG_POINTER(2);
432 
433  if (ISSIGNKEY(a))
434  { /* then b also ISSIGNKEY */
435  if (ISALLTRUE(a) && ISALLTRUE(b))
436  *result = true;
437  else if (ISALLTRUE(a))
438  *result = false;
439  else if (ISALLTRUE(b))
440  *result = false;
441  else
442  {
443  int32 i;
444  BITVECP sa = GETSIGN(a),
445  sb = GETSIGN(b);
446 
447  *result = true;
448  LOOPBYTE
449  {
450  if (sa[i] != sb[i])
451  {
452  *result = false;
453  break;
454  }
455  }
456  }
457  }
458  else
459  { /* a and b ISARRKEY */
460  int32 lena = ARRNELEM(a),
461  lenb = ARRNELEM(b);
462 
463  if (lena != lenb)
464  *result = false;
465  else
466  {
467  int32 *ptra = GETARR(a),
468  *ptrb = GETARR(b);
469  int32 i;
470 
471  *result = true;
472  for (i = 0; i < lena; i++)
473  if (ptra[i] != ptrb[i])
474  {
475  *result = false;
476  break;
477  }
478  }
479  }
480 
481  PG_RETURN_POINTER(result);
482 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define GETARR(x)
Definition: tsgistidx.c:71
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
#define LOOPBYTE
Definition: tsgistidx.c:34
signed int int32
Definition: c.h:346
#define GETSIGN(x)
Definition: tsgistidx.c:70
#define ARRNELEM(x)
Definition: tsgistidx.c:72
int i
#define ISALLTRUE(x)
Definition: tsgistidx.c:65
char * BITVECP
Definition: hstore_gist.c:20
#define ISSIGNKEY(x)
Definition: tsgistidx.c:64

◆ gtsvector_union()

Datum gtsvector_union ( PG_FUNCTION_ARGS  )

Definition at line 394 of file tsgistidx.c.

References ALLISTRUE, CALCGTSIZE, flag(), SignTSVector::flag, GETENTRY, GETSIGN, i, ISALLTRUE, MemSet, GistEntryVector::n, palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, SET_VARSIZE, SIGNKEY, and unionkey().

395 {
397  int *size = (int *) PG_GETARG_POINTER(1);
398  BITVEC base;
399  int32 i,
400  len;
401  int32 flag = 0;
402  SignTSVector *result;
403 
404  MemSet((void *) base, 0, sizeof(BITVEC));
405  for (i = 0; i < entryvec->n; i++)
406  {
407  if (unionkey(base, GETENTRY(entryvec, i)))
408  {
409  flag = ALLISTRUE;
410  break;
411  }
412  }
413 
414  flag |= SIGNKEY;
415  len = CALCGTSIZE(flag, 0);
416  result = (SignTSVector *) palloc(len);
417  *size = len;
418  SET_VARSIZE(result, len);
419  result->flag = flag;
420  if (!ISALLTRUE(result))
421  memcpy((void *) GETSIGN(result), (void *) base, sizeof(BITVEC));
422 
423  PG_RETURN_POINTER(result);
424 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
int32 n
Definition: gist.h:206
#define MemSet(start, val, len)
Definition: c.h:955
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
signed int int32
Definition: c.h:346
#define CALCGTSIZE(flag, len)
Definition: tsgistidx.c:68
char * flag(int b)
Definition: test-ctype.c:33
int32 flag
Definition: tsgistidx.c:55
#define GETENTRY(vec, pos)
Definition: tsgistidx.c:46
char BITVEC[SIGLEN]
Definition: tsgistidx.c:31
#define GETSIGN(x)
Definition: tsgistidx.c:70
#define SIGNKEY
Definition: tsgistidx.c:60
void * palloc(Size size)
Definition: mcxt.c:949
int i
#define ISALLTRUE(x)
Definition: tsgistidx.c:65
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
static int32 unionkey(BITVECP sbase, SignTSVector *add)
Definition: tsgistidx.c:368
#define ALLISTRUE
Definition: tsgistidx.c:61

◆ gtsvectorin()

Datum gtsvectorin ( PG_FUNCTION_ARGS  )

Definition at line 77 of file tsgistidx.c.

References ereport, errcode(), errmsg(), ERROR, and PG_RETURN_DATUM.

78 {
79  ereport(ERROR,
80  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
81  errmsg("gtsvector_in not implemented")));
82  PG_RETURN_DATUM(0);
83 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:343
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ gtsvectorout()

Datum gtsvectorout ( PG_FUNCTION_ARGS  )

Definition at line 92 of file tsgistidx.c.

References ARRNELEM, ARROUTSTR, EXTRALEN, GETSIGN, ISALLTRUE, ISARRKEY, sort-test::key, Max, outbuf_maxlen, palloc(), PG_DETOAST_DATUM, PG_FREE_IF_COPY, PG_GETARG_POINTER, PG_RETURN_POINTER, SIGLENBIT, SINGOUTSTR, sizebitvec(), and sprintf.

93 {
95  char *outbuf;
96 
97  if (outbuf_maxlen == 0)
98  outbuf_maxlen = 2 * EXTRALEN + Max(strlen(SINGOUTSTR), strlen(ARROUTSTR)) + 1;
99  outbuf = palloc(outbuf_maxlen);
100 
101  if (ISARRKEY(key))
102  sprintf(outbuf, ARROUTSTR, (int) ARRNELEM(key));
103  else
104  {
105  int cnttrue = (ISALLTRUE(key)) ? SIGLENBIT : sizebitvec(GETSIGN(key));
106 
107  sprintf(outbuf, SINGOUTSTR, cnttrue, (int) SIGLENBIT - cnttrue);
108  }
109 
110  PG_FREE_IF_COPY(key, 0);
111  PG_RETURN_POINTER(outbuf);
112 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define ISARRKEY(x)
Definition: tsgistidx.c:63
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
#define sprintf
Definition: port.h:194
#define SINGOUTSTR
Definition: tsgistidx.c:85
#define ARROUTSTR
Definition: tsgistidx.c:86
#define EXTRALEN
Definition: tsgistidx.c:87
#define Max(x, y)
Definition: c.h:898
#define GETSIGN(x)
Definition: tsgistidx.c:70
#define ARRNELEM(x)
Definition: tsgistidx.c:72
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define SIGLENBIT
Definition: tsgistidx.c:29
void * palloc(Size size)
Definition: mcxt.c:949
static int32 sizebitvec(BITVECP sign)
Definition: tsgistidx.c:485
#define ISALLTRUE(x)
Definition: tsgistidx.c:65
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:235
static int outbuf_maxlen
Definition: tsgistidx.c:89

◆ hemdist()

static int hemdist ( SignTSVector a,
SignTSVector b 
)
static

Definition at line 507 of file tsgistidx.c.

References GETSIGN, hemdistsign(), ISALLTRUE, SIGLENBIT, and sizebitvec().

Referenced by gtsvector_penalty().

508 {
509  if (ISALLTRUE(a))
510  {
511  if (ISALLTRUE(b))
512  return 0;
513  else
514  return SIGLENBIT - sizebitvec(GETSIGN(b));
515  }
516  else if (ISALLTRUE(b))
517  return SIGLENBIT - sizebitvec(GETSIGN(a));
518 
519  return hemdistsign(GETSIGN(a), GETSIGN(b));
520 }
static int hemdistsign(BITVECP a, BITVECP b)
Definition: tsgistidx.c:491
#define GETSIGN(x)
Definition: tsgistidx.c:70
#define SIGLENBIT
Definition: tsgistidx.c:29
static int32 sizebitvec(BITVECP sign)
Definition: tsgistidx.c:485
#define ISALLTRUE(x)
Definition: tsgistidx.c:65

◆ hemdistcache()

static int hemdistcache ( CACHESIGN a,
CACHESIGN b 
)
static

Definition at line 589 of file tsgistidx.c.

References CACHESIGN::allistrue, hemdistsign(), SIGLENBIT, CACHESIGN::sign, and sizebitvec().

Referenced by gtsvector_picksplit().

590 {
591  if (a->allistrue)
592  {
593  if (b->allistrue)
594  return 0;
595  else
596  return SIGLENBIT - sizebitvec(b->sign);
597  }
598  else if (b->allistrue)
599  return SIGLENBIT - sizebitvec(a->sign);
600 
601  return hemdistsign(a->sign, b->sign);
602 }
static int hemdistsign(BITVECP a, BITVECP b)
Definition: tsgistidx.c:491
BITVEC sign
Definition: trgm_gist.c:711
#define SIGLENBIT
Definition: tsgistidx.c:29
static int32 sizebitvec(BITVECP sign)
Definition: tsgistidx.c:485
bool allistrue
Definition: trgm_gist.c:710

◆ hemdistsign()

static int hemdistsign ( BITVECP  a,
BITVECP  b 
)
static

Definition at line 491 of file tsgistidx.c.

References i, LOOPBYTE, and pg_number_of_ones.

Referenced by gtsvector_penalty(), gtsvector_picksplit(), hemdist(), and hemdistcache().

492 {
493  int i,
494  diff,
495  dist = 0;
496 
497  LOOPBYTE
498  {
499  diff = (unsigned char) (a[i] ^ b[i]);
500  /* Using the popcount functions here isn't likely to win */
501  dist += pg_number_of_ones[diff];
502  }
503  return dist;
504 }
#define LOOPBYTE
Definition: tsgistidx.c:34
PGDLLIMPORT const uint8 pg_number_of_ones[256]
Definition: pg_bitutils.c:87
int i

◆ makesign()

static void makesign ( BITVECP  sign,
SignTSVector a 
)
static

Definition at line 151 of file tsgistidx.c.

References ARRNELEM, GETARR, HASH, and MemSet.

Referenced by fillcache(), gtsvector_compress(), and gtsvector_penalty().

152 {
153  int32 k,
154  len = ARRNELEM(a);
155  int32 *ptr = GETARR(a);
156 
157  MemSet((void *) sign, 0, sizeof(BITVEC));
158  for (k = 0; k < len; k++)
159  HASH(sign, ptr[k]);
160 }
#define GETARR(x)
Definition: tsgistidx.c:71
#define MemSet(start, val, len)
Definition: c.h:955
signed int int32
Definition: c.h:346
char sign
Definition: informix.c:688
char BITVEC[SIGLEN]
Definition: tsgistidx.c:31
#define ARRNELEM(x)
Definition: tsgistidx.c:72
#define HASH(sign, val)
Definition: tsgistidx.c:44

◆ sizebitvec()

static int32 sizebitvec ( BITVECP  sign)
static

Definition at line 485 of file tsgistidx.c.

References pg_popcount(), and SIGLEN.

Referenced by gtsvector_penalty(), gtsvector_picksplit(), gtsvectorout(), hemdist(), and hemdistcache().

486 {
487  return pg_popcount(sign, SIGLEN);
488 }
#define SIGLEN
Definition: tsgistidx.c:28
uint64 pg_popcount(const char *buf, int bytes)
Definition: pg_bitutils.c:282
char sign
Definition: informix.c:688

◆ unionkey()

static int32 unionkey ( BITVECP  sbase,
SignTSVector add 
)
static

Definition at line 368 of file tsgistidx.c.

References ARRNELEM, GETARR, GETSIGN, HASH, i, ISALLTRUE, ISSIGNKEY, and LOOPBYTE.

Referenced by gtsvector_union().

369 {
370  int32 i;
371 
372  if (ISSIGNKEY(add))
373  {
374  BITVECP sadd = GETSIGN(add);
375 
376  if (ISALLTRUE(add))
377  return 1;
378 
379  LOOPBYTE
380  sbase[i] |= sadd[i];
381  }
382  else
383  {
384  int32 *ptr = GETARR(add);
385 
386  for (i = 0; i < ARRNELEM(add); i++)
387  HASH(sbase, ptr[i]);
388  }
389  return 0;
390 }
#define GETARR(x)
Definition: tsgistidx.c:71
#define LOOPBYTE
Definition: tsgistidx.c:34
signed int int32
Definition: c.h:346
#define GETSIGN(x)
Definition: tsgistidx.c:70
#define ARRNELEM(x)
Definition: tsgistidx.c:72
int i
#define ISALLTRUE(x)
Definition: tsgistidx.c:65
#define HASH(sign, val)
Definition: tsgistidx.c:44
char * BITVECP
Definition: hstore_gist.c:20
#define ISSIGNKEY(x)
Definition: tsgistidx.c:64

◆ uniqueint()

static int uniqueint ( int32 a,
int32  l 
)
static

Definition at line 130 of file tsgistidx.c.

References compareint(), and qsort.

Referenced by gtsvector_compress().

131 {
132  int32 *ptr,
133  *res;
134 
135  if (l <= 1)
136  return l;
137 
138  ptr = res = a;
139 
140  qsort((void *) a, l, sizeof(int32), compareint);
141 
142  while (ptr - a < l)
143  if (*ptr != *res)
144  *(++res) = *ptr++;
145  else
146  ptr++;
147  return res + 1 - a;
148 }
static int compareint(const void *va, const void *vb)
Definition: tsgistidx.c:115
signed int int32
Definition: c.h:346
#define qsort(a, b, c, d)
Definition: port.h:492

Variable Documentation

◆ outbuf_maxlen

int outbuf_maxlen = 0
static

Definition at line 89 of file tsgistidx.c.

Referenced by gtsvectorout().