aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/tsvector_op.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2009-06-11 14:49:15 +0000
committerBruce Momjian <bruce@momjian.us>2009-06-11 14:49:15 +0000
commitd7471402794266078953f1bd113dab4913d631a1 (patch)
tree618e392a84eaf837e00bf78f8694097b78fec227 /src/backend/utils/adt/tsvector_op.c
parent4e86efb4e51b66ef57b3fe6f28576de23a1bf1c6 (diff)
downloadpostgresql-d7471402794266078953f1bd113dab4913d631a1.tar.gz
postgresql-d7471402794266078953f1bd113dab4913d631a1.zip
8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list
provided by Andrew.
Diffstat (limited to 'src/backend/utils/adt/tsvector_op.c')
-rw-r--r--src/backend/utils/adt/tsvector_op.c141
1 files changed, 71 insertions, 70 deletions
diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c
index e7bce9a707b..093f2a348ad 100644
--- a/src/backend/utils/adt/tsvector_op.c
+++ b/src/backend/utils/adt/tsvector_op.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.22 2009/05/27 19:41:58 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.23 2009/06/11 14:49:04 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -38,8 +38,8 @@ typedef struct
typedef struct StatEntry
{
- uint32 ndoc; /* zero indicates that we already was here while
- walking throug the tree */
+ uint32 ndoc; /* zero indicates that we already was here
+ * while walking throug the tree */
uint32 nentry;
struct StatEntry *left;
struct StatEntry *right;
@@ -54,11 +54,11 @@ typedef struct
int4 weight;
uint32 maxdepth;
-
- StatEntry **stack;
+
+ StatEntry **stack;
uint32 stackpos;
- StatEntry* root;
+ StatEntry *root;
} TSVectorStat;
#define STATHDRSIZE (offsetof(TSVectorStat, data))
@@ -127,7 +127,7 @@ silly_cmp_tsvector(const TSVector a, const TSVector b)
{
return (aptr->haspos > bptr->haspos) ? -1 : 1;
}
- else if ( (res=tsCompareString( STRPTR(a) + aptr->pos, aptr->len, STRPTR(b) + bptr->pos, bptr->len, false)) !=0 )
+ else if ((res = tsCompareString(STRPTR(a) + aptr->pos, aptr->len, STRPTR(b) + bptr->pos, bptr->len, false)) != 0)
{
return res;
}
@@ -172,7 +172,7 @@ tsvector_##type(PG_FUNCTION_ARGS) \
PG_FREE_IF_COPY(a,0); \
PG_FREE_IF_COPY(b,1); \
PG_RETURN_##ret( res action 0 ); \
-} \
+} \
/* keep compiler quiet - no extra ; */ \
extern int no_such_variable
@@ -524,40 +524,41 @@ tsvector_concat(PG_FUNCTION_ARGS)
}
/*
- * Compare two strings by tsvector rules.
+ * Compare two strings by tsvector rules.
* if isPrefix = true then it returns not-zero value if b has prefix a
*/
int4
tsCompareString(char *a, int lena, char *b, int lenb, bool prefix)
{
- int cmp;
+ int cmp;
- if ( lena == 0 )
+ if (lena == 0)
{
- if ( prefix )
- cmp = 0; /* emtry string is equal to any if a prefix match */
+ if (prefix)
+ cmp = 0; /* emtry string is equal to any if a prefix
+ * match */
else
- cmp = (lenb>0) ? -1 : 0;
+ cmp = (lenb > 0) ? -1 : 0;
}
- else if ( lenb == 0 )
+ else if (lenb == 0)
{
- cmp = (lena>0) ? 1 : 0;
+ cmp = (lena > 0) ? 1 : 0;
}
else
{
cmp = memcmp(a, b, Min(lena, lenb));
- if ( prefix )
+ if (prefix)
{
- if ( cmp == 0 && lena > lenb )
+ if (cmp == 0 && lena > lenb)
{
/*
* b argument is not beginning with argument a
*/
- cmp=1;
+ cmp = 1;
}
}
- else if ( (cmp == 0) && (lena != lenb) )
+ else if ((cmp == 0) && (lena != lenb))
{
cmp = (lena < lenb) ? -1 : 1;
}
@@ -601,16 +602,16 @@ checkcondition_str(void *checkval, QueryOperand *val)
WordEntry *StopLow = chkval->arrb;
WordEntry *StopHigh = chkval->arre;
WordEntry *StopMiddle = StopHigh;
- int difference = -1;
- bool res=false;
+ int difference = -1;
+ bool res = false;
/* Loop invariant: StopLow <= val < StopHigh */
while (StopLow < StopHigh)
{
StopMiddle = StopLow + (StopHigh - StopLow) / 2;
- difference = tsCompareString( chkval->operand + val->distance, val->length,
- chkval->values + StopMiddle->pos, StopMiddle->len,
- false);
+ difference = tsCompareString(chkval->operand + val->distance, val->length,
+ chkval->values + StopMiddle->pos, StopMiddle->len,
+ false);
if (difference == 0)
{
@@ -624,19 +625,19 @@ checkcondition_str(void *checkval, QueryOperand *val)
StopHigh = StopMiddle;
}
- if ( res == false && val->prefix == true )
+ if (res == false && val->prefix == true)
{
/*
* there was a failed exact search, so we should scan further to find
* a prefix match.
*/
- if ( StopLow >= StopHigh )
+ if (StopLow >= StopHigh)
StopMiddle = StopHigh;
- while( res == false && StopMiddle < chkval->arre &&
- tsCompareString( chkval->operand + val->distance, val->length,
- chkval->values + StopMiddle->pos, StopMiddle->len,
- true) == 0 )
+ while (res == false && StopMiddle < chkval->arre &&
+ tsCompareString(chkval->operand + val->distance, val->length,
+ chkval->values + StopMiddle->pos, StopMiddle->len,
+ true) == 0)
{
res = (val->weight && StopMiddle->haspos) ?
checkclass_str(chkval, StopMiddle, val) : true;
@@ -645,7 +646,7 @@ checkcondition_str(void *checkval, QueryOperand *val)
}
}
- return res;
+ return res;
}
/*
@@ -803,7 +804,7 @@ check_weight(TSVector txt, WordEntry *wptr, int8 weight)
return num;
}
-#define compareStatWord(a,e,t) \
+#define compareStatWord(a,e,t) \
tsCompareString((a)->lexeme, (a)->lenlexeme, \
STRPTR(t) + (e)->pos, (e)->len, \
false)
@@ -811,22 +812,22 @@ check_weight(TSVector txt, WordEntry *wptr, int8 weight)
static void
insertStatEntry(MemoryContext persistentContext, TSVectorStat *stat, TSVector txt, uint32 off)
{
- WordEntry *we = ARRPTR(txt) + off;
- StatEntry *node = stat->root,
- *pnode=NULL;
+ WordEntry *we = ARRPTR(txt) + off;
+ StatEntry *node = stat->root,
+ *pnode = NULL;
int n,
res = 0;
- uint32 depth=1;
+ uint32 depth = 1;
- if (stat->weight == 0)
+ if (stat->weight == 0)
n = (we->haspos) ? POSDATALEN(txt, we) : 1;
else
n = (we->haspos) ? check_weight(txt, we, stat->weight) : 0;
- if ( n == 0 )
- return; /* nothing to insert */
+ if (n == 0)
+ return; /* nothing to insert */
- while( node )
+ while (node)
{
res = compareStatWord(node, we, txt);
@@ -837,7 +838,7 @@ insertStatEntry(MemoryContext persistentContext, TSVectorStat *stat, TSVector tx
else
{
pnode = node;
- node = ( res < 0 ) ? node->left : node->right;
+ node = (res < 0) ? node->left : node->right;
}
depth++;
}
@@ -847,14 +848,14 @@ insertStatEntry(MemoryContext persistentContext, TSVectorStat *stat, TSVector tx
if (node == NULL)
{
- node = MemoryContextAlloc(persistentContext, STATENTRYHDRSZ + we->len );
+ node = MemoryContextAlloc(persistentContext, STATENTRYHDRSZ + we->len);
node->left = node->right = NULL;
node->ndoc = 1;
node->nentry = n;
node->lenlexeme = we->len;
memcpy(node->lexeme, STRPTR(txt) + we->pos, node->lenlexeme);
- if ( pnode==NULL )
+ if (pnode == NULL)
{
stat->root = node;
}
@@ -865,7 +866,7 @@ insertStatEntry(MemoryContext persistentContext, TSVectorStat *stat, TSVector tx
else
pnode->right = node;
}
-
+
}
else
{
@@ -875,18 +876,18 @@ insertStatEntry(MemoryContext persistentContext, TSVectorStat *stat, TSVector tx
}
static void
-chooseNextStatEntry(MemoryContext persistentContext, TSVectorStat *stat, TSVector txt,
- uint32 low, uint32 high, uint32 offset)
+chooseNextStatEntry(MemoryContext persistentContext, TSVectorStat *stat, TSVector txt,
+ uint32 low, uint32 high, uint32 offset)
{
- uint32 pos;
- uint32 middle = (low + high) >> 1;
+ uint32 pos;
+ uint32 middle = (low + high) >> 1;
pos = (low + middle) >> 1;
if (low != middle && pos >= offset && pos - offset < txt->size)
- insertStatEntry( persistentContext, stat, txt, pos - offset );
+ insertStatEntry(persistentContext, stat, txt, pos - offset);
pos = (high + middle + 1) >> 1;
if (middle + 1 != high && pos >= offset && pos - offset < txt->size)
- insertStatEntry( persistentContext, stat, txt, pos - offset );
+ insertStatEntry(persistentContext, stat, txt, pos - offset);
if (low != middle)
chooseNextStatEntry(persistentContext, stat, txt, low, middle, offset);
@@ -909,13 +910,13 @@ chooseNextStatEntry(MemoryContext persistentContext, TSVectorStat *stat, TSVecto
static TSVectorStat *
ts_accum(MemoryContext persistentContext, TSVectorStat *stat, Datum data)
{
- TSVector txt = DatumGetTSVector(data);
- uint32 i,
- nbit = 0,
- offset;
+ TSVector txt = DatumGetTSVector(data);
+ uint32 i,
+ nbit = 0,
+ offset;
if (stat == NULL)
- { /* Init in first */
+ { /* Init in first */
stat = MemoryContextAllocZero(persistentContext, sizeof(TSVectorStat));
stat->maxdepth = 1;
}
@@ -935,7 +936,7 @@ ts_accum(MemoryContext persistentContext, TSVectorStat *stat, Datum data)
nbit = 1 << nbit;
offset = (nbit - txt->size) / 2;
- insertStatEntry( persistentContext, stat, txt, (nbit >> 1) - offset );
+ insertStatEntry(persistentContext, stat, txt, (nbit >> 1) - offset);
chooseNextStatEntry(persistentContext, stat, txt, 0, nbit, offset);
return stat;
@@ -945,22 +946,22 @@ static void
ts_setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx,
TSVectorStat *stat)
{
- TupleDesc tupdesc;
- MemoryContext oldcontext;
- StatEntry *node;
+ TupleDesc tupdesc;
+ MemoryContext oldcontext;
+ StatEntry *node;
funcctx->user_fctx = (void *) stat;
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
stat->stack = palloc0(sizeof(StatEntry *) * (stat->maxdepth + 1));
- stat->stackpos = 0;
+ stat->stackpos = 0;
node = stat->root;
/* find leftmost value */
for (;;)
{
- stat->stack[ stat->stackpos ] = node;
+ stat->stack[stat->stackpos] = node;
if (node->left)
{
stat->stackpos++;
@@ -984,14 +985,14 @@ ts_setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx,
}
static StatEntry *
-walkStatEntryTree(TSVectorStat *stat)
+walkStatEntryTree(TSVectorStat *stat)
{
- StatEntry *node = stat->stack[ stat->stackpos ];
+ StatEntry *node = stat->stack[stat->stackpos];
- if ( node == NULL )
+ if (node == NULL)
return NULL;
- if ( node->ndoc != 0 )
+ if (node->ndoc != 0)
{
/* return entry itself: we already was at left sublink */
return node;
@@ -1031,8 +1032,8 @@ walkStatEntryTree(TSVectorStat *stat)
static Datum
ts_process_call(FuncCallContext *funcctx)
{
- TSVectorStat *st;
- StatEntry *entry;
+ TSVectorStat *st;
+ StatEntry *entry;
st = (TSVectorStat *) funcctx->user_fctx;
@@ -1164,7 +1165,7 @@ ts_stat1(PG_FUNCTION_ARGS)
if (SRF_IS_FIRSTCALL())
{
- TSVectorStat *stat;
+ TSVectorStat *stat;
text *txt = PG_GETARG_TEXT_P(0);
funcctx = SRF_FIRSTCALL_INIT();
@@ -1189,7 +1190,7 @@ ts_stat2(PG_FUNCTION_ARGS)
if (SRF_IS_FIRSTCALL())
{
- TSVectorStat *stat;
+ TSVectorStat *stat;
text *txt = PG_GETARG_TEXT_P(0);
text *ws = PG_GETARG_TEXT_P(1);