19 #define GET_SIGLEN() (PG_HAS_OPCLASS_OPTIONS() ? \
20 ((TrgmGistOptions *) PG_GET_OPCLASS_OPTIONS())->siglen : \
39 #define GETENTRY(vec,pos) ((TRGM *) DatumGetPointer((vec)->vector[(pos)].key))
100 for (k = 0; k <
len; k++)
102 CPTRGM(((
char *) &tmp), ptr + k);
134 if ((
sign[
i] & 0xff) != 0xff)
180 for (k = 0; k <
len; k++)
182 CPTRGM(((
char *) &tmp), ptr + k);
224 memcmp((
char *) cache->
query, (
char *) query, querysize) != 0)
241 elog(
ERROR,
"cannot handle ~~* with case-sensitive trigrams");
250 elog(
ERROR,
"cannot handle ~* with case-sensitive trigrams");
255 &graph, fcinfo->flinfo->fn_mcxt);
264 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
269 qtrgsize = qtrg ?
VARSIZE(qtrg) : 0;
280 memcpy((
char *) newcache->
query, (
char *) query, querysize);
285 memcpy((
char *) newcache->
trigrams, (
char *) qtrg, qtrgsize);
291 newcache->
graph = graph;
295 fcinfo->flinfo->fn_extra = (
void *) newcache;
319 res = (tmpsml >= nlimit);
338 elog(
ERROR,
"cannot handle ~~* with case-sensitive trigrams");
367 for (k = 0; k <
len; k++)
369 CPTRGM(((
char *) &tmp), ptr + k);
380 elog(
ERROR,
"cannot handle ~* with case-sensitive trigrams");
419 check = (
bool *)
palloc(
len *
sizeof(
bool));
420 for (k = 0; k <
len; k++)
422 CPTRGM(((
char *) &tmp), ptr + k);
436 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
458 char *cache = (
char *) fcinfo->flinfo->fn_extra;
465 memcmp(cache, query, querysize) != 0)
475 memcpy(newcache, query, querysize);
480 fcinfo->flinfo->fn_extra = newcache;
518 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
548 CPTRGM(((
char *) &tmp), ptr +
i);
549 HASH(sbase, tmp, siglen);
629 for (
i = 0;
i < lena;
i++)
656 diff = (
unsigned char) (
a[
i] ^
b[
i]);
694 char *cache = (
char *) fcinfo->flinfo->fn_extra;
703 VARSIZE(cachedVal) != newvalsize ||
704 memcmp(cachedVal,
newval, newvalsize) != 0)
715 memcpy(cachedVal,
newval, newvalsize);
719 fcinfo->flinfo->fn_extra = newcache;
754 #define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
781 else if (
b->allistrue)
817 cache_sign =
palloc(siglen * (maxoff + 1));
829 if (size_waste > waste)
839 if (seed_1 == 0 || seed_2 == 0)
853 datum_l =
gtrgm_alloc(cache[seed_1].allistrue, siglen, cache[seed_1].
sign);
854 datum_r =
gtrgm_alloc(cache[seed_2].allistrue, siglen, cache[seed_2].
sign);
863 costvector[
j - 1].
pos =
j;
864 size_alpha =
hemdistcache(&(cache[seed_1]), &(cache[
j]), siglen);
865 size_beta =
hemdistcache(&(cache[seed_2]), &(cache[
j]), siglen);
866 costvector[
j - 1].
cost = abs(size_alpha - size_beta);
870 for (k = 0; k < maxoff; k++)
872 j = costvector[k].
pos;
879 else if (
j == seed_2)
923 union_l[
i] |= ptr[
i];
939 union_r[
i] |= ptr[
i];
959 "signature length in bytes",
#define offsetof(type, field)
#define MemSet(start, val, len)
static void PGresult * res
#define PG_RETURN_FLOAT8(x)
#define DatumGetTextPP(X)
#define PG_GETARG_POINTER(n)
#define PG_GETARG_UINT16(n)
#define PG_RETURN_DATUM(x)
#define PG_RETURN_POINTER(x)
#define PG_GET_COLLATION()
#define PG_RETURN_BOOL(x)
#define PG_GETARG_TEXT_P(n)
#define gistentryinit(e, k, r, pg, o, l)
#define HASHVAL(val, siglen)
#define CALCGTSIZE(flag, siglen)
#define SIGLENBIT(siglen)
#define HASH(sign, val, siglen)
void pfree(void *pointer)
void * MemoryContextAlloc(MemoryContext context, Size size)
#define OffsetNumberNext(offsetNumber)
#define FirstOffsetNumber
PGDLLIMPORT const uint8 pg_number_of_ones[256]
uint64 pg_popcount(const char *buf, int bytes)
#define qsort(a, b, c, d)
#define DatumGetPointer(X)
#define SET_VARSIZE(PTR, len)
#define PointerGetDatum(X)
#define VARSIZE_ANY_EXHDR(PTR)
void init_local_reloptions(local_relopts *opts, Size relopt_struct_size)
void add_local_int_reloption(local_relopts *relopts, const char *name, const char *desc, int default_val, int min_val, int max_val, int offset)
#define RegExpICaseStrategyNumber
bool * trgm_presence_map(TRGM *query, TRGM *key)
TRGM * generate_trgm(char *str, int slen)
#define WordSimilarityStrategyNumber
#define DistanceStrategyNumber
#define StrictWordSimilarityStrategyNumber
TRGM * generate_wildcard_trgm(const char *str, int slen)
#define StrictWordDistanceStrategyNumber
double index_strategy_get_limit(StrategyNumber strategy)
#define SimilarityStrategyNumber
bool trigramsMatchGraph(TrgmPackedGraph *graph, bool *check)
bool trgm_contained_by(TRGM *trg1, TRGM *trg2)
#define ILikeStrategyNumber
TRGM * createTrgmNFA(text *text_re, Oid collation, TrgmPackedGraph **graph, MemoryContext rcontext)
float4 cnt_sml(TRGM *trg1, TRGM *trg2, bool inexact)
#define LikeStrategyNumber
#define EqualStrategyNumber
#define RegExpStrategyNumber
#define WordDistanceStrategyNumber
Datum gtrgm_out(PG_FUNCTION_ARGS)
static int hemdistcache(CACHESIGN *a, CACHESIGN *b, int siglen)
static void fillcache(CACHESIGN *item, TRGM *key, BITVECP sign, int siglen)
Datum gtrgm_same(PG_FUNCTION_ARGS)
static int32 unionkey(BITVECP sbase, TRGM *add, int siglen)
PG_FUNCTION_INFO_V1(gtrgm_in)
Datum gtrgm_distance(PG_FUNCTION_ARGS)
static int32 sizebitvec(BITVECP sign, int siglen)
Datum gtrgm_in(PG_FUNCTION_ARGS)
Datum gtrgm_options(PG_FUNCTION_ARGS)
static int hemdistsign(BITVECP a, BITVECP b, int siglen)
#define GETENTRY(vec, pos)
Datum gtrgm_compress(PG_FUNCTION_ARGS)
Datum gtrgm_picksplit(PG_FUNCTION_ARGS)
Datum gtrgm_decompress(PG_FUNCTION_ARGS)
static TRGM * gtrgm_alloc(bool isalltrue, int siglen, BITVECP sign)
Datum gtrgm_union(PG_FUNCTION_ARGS)
Datum gtrgm_penalty(PG_FUNCTION_ARGS)
static void makesign(BITVECP sign, TRGM *a, int siglen)
Datum gtrgm_consistent(PG_FUNCTION_ARGS)
static int32 cnt_sml_sign_common(TRGM *qtrg, BITVECP sign, int siglen)
static int hemdist(TRGM *a, TRGM *b, int siglen)
static int comparecost(const void *a, const void *b)