diff options
| author | Robert Haas | 2016-06-09 22:02:36 +0000 |
|---|---|---|
| committer | Robert Haas | 2016-06-09 22:02:36 +0000 |
| commit | 4bc424b968058c7f0aa685821d7039e86faac99c (patch) | |
| tree | a4e245ae67bd11edb3926ff5fb3b0223438ac283 /contrib/pg_trgm | |
| parent | 9164deea2f4ac90ee5e008ff41fc5ad4423887b2 (diff) | |
pgindent run for 9.6
Diffstat (limited to 'contrib/pg_trgm')
| -rw-r--r-- | contrib/pg_trgm/trgm_gin.c | 17 | ||||
| -rw-r--r-- | contrib/pg_trgm/trgm_gist.c | 3 | ||||
| -rw-r--r-- | contrib/pg_trgm/trgm_op.c | 123 |
3 files changed, 76 insertions, 67 deletions
diff --git a/contrib/pg_trgm/trgm_gin.c b/contrib/pg_trgm/trgm_gin.c index 8c190415910..ead33ef5447 100644 --- a/contrib/pg_trgm/trgm_gin.c +++ b/contrib/pg_trgm/trgm_gin.c @@ -265,13 +265,13 @@ gin_trgm_consistent(PG_FUNCTION_ARGS) Datum gin_trgm_triconsistent(PG_FUNCTION_ARGS) { - GinTernaryValue *check = (GinTernaryValue *) PG_GETARG_POINTER(0); + GinTernaryValue *check = (GinTernaryValue *) PG_GETARG_POINTER(0); StrategyNumber strategy = PG_GETARG_UINT16(1); /* text *query = PG_GETARG_TEXT_P(2); */ int32 nkeys = PG_GETARG_INT32(3); Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); - GinTernaryValue res = GIN_MAYBE; + GinTernaryValue res = GIN_MAYBE; int32 i, ntrue; bool *boolcheck; @@ -293,11 +293,12 @@ gin_trgm_triconsistent(PG_FUNCTION_ARGS) } /* - * See comment in gin_trgm_consistent() about * upper bound formula + * See comment in gin_trgm_consistent() about * upper bound + * formula */ res = (nkeys == 0) ? GIN_FALSE : (((((float4) ntrue) / ((float4) nkeys)) >= nlimit) - ? GIN_MAYBE : GIN_FALSE); + ? GIN_MAYBE : GIN_FALSE); break; case ILikeStrategyNumber: #ifndef IGNORECASE @@ -330,9 +331,9 @@ gin_trgm_triconsistent(PG_FUNCTION_ARGS) else { /* - * As trigramsMatchGraph implements a monotonic boolean function, - * promoting all GIN_MAYBE keys to GIN_TRUE will give a - * conservative result. + * As trigramsMatchGraph implements a monotonic boolean + * function, promoting all GIN_MAYBE keys to GIN_TRUE will + * give a conservative result. */ boolcheck = (bool *) palloc(sizeof(bool) * nkeys); for (i = 0; i < nkeys; i++) @@ -345,7 +346,7 @@ gin_trgm_triconsistent(PG_FUNCTION_ARGS) break; default: elog(ERROR, "unrecognized strategy number: %d", strategy); - res = GIN_FALSE; /* keep compiler quiet */ + res = GIN_FALSE; /* keep compiler quiet */ break; } diff --git a/contrib/pg_trgm/trgm_gist.c b/contrib/pg_trgm/trgm_gist.c index 2181c2623fa..3a5aff9edee 100644 --- a/contrib/pg_trgm/trgm_gist.c +++ b/contrib/pg_trgm/trgm_gist.c @@ -296,6 +296,7 @@ gtrgm_consistent(PG_FUNCTION_ARGS) if (GIST_LEAF(entry)) { /* all leafs contains orig trgm */ + /* * Prevent gcc optimizing the tmpsml variable using volatile * keyword. Otherwise comparison of nlimit and tmpsml may give @@ -476,12 +477,14 @@ gtrgm_distance(PG_FUNCTION_ARGS) *recheck = strategy == WordDistanceStrategyNumber; if (GIST_LEAF(entry)) { /* all leafs contains orig trgm */ + /* * Prevent gcc optimizing the sml variable using volatile * keyword. Otherwise res can differ from the * word_similarity_dist_op() function. */ float4 volatile sml = cnt_sml(qtrg, key, *recheck); + res = 1.0 - sml; } else if (ISALLTRUE(key)) diff --git a/contrib/pg_trgm/trgm_op.c b/contrib/pg_trgm/trgm_op.c index b728cc1abd3..dd0f492cfab 100644 --- a/contrib/pg_trgm/trgm_op.c +++ b/contrib/pg_trgm/trgm_op.c @@ -16,8 +16,8 @@ PG_MODULE_MAGIC; /* GUC variables */ -double similarity_threshold = 0.3f; -double word_similarity_threshold = 0.6f; +double similarity_threshold = 0.3f; +double word_similarity_threshold = 0.6f; void _PG_init(void); @@ -36,8 +36,8 @@ PG_FUNCTION_INFO_V1(word_similarity_dist_commutator_op); /* Trigram with position */ typedef struct { - trgm trg; - int index; + trgm trg; + int index; } pos_trgm; /* @@ -48,29 +48,29 @@ _PG_init(void) { /* Define custom GUC variables. */ DefineCustomRealVariable("pg_trgm.similarity_threshold", - "Sets the threshold used by the %% operator.", - "Valid range is 0.0 .. 1.0.", - &similarity_threshold, - 0.3, - 0.0, - 1.0, - PGC_USERSET, - 0, - NULL, - NULL, - NULL); + "Sets the threshold used by the %% operator.", + "Valid range is 0.0 .. 1.0.", + &similarity_threshold, + 0.3, + 0.0, + 1.0, + PGC_USERSET, + 0, + NULL, + NULL, + NULL); DefineCustomRealVariable("pg_trgm.word_similarity_threshold", - "Sets the threshold used by the <%% operator.", - "Valid range is 0.0 .. 1.0.", - &word_similarity_threshold, - 0.6, - 0.0, - 1.0, - PGC_USERSET, - 0, - NULL, - NULL, - NULL); + "Sets the threshold used by the <%% operator.", + "Valid range is 0.0 .. 1.0.", + &word_similarity_threshold, + 0.6, + 0.0, + 1.0, + PGC_USERSET, + 0, + NULL, + NULL, + NULL); } /* @@ -352,9 +352,9 @@ generate_trgm(char *str, int slen) * Make array of positional trigrams from two trigram arrays trg1 and trg2. * * trg1: trigram array of search pattern, of length len1. trg1 is required - * word which positions don't matter and replaced with -1. + * word which positions don't matter and replaced with -1. * trg2: trigram array of text, of length len2. trg2 is haystack where we - * search and have to store its positions. + * search and have to store its positions. * * Returns concatenated trigram array. */ @@ -362,7 +362,8 @@ static pos_trgm * make_positional_trgm(trgm *trg1, int len1, trgm *trg2, int len2) { pos_trgm *result; - int i, len = len1 + len2; + int i, + len = len1 + len2; result = (pos_trgm *) palloc(sizeof(pos_trgm) * len); @@ -387,9 +388,9 @@ make_positional_trgm(trgm *trg1, int len1, trgm *trg2, int len2) static int comp_ptrgm(const void *v1, const void *v2) { - const pos_trgm *p1 = (const pos_trgm *)v1; - const pos_trgm *p2 = (const pos_trgm *)v2; - int cmp; + const pos_trgm *p1 = (const pos_trgm *) v1; + const pos_trgm *p2 = (const pos_trgm *) v2; + int cmp; cmp = CMPTRGM(p1->trg, p2->trg); if (cmp != 0) @@ -413,7 +414,7 @@ comp_ptrgm(const void *v1, const void *v2) * len2: length of array "trg2" and array "trg2indexes". * len: length of the array "found". * check_only: if true then only check existaince of similar search pattern in - * text. + * text. * * Returns word similarity. */ @@ -441,7 +442,7 @@ iterate_word_similarity(int *trg2indexes, for (i = 0; i < len2; i++) { /* Get index of next trigram */ - int trgindex = trg2indexes[i]; + int trgindex = trg2indexes[i]; /* Update last position of this trigram */ if (lower >= 0 || found[trgindex]) @@ -458,10 +459,10 @@ iterate_word_similarity(int *trg2indexes, /* Adjust lower bound if this trigram is present in required substing */ if (found[trgindex]) { - int prev_lower, - tmp_ulen2, - tmp_lower, - tmp_count; + int prev_lower, + tmp_ulen2, + tmp_lower, + tmp_count; upper = i; if (lower == -1) @@ -478,8 +479,8 @@ iterate_word_similarity(int *trg2indexes, prev_lower = lower; for (tmp_lower = lower; tmp_lower <= upper; tmp_lower++) { - float smlr_tmp = CALCSML(tmp_count, ulen1, tmp_ulen2); - int tmp_trgindex; + float smlr_tmp = CALCSML(tmp_count, ulen1, tmp_ulen2); + int tmp_trgindex; if (smlr_tmp > smlr_cur) { @@ -488,10 +489,11 @@ iterate_word_similarity(int *trg2indexes, lower = tmp_lower; count = tmp_count; } + /* * if we only check that word similarity is greater than - * pg_trgm.word_similarity_threshold we do not need to calculate - * a maximum similarity. + * pg_trgm.word_similarity_threshold we do not need to + * calculate a maximum similarity. */ if (check_only && smlr_cur >= word_similarity_threshold) break; @@ -506,6 +508,7 @@ iterate_word_similarity(int *trg2indexes, } smlr_max = Max(smlr_max, smlr_cur); + /* * if we only check that word similarity is greater than * pg_trgm.word_similarity_threshold we do not need to calculate a @@ -516,7 +519,8 @@ iterate_word_similarity(int *trg2indexes, for (tmp_lower = prev_lower; tmp_lower < lower; tmp_lower++) { - int tmp_trgindex; + int tmp_trgindex; + tmp_trgindex = trg2indexes[tmp_lower]; if (lastpos[tmp_trgindex] == tmp_lower) lastpos[tmp_trgindex] = -1; @@ -544,13 +548,13 @@ iterate_word_similarity(int *trg2indexes, * str1: search pattern string, of length slen1 bytes. * str2: text in which we are looking for a word, of length slen2 bytes. * check_only: if true then only check existaince of similar search pattern in - * text. + * text. * * Returns word similarity. */ static float4 calc_word_similarity(char *str1, int slen1, char *str2, int slen2, - bool check_only) + bool check_only) { bool *found; pos_trgm *ptrg; @@ -568,8 +572,8 @@ calc_word_similarity(char *str1, int slen1, char *str2, int slen2, protect_out_of_mem(slen1 + slen2); /* Make positional trigrams */ - trg1 = (trgm *) palloc(sizeof(trgm) * (slen1 / 2 + 1) * 3); - trg2 = (trgm *) palloc(sizeof(trgm) * (slen2 / 2 + 1) * 3); + trg1 = (trgm *) palloc(sizeof(trgm) * (slen1 / 2 + 1) *3); + trg2 = (trgm *) palloc(sizeof(trgm) * (slen2 / 2 + 1) *3); len1 = generate_trgm_only(trg1, str1, slen1); len2 = generate_trgm_only(trg2, str2, slen2); @@ -594,7 +598,8 @@ calc_word_similarity(char *str1, int slen1, char *str2, int slen2, { if (i > 0) { - int cmp = CMPTRGM(ptrg[i - 1].trg, ptrg[i].trg); + int cmp = CMPTRGM(ptrg[i - 1].trg, ptrg[i].trg); + if (cmp != 0) { if (found[j]) @@ -617,7 +622,7 @@ calc_word_similarity(char *str1, int slen1, char *str2, int slen2, /* Run iterative procedure to find maximum similarity with word */ result = iterate_word_similarity(trg2indexes, found, ulen1, len2, len, - check_only); + check_only); pfree(trg2indexes); pfree(found); @@ -1075,8 +1080,8 @@ word_similarity(PG_FUNCTION_ARGS) float4 res; res = calc_word_similarity(VARDATA_ANY(in1), VARSIZE_ANY_EXHDR(in1), - VARDATA_ANY(in2), VARSIZE_ANY_EXHDR(in2), - false); + VARDATA_ANY(in2), VARSIZE_ANY_EXHDR(in2), + false); PG_FREE_IF_COPY(in1, 0); PG_FREE_IF_COPY(in2, 1); @@ -1111,8 +1116,8 @@ word_similarity_op(PG_FUNCTION_ARGS) float4 res; res = calc_word_similarity(VARDATA_ANY(in1), VARSIZE_ANY_EXHDR(in1), - VARDATA_ANY(in2), VARSIZE_ANY_EXHDR(in2), - true); + VARDATA_ANY(in2), VARSIZE_ANY_EXHDR(in2), + true); PG_FREE_IF_COPY(in1, 0); PG_FREE_IF_COPY(in2, 1); @@ -1127,8 +1132,8 @@ word_similarity_commutator_op(PG_FUNCTION_ARGS) float4 res; res = calc_word_similarity(VARDATA_ANY(in2), VARSIZE_ANY_EXHDR(in2), - VARDATA_ANY(in1), VARSIZE_ANY_EXHDR(in1), - true); + VARDATA_ANY(in1), VARSIZE_ANY_EXHDR(in1), + true); PG_FREE_IF_COPY(in1, 0); PG_FREE_IF_COPY(in2, 1); @@ -1143,8 +1148,8 @@ word_similarity_dist_op(PG_FUNCTION_ARGS) float4 res; res = calc_word_similarity(VARDATA_ANY(in1), VARSIZE_ANY_EXHDR(in1), - VARDATA_ANY(in2), VARSIZE_ANY_EXHDR(in2), - false); + VARDATA_ANY(in2), VARSIZE_ANY_EXHDR(in2), + false); PG_FREE_IF_COPY(in1, 0); PG_FREE_IF_COPY(in2, 1); @@ -1159,8 +1164,8 @@ word_similarity_dist_commutator_op(PG_FUNCTION_ARGS) float4 res; res = calc_word_similarity(VARDATA_ANY(in2), VARSIZE_ANY_EXHDR(in2), - VARDATA_ANY(in1), VARSIZE_ANY_EXHDR(in1), - false); + VARDATA_ANY(in1), VARSIZE_ANY_EXHDR(in1), + false); PG_FREE_IF_COPY(in1, 0); PG_FREE_IF_COPY(in2, 1); |
