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)) 82 memcpy(
GETSIGN(res), sign, siglen);
84 memset(
GETSIGN(res), 0, siglen);
98 MemSet((
void *) sign, 0, siglen);
100 for (k = 0; k < len; k++)
102 CPTRGM(((
char *) &tmp), ptr + k);
103 HASH(sign, tmp, siglen);
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;
317 double tmpsml =
cnt_sml(qtrg, key, *recheck);
319 res = (tmpsml >= nlimit);
333 res = (((((
float8) count) / ((
float8) len))) >= 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;
514 res = (len == 0) ? -1.0 : 1.0 - ((
float8) count) / ((
float8) len);
518 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
548 CPTRGM(((
char *) &tmp), ptr + i);
549 HASH(sbase, tmp, siglen);
567 for (i = 0; i < len; i++)
629 for (i = 0; i < lena; i++)
630 if (
CMPTRGM(ptra + i, ptrb + 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;
731 *penalty =
hemdist(origval, newval, siglen);
751 memcpy((
void *) item->
sign, (
void *)
GETSIGN(key), siglen);
754 #define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) ) 817 cache_sign =
palloc(siglen * (maxoff + 1));
828 size_waste =
hemdistcache(&(cache[j]), &(cache[k]), siglen);
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)
886 if (
ISALLTRUE(datum_l) || cache[j].allistrue)
888 if (
ISALLTRUE(datum_l) && cache[j].allistrue)
899 if (
ISALLTRUE(datum_r) || cache[j].allistrue)
901 if (
ISALLTRUE(datum_r) && cache[j].allistrue)
914 if (
ISALLTRUE(datum_l) || cache[j].allistrue)
923 union_l[
i] |= ptr[
i];
930 if (
ISALLTRUE(datum_r) || cache[j].allistrue)
939 union_r[
i] |= ptr[
i];
959 "signature length in bytes",
#define PG_RETURN_POINTER(x)
bool trigramsMatchGraph(TrgmPackedGraph *graph, bool *check)
#define StrictWordDistanceStrategyNumber
static int32 sizebitvec(BITVECP sign, int siglen)
void init_local_reloptions(local_relopts *opts, Size relopt_struct_size)
#define RegExpStrategyNumber
TRGM * generate_wildcard_trgm(const char *str, int slen)
#define SimilarityStrategyNumber
#define PointerGetDatum(X)
#define DistanceStrategyNumber
PG_FUNCTION_INFO_V1(gtrgm_in)
TRGM * createTrgmNFA(text *text_re, Oid collation, TrgmPackedGraph **graph, MemoryContext rcontext)
#define StrictWordSimilarityStrategyNumber
static int32 unionkey(BITVECP sbase, TRGM *add, int siglen)
#define RegExpICaseStrategyNumber
#define DatumGetTextPP(X)
#define WordDistanceStrategyNumber
#define PG_RETURN_FLOAT8(x)
Datum gtrgm_union(PG_FUNCTION_ARGS)
static int comparecost(const void *a, const void *b)
float4 cnt_sml(TRGM *trg1, TRGM *trg2, bool inexact)
#define MemSet(start, val, len)
#define PG_GETARG_POINTER(n)
bool * trgm_presence_map(TRGM *query, TRGM *key)
Datum gtrgm_same(PG_FUNCTION_ARGS)
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 PG_GET_COLLATION()
uint64 pg_popcount(const char *buf, int bytes)
#define CALCGTSIZE(flag, siglen)
#define HASH(sign, val, siglen)
Datum gtrgm_distance(PG_FUNCTION_ARGS)
void pfree(void *pointer)
Datum gtrgm_options(PG_FUNCTION_ARGS)
#define EqualStrategyNumber
Datum gtrgm_consistent(PG_FUNCTION_ARGS)
static void fillcache(CACHESIGN *item, TRGM *key, BITVECP sign, int siglen)
#define LikeStrategyNumber
#define FirstOffsetNumber
double index_strategy_get_limit(StrategyNumber strategy)
bool trgm_contained_by(TRGM *trg1, TRGM *trg2)
static int hemdistcache(CACHESIGN *a, CACHESIGN *b, int siglen)
static int hemdist(TRGM *a, TRGM *b, int siglen)
Datum gtrgm_out(PG_FUNCTION_ARGS)
#define PG_RETURN_BOOL(x)
#define GETENTRY(vec, pos)
#define PG_RETURN_DATUM(x)
static int hemdistsign(BITVECP a, BITVECP b, int siglen)
Datum gtrgm_penalty(PG_FUNCTION_ARGS)
Datum gtrgm_picksplit(PG_FUNCTION_ARGS)
#define WordSimilarityStrategyNumber
#define HASHVAL(val, siglen)
#define SIGLENBIT(siglen)
#define gistentryinit(e, k, r, pg, o, l)
Datum gtrgm_decompress(PG_FUNCTION_ARGS)
TRGM * generate_trgm(char *str, int slen)
#define OffsetNumberNext(offsetNumber)
#define PG_GETARG_UINT16(n)
#define DatumGetPointer(X)
PGDLLIMPORT const uint8 pg_number_of_ones[256]
#define VARSIZE_ANY_EXHDR(PTR)
#define PG_GETARG_TEXT_P(n)
void * MemoryContextAlloc(MemoryContext context, Size size)
static int32 cnt_sml_sign_common(TRGM *qtrg, BITVECP sign, int siglen)
#define SET_VARSIZE(PTR, len)
#define ILikeStrategyNumber
static void makesign(BITVECP sign, TRGM *a, int siglen)
#define qsort(a, b, c, d)
Datum gtrgm_in(PG_FUNCTION_ARGS)
Datum gtrgm_compress(PG_FUNCTION_ARGS)
static TRGM * gtrgm_alloc(bool isalltrue, int siglen, BITVECP sign)
#define offsetof(type, field)