20 #define GET_SIGLEN() (PG_HAS_OPCLASS_OPTIONS() ? \
21 ((TrgmGistOptions *) PG_GET_OPCLASS_OPTIONS())->siglen : \
40 #define GETENTRY(vec,pos) ((TRGM *) DatumGetPointer((vec)->vector[(pos)].key))
60 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
61 errmsg(
"cannot accept a value of type %s",
"gtrgm")));
70 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
71 errmsg(
"cannot display a value of type %s",
"gtrgm")));
107 for (k = 0; k <
len; k++)
109 CPTRGM(((
char *) &tmp), ptr + k);
141 if ((
sign[
i] & 0xff) != 0xff)
187 for (k = 0; k <
len; k++)
189 CPTRGM(((
char *) &tmp), ptr + k);
231 memcmp((
char *) cache->
query, (
char *) query, querysize) != 0)
248 elog(
ERROR,
"cannot handle ~~* with case-sensitive trigrams");
257 elog(
ERROR,
"cannot handle ~* with case-sensitive trigrams");
262 &graph, fcinfo->flinfo->fn_mcxt);
271 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
276 qtrgsize = qtrg ?
VARSIZE(qtrg) : 0;
287 memcpy((
char *) newcache->
query, (
char *) query, querysize);
292 memcpy((
char *) newcache->
trigrams, (
char *) qtrg, qtrgsize);
298 newcache->
graph = graph;
302 fcinfo->flinfo->fn_extra = (
void *) newcache;
326 res = (tmpsml >= nlimit);
345 elog(
ERROR,
"cannot handle ~~* with case-sensitive trigrams");
374 for (k = 0; k <
len; k++)
376 CPTRGM(((
char *) &tmp), ptr + k);
387 elog(
ERROR,
"cannot handle ~* with case-sensitive trigrams");
426 check = (
bool *)
palloc(
len *
sizeof(
bool));
427 for (k = 0; k <
len; k++)
429 CPTRGM(((
char *) &tmp), ptr + k);
443 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
465 char *cache = (
char *) fcinfo->flinfo->fn_extra;
472 memcmp(cache, query, querysize) != 0)
482 memcpy(newcache, query, querysize);
487 fcinfo->flinfo->fn_extra = newcache;
525 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
555 CPTRGM(((
char *) &tmp), ptr +
i);
556 HASH(sbase, tmp, siglen);
636 for (
i = 0;
i < lena;
i++)
663 diff = (
unsigned char) (
a[
i] ^
b[
i]);
701 char *cache = (
char *) fcinfo->flinfo->fn_extra;
710 VARSIZE(cachedVal) != newvalsize ||
711 memcmp(cachedVal,
newval, newvalsize) != 0)
722 memcpy(cachedVal,
newval, newvalsize);
726 fcinfo->flinfo->fn_extra = newcache;
761 #define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
788 else if (
b->allistrue)
824 cache_sign =
palloc(siglen * (maxoff + 1));
836 if (size_waste > waste)
846 if (seed_1 == 0 || seed_2 == 0)
860 datum_l =
gtrgm_alloc(cache[seed_1].allistrue, siglen, cache[seed_1].
sign);
861 datum_r =
gtrgm_alloc(cache[seed_2].allistrue, siglen, cache[seed_2].
sign);
870 costvector[
j - 1].
pos =
j;
871 size_alpha =
hemdistcache(&(cache[seed_1]), &(cache[
j]), siglen);
872 size_beta =
hemdistcache(&(cache[seed_2]), &(cache[
j]), siglen);
873 costvector[
j - 1].
cost = abs(size_alpha - size_beta);
877 for (k = 0; k < maxoff; k++)
879 j = costvector[k].
pos;
886 else if (
j == seed_2)
924 memset(
GETSIGN(datum_l), 0xff, siglen);
930 union_l[
i] |= ptr[
i];
940 memset(
GETSIGN(datum_r), 0xff, siglen);
946 union_r[
i] |= ptr[
i];
966 "signature length in bytes",
#define MemSet(start, val, len)
static void PGresult * res
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define PG_RETURN_FLOAT8(x)
#define DatumGetTextPP(X)
#define PG_GETARG_POINTER(n)
#define PG_GETARG_UINT16(n)
#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)
if(TABLE==NULL||TABLE_index==NULL)
void pfree(void *pointer)
void * MemoryContextAlloc(MemoryContext context, Size size)
#define OffsetNumberNext(offsetNumber)
#define FirstOffsetNumber
PGDLLIMPORT const uint8 pg_number_of_ones[256]
static uint64 pg_popcount(const char *buf, int bytes)
#define qsort(a, b, c, d)
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
void init_local_reloptions(local_relopts *relopts, 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)
static pg_noinline void Size size
#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)
#define SET_VARSIZE(PTR, len)
#define VARSIZE_ANY_EXHDR(PTR)