Commit e50f52a0 authored by Bruce Momjian's avatar Bruce Momjian

pgindent run.

parent c91ceec2
...@@ -299,6 +299,7 @@ gts_compress(PG_FUNCTION_ARGS) ...@@ -299,6 +299,7 @@ gts_compress(PG_FUNCTION_ARGS)
if (entry->leafkey) if (entry->leafkey)
{ {
TSKEY *r = (TSKEY *) palloc(sizeof(TSKEY)); TSKEY *r = (TSKEY *) palloc(sizeof(TSKEY));
retval = palloc(sizeof(GISTENTRY)); retval = palloc(sizeof(GISTENTRY));
r->lower = r->upper = *(Timestamp *) (entry->key); r->lower = r->upper = *(Timestamp *) (entry->key);
gistentryinit(*retval, PointerGetDatum(r), gistentryinit(*retval, PointerGetDatum(r),
......
...@@ -73,11 +73,11 @@ bool cube_right(NDBOX * a, NDBOX * b); ...@@ -73,11 +73,11 @@ bool cube_right(NDBOX * a, NDBOX * b);
bool cube_lt(NDBOX * a, NDBOX * b); bool cube_lt(NDBOX * a, NDBOX * b);
bool cube_gt(NDBOX * a, NDBOX * b); bool cube_gt(NDBOX * a, NDBOX * b);
double *cube_distance(NDBOX * a, NDBOX * b); double *cube_distance(NDBOX * a, NDBOX * b);
int cube_dim(NDBOX *a); int cube_dim(NDBOX * a);
double *cube_ll_coord(NDBOX * a, int n); double *cube_ll_coord(NDBOX * a, int n);
double *cube_ur_coord(NDBOX * a, int n); double *cube_ur_coord(NDBOX * a, int n);
bool cube_is_point(NDBOX * a); bool cube_is_point(NDBOX * a);
NDBOX *cube_enlarge(NDBOX * a, double * r, int n); NDBOX *cube_enlarge(NDBOX * a, double *r, int n);
/* /*
...@@ -115,7 +115,7 @@ cube(text *str) ...@@ -115,7 +115,7 @@ cube(text *str)
} }
char * char *
cube_out(NDBOX *cube) cube_out(NDBOX * cube)
{ {
StringInfoData buf; StringInfoData buf;
bool equal = true; bool equal = true;
...@@ -792,6 +792,7 @@ cube_lt(NDBOX * a, NDBOX * b) ...@@ -792,6 +792,7 @@ cube_lt(NDBOX * a, NDBOX * b)
if (max(a->x[i], a->x[a->dim + i]) < 0) if (max(a->x[i], a->x[a->dim + i]) < 0)
return (TRUE); return (TRUE);
} }
/* /*
* if all common dimensions are equal, the cube with more * if all common dimensions are equal, the cube with more
* dimensions wins * dimensions wins
...@@ -814,6 +815,7 @@ cube_lt(NDBOX * a, NDBOX * b) ...@@ -814,6 +815,7 @@ cube_lt(NDBOX * a, NDBOX * b)
if (max(b->x[i], b->x[b->dim + i]) < 0) if (max(b->x[i], b->x[b->dim + i]) < 0)
return (FALSE); return (FALSE);
} }
/* /*
* if all common dimensions are equal, the cube with more * if all common dimensions are equal, the cube with more
* dimensions wins * dimensions wins
...@@ -874,6 +876,7 @@ cube_gt(NDBOX * a, NDBOX * b) ...@@ -874,6 +876,7 @@ cube_gt(NDBOX * a, NDBOX * b)
if (max(a->x[i], a->x[a->dim + i]) > 0) if (max(a->x[i], a->x[a->dim + i]) > 0)
return (TRUE); return (TRUE);
} }
/* /*
* if all common dimensions are equal, the cube with more * if all common dimensions are equal, the cube with more
* dimensions wins * dimensions wins
...@@ -896,6 +899,7 @@ cube_gt(NDBOX * a, NDBOX * b) ...@@ -896,6 +899,7 @@ cube_gt(NDBOX * a, NDBOX * b)
if (max(b->x[i], b->x[b->dim + i]) > 0) if (max(b->x[i], b->x[b->dim + i]) > 0)
return (FALSE); return (FALSE);
} }
/* /*
* if all common dimensions are equal, the cube with more * if all common dimensions are equal, the cube with more
* dimensions wins * dimensions wins
...@@ -937,9 +941,9 @@ cube_same(NDBOX * a, NDBOX * b) ...@@ -937,9 +941,9 @@ cube_same(NDBOX * a, NDBOX * b)
/* /*
* all dimensions of (b) are compared to those of (a); instead of * all dimensions of (b) are compared to those of (a); instead of
* those in (a) absent in (b), compare (a) to zero * those in (a) absent in (b), compare (a) to zero Since both LL and
* Since both LL and UR coordinates are compared to zero, we can * UR coordinates are compared to zero, we can just check them all
* just check them all without worrying about which is which. * without worrying about which is which.
*/ */
for (i = b->dim; i < a->dim; i++) for (i = b->dim; i < a->dim; i++)
{ {
...@@ -974,9 +978,9 @@ cube_contains(NDBOX * a, NDBOX * b) ...@@ -974,9 +978,9 @@ cube_contains(NDBOX * a, NDBOX * b)
{ {
/* /*
* the further comparisons will make sense if the excess * the further comparisons will make sense if the excess
* dimensions of (b) were zeroes * dimensions of (b) were zeroes Since both UL and UR coordinates
* Since both UL and UR coordinates must be zero, we can * must be zero, we can check them all without worrying about
* check them all without worrying about which is which. * which is which.
*/ */
for (i = a->dim; i < b->dim; i++) for (i = a->dim; i < b->dim; i++)
{ {
...@@ -1124,9 +1128,11 @@ cube_is_point(NDBOX * a) ...@@ -1124,9 +1128,11 @@ cube_is_point(NDBOX * a)
{ {
int i, int i,
j; j;
for (i = 0, j = a->dim; i < a->dim; i++, j++) for (i = 0, j = a->dim; i < a->dim; i++, j++)
{ {
if (a->x[i] != a->x[j]) return FALSE; if (a->x[i] != a->x[j])
return FALSE;
} }
return TRUE; return TRUE;
...@@ -1145,10 +1151,11 @@ double * ...@@ -1145,10 +1151,11 @@ double *
cube_ll_coord(NDBOX * a, int n) cube_ll_coord(NDBOX * a, int n)
{ {
double *result; double *result;
result = (double *) palloc(sizeof(double)); result = (double *) palloc(sizeof(double));
*result = 0; *result = 0;
if (a->dim >= n && n > 0) if (a->dim >= n && n > 0)
*result = min(a->x[n-1], a->x[a->dim + n-1]); *result = min(a->x[n - 1], a->x[a->dim + n - 1]);
return result; return result;
} }
...@@ -1157,24 +1164,28 @@ double * ...@@ -1157,24 +1164,28 @@ double *
cube_ur_coord(NDBOX * a, int n) cube_ur_coord(NDBOX * a, int n)
{ {
double *result; double *result;
result = (double *) palloc(sizeof(double)); result = (double *) palloc(sizeof(double));
*result = 0; *result = 0;
if (a->dim >= n && n > 0) if (a->dim >= n && n > 0)
*result = max(a->x[n-1], a->x[a->dim + n-1]); *result = max(a->x[n - 1], a->x[a->dim + n - 1]);
return result; return result;
} }
/* Increase or decrease box size by a radius in at least n dimensions. */ /* Increase or decrease box size by a radius in at least n dimensions. */
NDBOX * NDBOX *
cube_enlarge(NDBOX * a, double * r, int n) cube_enlarge(NDBOX * a, double *r, int n)
{ {
NDBOX *result; NDBOX *result;
int dim = 0; int dim = 0;
int size; int size;
int i, int i,
j; j;
if (*r > 0 && n > 0) dim = n;
if (a->dim > dim) dim = a->dim; if (*r > 0 && n > 0)
dim = n;
if (a->dim > dim)
dim = a->dim;
size = offsetof(NDBOX, x[0]) + sizeof(double) * dim * 2; size = offsetof(NDBOX, x[0]) + sizeof(double) * dim * 2;
result = (NDBOX *) palloc(size); result = (NDBOX *) palloc(size);
memset(result, 0, size); memset(result, 0, size);
......
This diff is collapsed.
This diff is collapsed.
...@@ -49,7 +49,7 @@ typedef struct ...@@ -49,7 +49,7 @@ typedef struct
int items; int items;
int lower; int lower;
int4 array[1]; int4 array[1];
}PGARRAY; } PGARRAY;
/* This is used to keep track of our position during enumeration */ /* This is used to keep track of our position during enumeration */
typedef struct callContext typedef struct callContext
...@@ -57,14 +57,14 @@ typedef struct callContext ...@@ -57,14 +57,14 @@ typedef struct callContext
PGARRAY *p; PGARRAY *p;
int num; int num;
int flags; int flags;
}CTX; } CTX;
#define TOASTED 1 #define TOASTED 1
#define START_NUM 8 #define START_NUM 8
#define PGARRAY_SIZE(n) (sizeof(PGARRAY) + ((n-1)*sizeof(int4))) #define PGARRAY_SIZE(n) (sizeof(PGARRAY) + ((n-1)*sizeof(int4)))
static PGARRAY * GetPGArray(int4 state, int fAdd); static PGARRAY *GetPGArray(int4 state, int fAdd);
static PGARRAY *ShrinkPGArray(PGARRAY *p); static PGARRAY *ShrinkPGArray(PGARRAY * p);
Datum int_agg_state(PG_FUNCTION_ARGS); Datum int_agg_state(PG_FUNCTION_ARGS);
Datum int_agg_final_count(PG_FUNCTION_ARGS); Datum int_agg_final_count(PG_FUNCTION_ARGS);
...@@ -80,20 +80,21 @@ PG_FUNCTION_INFO_V1(int_enum); ...@@ -80,20 +80,21 @@ PG_FUNCTION_INFO_V1(int_enum);
* Manage the aggregation state of the array * Manage the aggregation state of the array
* You need to specify the correct memory context, or it will vanish! * You need to specify the correct memory context, or it will vanish!
*/ */
static PGARRAY * GetPGArray(int4 state, int fAdd) static PGARRAY *
GetPGArray(int4 state, int fAdd)
{ {
PGARRAY *p = (PGARRAY *) state; PGARRAY *p = (PGARRAY *) state;
if(!state) if (!state)
{ {
/* New array */ /* New array */
int cb = PGARRAY_SIZE(START_NUM); int cb = PGARRAY_SIZE(START_NUM);
p = (PGARRAY *) MemoryContextAlloc(TopTransactionContext, cb); p = (PGARRAY *) MemoryContextAlloc(TopTransactionContext, cb);
if(!p) if (!p)
{ {
elog(ERROR,"Integer aggregator, cant allocate TopTransactionContext memory"); elog(ERROR, "Integer aggregator, cant allocate TopTransactionContext memory");
return 0; return 0;
} }
...@@ -104,11 +105,11 @@ static PGARRAY * GetPGArray(int4 state, int fAdd) ...@@ -104,11 +105,11 @@ static PGARRAY * GetPGArray(int4 state, int fAdd)
p->a.elemtype = INT4OID; p->a.elemtype = INT4OID;
#endif #endif
p->items = 0; p->items = 0;
p->lower= START_NUM; p->lower = START_NUM;
} }
else if(fAdd) else if (fAdd)
{ /* Ensure array has space */ { /* Ensure array has space */
if(p->items >= p->lower) if (p->items >= p->lower)
{ {
PGARRAY *pn; PGARRAY *pn;
int n = p->lower + p->lower; int n = p->lower + p->lower;
...@@ -116,10 +117,10 @@ static PGARRAY * GetPGArray(int4 state, int fAdd) ...@@ -116,10 +117,10 @@ static PGARRAY * GetPGArray(int4 state, int fAdd)
pn = (PGARRAY *) repalloc(p, cbNew); pn = (PGARRAY *) repalloc(p, cbNew);
if(!pn) if (!pn)
{ /* Realloc failed! Reallocate new block. */ { /* Realloc failed! Reallocate new block. */
pn = (PGARRAY *) MemoryContextAlloc(TopTransactionContext, cbNew); pn = (PGARRAY *) MemoryContextAlloc(TopTransactionContext, cbNew);
if(!pn) if (!pn)
{ {
elog(ERROR, "Integer aggregator, REALLY REALLY can't alloc memory"); elog(ERROR, "Integer aggregator, REALLY REALLY can't alloc memory");
return (PGARRAY *) NULL; return (PGARRAY *) NULL;
...@@ -137,10 +138,12 @@ static PGARRAY * GetPGArray(int4 state, int fAdd) ...@@ -137,10 +138,12 @@ static PGARRAY * GetPGArray(int4 state, int fAdd)
/* Shrinks the array to its actual size and moves it into the standard /* Shrinks the array to its actual size and moves it into the standard
* memory allocation context, frees working memory */ * memory allocation context, frees working memory */
static PGARRAY *ShrinkPGArray(PGARRAY *p) static PGARRAY *
ShrinkPGArray(PGARRAY * p)
{ {
PGARRAY *pnew=NULL; PGARRAY *pnew = NULL;
if(p)
if (p)
{ {
/* get target size */ /* get target size */
int cb = PGARRAY_SIZE(p->items); int cb = PGARRAY_SIZE(p->items);
...@@ -148,12 +151,15 @@ static PGARRAY *ShrinkPGArray(PGARRAY *p) ...@@ -148,12 +151,15 @@ static PGARRAY *ShrinkPGArray(PGARRAY *p)
/* use current transaction context */ /* use current transaction context */
pnew = palloc(cb); pnew = palloc(cb);
if(pnew) if (pnew)
{ {
/* Fix up the fields in the new structure, so Postgres understands */ /*
* Fix up the fields in the new structure, so Postgres
* understands
*/
memcpy(pnew, p, cb); memcpy(pnew, p, cb);
pnew->a.size = cb; pnew->a.size = cb;
pnew->a.ndim=1; pnew->a.ndim = 1;
pnew->a.flags = 0; pnew->a.flags = 0;
#ifndef PG_7_2 #ifndef PG_7_2
pnew->a.elemtype = INT4OID; pnew->a.elemtype = INT4OID;
...@@ -161,79 +167,72 @@ static PGARRAY *ShrinkPGArray(PGARRAY *p) ...@@ -161,79 +167,72 @@ static PGARRAY *ShrinkPGArray(PGARRAY *p)
pnew->lower = 0; pnew->lower = 0;
} }
else else
{
elog(ERROR, "Integer aggregator, can't allocate memory"); elog(ERROR, "Integer aggregator, can't allocate memory");
}
pfree(p); pfree(p);
} }
return pnew; return pnew;
} }
/* Called for each iteration during an aggregate function */ /* Called for each iteration during an aggregate function */
Datum int_agg_state(PG_FUNCTION_ARGS) Datum
int_agg_state(PG_FUNCTION_ARGS)
{ {
int4 state = PG_GETARG_INT32(0); int4 state = PG_GETARG_INT32(0);
int4 value = PG_GETARG_INT32(1); int4 value = PG_GETARG_INT32(1);
PGARRAY *p = GetPGArray(state, 1); PGARRAY *p = GetPGArray(state, 1);
if(!p)
{ if (!p)
elog(ERROR,"No aggregate storage"); elog(ERROR, "No aggregate storage");
} else if (p->items >= p->lower)
else if(p->items >= p->lower) elog(ERROR, "aggregate storage too small");
{
elog(ERROR,"aggregate storage too small");
}
else else
{ p->array[p->items++] = value;
p->array[p->items++]= value;
}
PG_RETURN_INT32(p); PG_RETURN_INT32(p);
} }
/* This is the final function used for the integer aggregator. It returns all the integers /* This is the final function used for the integer aggregator. It returns all the integers
* collected as a one dimentional integer array */ * collected as a one dimentional integer array */
Datum int_agg_final_array(PG_FUNCTION_ARGS) Datum
int_agg_final_array(PG_FUNCTION_ARGS)
{ {
PGARRAY *pnew = ShrinkPGArray(GetPGArray(PG_GETARG_INT32(0),0)); PGARRAY *pnew = ShrinkPGArray(GetPGArray(PG_GETARG_INT32(0), 0));
if(pnew)
{ if (pnew)
PG_RETURN_POINTER(pnew); PG_RETURN_POINTER(pnew);
}
else else
{
PG_RETURN_NULL(); PG_RETURN_NULL();
}
} }
/* This function accepts an array, and returns one item for each entry in the array */ /* This function accepts an array, and returns one item for each entry in the array */
Datum int_enum(PG_FUNCTION_ARGS) Datum
int_enum(PG_FUNCTION_ARGS)
{ {
PGARRAY *p = (PGARRAY *) PG_GETARG_POINTER(0); PGARRAY *p = (PGARRAY *) PG_GETARG_POINTER(0);
CTX *pc; CTX *pc;
ReturnSetInfo *rsi = (ReturnSetInfo *)fcinfo->resultinfo; ReturnSetInfo *rsi = (ReturnSetInfo *) fcinfo->resultinfo;
if (!rsi || !IsA(rsi, ReturnSetInfo)) if (!rsi || !IsA(rsi, ReturnSetInfo))
elog(ERROR, "No ReturnSetInfo sent! function must be declared returning a 'setof' integer"); elog(ERROR, "No ReturnSetInfo sent! function must be declared returning a 'setof' integer");
if(!p) if (!p)
{ {
elog(WARNING, "No data sent"); elog(WARNING, "No data sent");
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
if(!fcinfo->context) if (!fcinfo->context)
{ {
/* Allocate a working context */ /* Allocate a working context */
pc = (CTX *) palloc(sizeof(CTX)); pc = (CTX *) palloc(sizeof(CTX));
/* Don't copy atribute if you don't need too */ /* Don't copy atribute if you don't need too */
if(VARATT_IS_EXTENDED(p) ) if (VARATT_IS_EXTENDED(p))
{ {
/* Toasted!!! */ /* Toasted!!! */
pc->p = (PGARRAY *) PG_DETOAST_DATUM_COPY(p); pc->p = (PGARRAY *) PG_DETOAST_DATUM_COPY(p);
pc->flags = TOASTED; pc->flags = TOASTED;
if(!pc->p) if (!pc->p)
{ {
elog(ERROR, "Error in toaster!!! no detoasting"); elog(ERROR, "Error in toaster!!! no detoasting");
PG_RETURN_NULL(); PG_RETURN_NULL();
...@@ -246,25 +245,26 @@ Datum int_enum(PG_FUNCTION_ARGS) ...@@ -246,25 +245,26 @@ Datum int_enum(PG_FUNCTION_ARGS)
pc->flags = 0; pc->flags = 0;
} }
fcinfo->context = (Node *) pc; fcinfo->context = (Node *) pc;
pc->num=0; pc->num = 0;
} }
else /* use an existing one */ else
{ /* use an existing one */
pc = (CTX *) fcinfo->context; pc = (CTX *) fcinfo->context;
}
/* Are we done yet? */ /* Are we done yet? */
if(pc->num >= pc->p->items) if (pc->num >= pc->p->items)
{ {
/* We are done */ /* We are done */
if(pc->flags & TOASTED) if (pc->flags & TOASTED)
pfree(pc->p); pfree(pc->p);
pfree(fcinfo->context); pfree(fcinfo->context);
fcinfo->context = NULL; fcinfo->context = NULL;
rsi->isDone = ExprEndResult ; rsi->isDone = ExprEndResult;
} }
else /* nope, return the next value */ else
/* nope, return the next value */
{ {
int val = pc->p->array[pc->num++]; int val = pc->p->array[pc->num++];
rsi->isDone = ExprMultipleResult; rsi->isDone = ExprMultipleResult;
PG_RETURN_INT32(val); PG_RETURN_INT32(val);
} }
......
This diff is collapsed.
This diff is collapsed.
...@@ -31,24 +31,28 @@ Datum _ltxtq_extract_exec(PG_FUNCTION_ARGS); ...@@ -31,24 +31,28 @@ Datum _ltxtq_extract_exec(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(_lca); PG_FUNCTION_INFO_V1(_lca);
Datum _lca(PG_FUNCTION_ARGS); Datum _lca(PG_FUNCTION_ARGS);
typedef Datum (*PGCALL2)(PG_FUNCTION_ARGS); typedef Datum (*PGCALL2) (PG_FUNCTION_ARGS);
#define NEXTVAL(x) ( (ltree*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) ) #define NEXTVAL(x) ( (ltree*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) )
static bool static bool
array_iterator( ArrayType *la, PGCALL2 callback, void* param, ltree ** found) { array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree ** found)
int num=ArrayGetNItems( ARR_NDIM(la), ARR_DIMS(la)); {
ltree *item = (ltree*)ARR_DATA_PTR(la); int num = ArrayGetNItems(ARR_NDIM(la), ARR_DIMS(la));
ltree *item = (ltree *) ARR_DATA_PTR(la);
if ( ARR_NDIM(la) !=1 )
elog(ERROR,"Dimension of array != 1"); if (ARR_NDIM(la) != 1)
elog(ERROR, "Dimension of array != 1");
if ( found )
*found=NULL; if (found)
while( num>0 ) { *found = NULL;
if ( DatumGetBool( DirectFunctionCall2( callback, while (num > 0)
PointerGetDatum(item), PointerGetDatum(param) ) ) ) { {
if (DatumGetBool(DirectFunctionCall2(callback,
if ( found ) PointerGetDatum(item), PointerGetDatum(param))))
{
if (found)
*found = item; *found = item;
return true; return true;
} }
...@@ -60,179 +64,205 @@ array_iterator( ArrayType *la, PGCALL2 callback, void* param, ltree ** found) { ...@@ -60,179 +64,205 @@ array_iterator( ArrayType *la, PGCALL2 callback, void* param, ltree ** found) {
} }
Datum Datum
_ltree_isparent(PG_FUNCTION_ARGS) { _ltree_isparent(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
ltree *query = PG_GETARG_LTREE(1); ltree *query = PG_GETARG_LTREE(1);
bool res = array_iterator( la, ltree_isparent, (void*)query, NULL ); bool res = array_iterator(la, ltree_isparent, (void *) query, NULL);
PG_FREE_IF_COPY(la,0);
PG_FREE_IF_COPY(query,1); PG_FREE_IF_COPY(la, 0);
PG_FREE_IF_COPY(query, 1);
PG_RETURN_BOOL(res); PG_RETURN_BOOL(res);
} }
Datum Datum
_ltree_r_isparent(PG_FUNCTION_ARGS) { _ltree_r_isparent(PG_FUNCTION_ARGS)
PG_RETURN_DATUM( DirectFunctionCall2( _ltree_isparent, {
PG_RETURN_DATUM(DirectFunctionCall2(_ltree_isparent,
PG_GETARG_DATUM(1), PG_GETARG_DATUM(1),
PG_GETARG_DATUM(0) PG_GETARG_DATUM(0)
) ); ));
} }
Datum Datum
_ltree_risparent(PG_FUNCTION_ARGS) { _ltree_risparent(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
ltree *query = PG_GETARG_LTREE(1); ltree *query = PG_GETARG_LTREE(1);
bool res = array_iterator( la, ltree_risparent, (void*)query, NULL ); bool res = array_iterator(la, ltree_risparent, (void *) query, NULL);
PG_FREE_IF_COPY(la,0);
PG_FREE_IF_COPY(query,1); PG_FREE_IF_COPY(la, 0);
PG_FREE_IF_COPY(query, 1);
PG_RETURN_BOOL(res); PG_RETURN_BOOL(res);
} }
Datum Datum
_ltree_r_risparent(PG_FUNCTION_ARGS) { _ltree_r_risparent(PG_FUNCTION_ARGS)
PG_RETURN_DATUM( DirectFunctionCall2( _ltree_risparent, {
PG_RETURN_DATUM(DirectFunctionCall2(_ltree_risparent,
PG_GETARG_DATUM(1), PG_GETARG_DATUM(1),
PG_GETARG_DATUM(0) PG_GETARG_DATUM(0)
) ); ));
} }
Datum Datum
_ltq_regex(PG_FUNCTION_ARGS) { _ltq_regex(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
lquery *query = PG_GETARG_LQUERY(1); lquery *query = PG_GETARG_LQUERY(1);
bool res = array_iterator( la, ltq_regex, (void*)query, NULL ); bool res = array_iterator(la, ltq_regex, (void *) query, NULL);
PG_FREE_IF_COPY(la,0);
PG_FREE_IF_COPY(query,1); PG_FREE_IF_COPY(la, 0);
PG_FREE_IF_COPY(query, 1);
PG_RETURN_BOOL(res); PG_RETURN_BOOL(res);
} }
Datum Datum
_ltq_rregex(PG_FUNCTION_ARGS) { _ltq_rregex(PG_FUNCTION_ARGS)
PG_RETURN_DATUM( DirectFunctionCall2( _ltq_regex, {
PG_RETURN_DATUM(DirectFunctionCall2(_ltq_regex,
PG_GETARG_DATUM(1), PG_GETARG_DATUM(1),
PG_GETARG_DATUM(0) PG_GETARG_DATUM(0)
) ); ));
} }
Datum Datum
_ltxtq_exec(PG_FUNCTION_ARGS) { _ltxtq_exec(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
ltxtquery *query = PG_GETARG_LTXTQUERY(1); ltxtquery *query = PG_GETARG_LTXTQUERY(1);
bool res = array_iterator( la, ltxtq_exec, (void*)query, NULL ); bool res = array_iterator(la, ltxtq_exec, (void *) query, NULL);
PG_FREE_IF_COPY(la,0);
PG_FREE_IF_COPY(query,1); PG_FREE_IF_COPY(la, 0);
PG_FREE_IF_COPY(query, 1);
PG_RETURN_BOOL(res); PG_RETURN_BOOL(res);
} }
Datum Datum
_ltxtq_rexec(PG_FUNCTION_ARGS) { _ltxtq_rexec(PG_FUNCTION_ARGS)
PG_RETURN_DATUM( DirectFunctionCall2( _ltxtq_exec, {
PG_RETURN_DATUM(DirectFunctionCall2(_ltxtq_exec,
PG_GETARG_DATUM(1), PG_GETARG_DATUM(1),
PG_GETARG_DATUM(0) PG_GETARG_DATUM(0)
) ); ));
} }
Datum Datum
_ltree_extract_isparent(PG_FUNCTION_ARGS) { _ltree_extract_isparent(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
ltree *query = PG_GETARG_LTREE(1); ltree *query = PG_GETARG_LTREE(1);
ltree *found,*item; ltree *found,
*item;
if ( !array_iterator( la, ltree_isparent, (void*)query, &found ) ) { if (!array_iterator(la, ltree_isparent, (void *) query, &found))
PG_FREE_IF_COPY(la,0); {
PG_FREE_IF_COPY(query,1); PG_FREE_IF_COPY(la, 0);
PG_FREE_IF_COPY(query, 1);
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
item = (ltree*)palloc( found->len ); item = (ltree *) palloc(found->len);
memcpy( item, found, found->len ); memcpy(item, found, found->len);
PG_FREE_IF_COPY(la,0); PG_FREE_IF_COPY(la, 0);
PG_FREE_IF_COPY(query,1); PG_FREE_IF_COPY(query, 1);
PG_RETURN_POINTER(item); PG_RETURN_POINTER(item);
} }
Datum Datum
_ltree_extract_risparent(PG_FUNCTION_ARGS) { _ltree_extract_risparent(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
ltree *query = PG_GETARG_LTREE(1); ltree *query = PG_GETARG_LTREE(1);
ltree *found,*item; ltree *found,
*item;
if ( !array_iterator( la, ltree_risparent, (void*)query, &found ) ) { if (!array_iterator(la, ltree_risparent, (void *) query, &found))
PG_FREE_IF_COPY(la,0); {
PG_FREE_IF_COPY(query,1); PG_FREE_IF_COPY(la, 0);
PG_FREE_IF_COPY(query, 1);
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
item = (ltree*)palloc( found->len ); item = (ltree *) palloc(found->len);
memcpy( item, found, found->len ); memcpy(item, found, found->len);
PG_FREE_IF_COPY(la,0); PG_FREE_IF_COPY(la, 0);
PG_FREE_IF_COPY(query,1); PG_FREE_IF_COPY(query, 1);
PG_RETURN_POINTER(item); PG_RETURN_POINTER(item);
} }
Datum Datum
_ltq_extract_regex(PG_FUNCTION_ARGS) { _ltq_extract_regex(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
lquery *query = PG_GETARG_LQUERY(1); lquery *query = PG_GETARG_LQUERY(1);
ltree *found,*item; ltree *found,
*item;
if ( !array_iterator( la, ltq_regex, (void*)query, &found ) ) { if (!array_iterator(la, ltq_regex, (void *) query, &found))
PG_FREE_IF_COPY(la,0); {
PG_FREE_IF_COPY(query,1); PG_FREE_IF_COPY(la, 0);
PG_FREE_IF_COPY(query, 1);
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
item = (ltree*)palloc( found->len ); item = (ltree *) palloc(found->len);
memcpy( item, found, found->len ); memcpy(item, found, found->len);
PG_FREE_IF_COPY(la,0); PG_FREE_IF_COPY(la, 0);
PG_FREE_IF_COPY(query,1); PG_FREE_IF_COPY(query, 1);
PG_RETURN_POINTER(item); PG_RETURN_POINTER(item);
} }
Datum Datum
_ltxtq_extract_exec(PG_FUNCTION_ARGS) { _ltxtq_extract_exec(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
ltxtquery *query = PG_GETARG_LTXTQUERY(1); ltxtquery *query = PG_GETARG_LTXTQUERY(1);
ltree *found,*item; ltree *found,
*item;
if ( !array_iterator( la, ltxtq_exec, (void*)query, &found ) ) { if (!array_iterator(la, ltxtq_exec, (void *) query, &found))
PG_FREE_IF_COPY(la,0); {
PG_FREE_IF_COPY(query,1); PG_FREE_IF_COPY(la, 0);
PG_FREE_IF_COPY(query, 1);
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
item = (ltree*)palloc( found->len ); item = (ltree *) palloc(found->len);
memcpy( item, found, found->len ); memcpy(item, found, found->len);
PG_FREE_IF_COPY(la,0); PG_FREE_IF_COPY(la, 0);
PG_FREE_IF_COPY(query,1); PG_FREE_IF_COPY(query, 1);
PG_RETURN_POINTER(item); PG_RETURN_POINTER(item);
} }
Datum Datum
_lca(PG_FUNCTION_ARGS) { _lca(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
int num=ArrayGetNItems( ARR_NDIM(la), ARR_DIMS(la)); int num = ArrayGetNItems(ARR_NDIM(la), ARR_DIMS(la));
ltree *item = (ltree*)ARR_DATA_PTR(la); ltree *item = (ltree *) ARR_DATA_PTR(la);
ltree **a,*res; ltree **a,
*res;
a=(ltree**)palloc( sizeof(ltree*) * num );
while( num>0 ) { a = (ltree **) palloc(sizeof(ltree *) * num);
while (num > 0)
{
num--; num--;
a[num] = item; a[num] = item;
item = NEXTVAL(item); item = NEXTVAL(item);
} }
res = lca_inner(a, ArrayGetNItems( ARR_NDIM(la), ARR_DIMS(la))); res = lca_inner(a, ArrayGetNItems(ARR_NDIM(la), ARR_DIMS(la)));
pfree(a); pfree(a);
PG_FREE_IF_COPY(la,0); PG_FREE_IF_COPY(la, 0);
if ( res ) if (res)
PG_RETURN_POINTER(res); PG_RETURN_POINTER(res);
else else
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
...@@ -105,6 +105,6 @@ ltree_crc32_sz(char *buf, int size) ...@@ -105,6 +105,6 @@ ltree_crc32_sz(char *buf, int size)
len = 0; len = 0;
nr = size; nr = size;
for (len += nr, p = buf; nr--; ++p) for (len += nr, p = buf; nr--; ++p)
_CRC32_(crc, TOLOWER((unsigned int)*p)); _CRC32_(crc, TOLOWER((unsigned int) *p));
return ~crc; return ~crc;
} }
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
PG_FUNCTION_INFO_V1(ltq_regex); PG_FUNCTION_INFO_V1(ltq_regex);
PG_FUNCTION_INFO_V1(ltq_rregex); PG_FUNCTION_INFO_V1(ltq_rregex);
typedef struct { typedef struct
{
lquery_level *q; lquery_level *q;
int nq; int nq;
ltree_level *t; ltree_level *t;
...@@ -19,17 +20,18 @@ typedef struct { ...@@ -19,17 +20,18 @@ typedef struct {
} FieldNot; } FieldNot;
static char * static char *
getlexem(char *start, char *end, int *len) { getlexem(char *start, char *end, int *len)
{
char *ptr; char *ptr;
while( start<end && *start == '_' ) while (start < end && *start == '_')
start++; start++;
ptr = start; ptr = start;
if ( ptr == end ) if (ptr == end)
return NULL; return NULL;
while( ptr < end && *ptr != '_') while (ptr < end && *ptr != '_')
ptr++; ptr++;
*len = ptr - start; *len = ptr - start;
...@@ -37,23 +39,28 @@ getlexem(char *start, char *end, int *len) { ...@@ -37,23 +39,28 @@ getlexem(char *start, char *end, int *len) {
} }
bool bool
compare_subnode( ltree_level *t, char *qn, int len, int (*cmpptr)(const char *,const char *,size_t), bool anyend ) { compare_subnode(ltree_level * t, char *qn, int len, int (*cmpptr) (const char *, const char *, size_t), bool anyend)
{
char *endt = t->name + t->len; char *endt = t->name + t->len;
char *endq = qn + len; char *endq = qn + len;
char *tn; char *tn;
int lent,lenq; int lent,
lenq;
bool isok; bool isok;
while( (qn=getlexem(qn,endq,&lenq)) != NULL ) { while ((qn = getlexem(qn, endq, &lenq)) != NULL)
tn=t->name; {
tn = t->name;
isok = false; isok = false;
while( (tn=getlexem(tn,endt,&lent)) != NULL ) { while ((tn = getlexem(tn, endt, &lent)) != NULL)
{
if ( if (
( (
lent == lenq || lent == lenq ||
( lent > lenq && anyend ) (lent > lenq && anyend)
) && ) &&
(*cmpptr)(qn,tn,lenq) == 0 ) { (*cmpptr) (qn, tn, lenq) == 0)
{
isok = true; isok = true;
break; break;
...@@ -61,7 +68,7 @@ compare_subnode( ltree_level *t, char *qn, int len, int (*cmpptr)(const char *,c ...@@ -61,7 +68,7 @@ compare_subnode( ltree_level *t, char *qn, int len, int (*cmpptr)(const char *,c
tn += lent; tn += lent;
} }
if ( !isok ) if (!isok)
return false; return false;
qn += lenq; qn += lenq;
} }
...@@ -70,23 +77,28 @@ compare_subnode( ltree_level *t, char *qn, int len, int (*cmpptr)(const char *,c ...@@ -70,23 +77,28 @@ compare_subnode( ltree_level *t, char *qn, int len, int (*cmpptr)(const char *,c
} }
static bool static bool
checkLevel( lquery_level *curq, ltree_level *curt ) { checkLevel(lquery_level * curq, ltree_level * curt)
int (*cmpptr)(const char *,const char *,size_t); {
int (*cmpptr) (const char *, const char *, size_t);
lquery_variant *curvar = LQL_FIRST(curq); lquery_variant *curvar = LQL_FIRST(curq);
int i; int i;
for(i=0;i<curq->numvar;i++) { for (i = 0; i < curq->numvar; i++)
cmpptr = ( curvar->flag & LVAR_INCASE ) ? strncasecmp : strncmp; {
cmpptr = (curvar->flag & LVAR_INCASE) ? strncasecmp : strncmp;
if ( curvar->flag & LVAR_SUBLEXEM ) { if (curvar->flag & LVAR_SUBLEXEM)
if ( compare_subnode(curt, curvar->name, curvar->len, cmpptr, (curvar->flag & LVAR_ANYEND) ) ) {
if (compare_subnode(curt, curvar->name, curvar->len, cmpptr, (curvar->flag & LVAR_ANYEND)))
return true; return true;
} else if ( }
else if (
( (
curvar->len == curt->len || curvar->len == curt->len ||
( curt->len > curvar->len && (curvar->flag & LVAR_ANYEND) ) (curt->len > curvar->len && (curvar->flag & LVAR_ANYEND))
) && ) &&
(*cmpptr)( curvar->name, curt->name, curvar->len) == 0 ) { (*cmpptr) (curvar->name, curt->name, curvar->len) == 0)
{
return true; return true;
} }
...@@ -106,74 +118,93 @@ printFieldNot(FieldNot *fn ) { ...@@ -106,74 +118,93 @@ printFieldNot(FieldNot *fn ) {
*/ */
static bool static bool
checkCond( lquery_level *curq, int query_numlevel, ltree_level *curt, int tree_numlevel, FieldNot *ptr ) { checkCond(lquery_level * curq, int query_numlevel, ltree_level * curt, int tree_numlevel, FieldNot * ptr)
uint32 low_pos=0,high_pos=0,cur_tpos=0; {
int tlen = tree_numlevel, qlen = query_numlevel; uint32 low_pos = 0,
high_pos = 0,
cur_tpos = 0;
int tlen = tree_numlevel,
qlen = query_numlevel;
int isok; int isok;
lquery_level *prevq=NULL; lquery_level *prevq = NULL;
ltree_level *prevt=NULL; ltree_level *prevt = NULL;
while( tlen >0 && qlen>0 ) { while (tlen > 0 && qlen > 0)
if ( curq->numvar ) { {
if (curq->numvar)
{
prevt = curt; prevt = curt;
while ( cur_tpos < low_pos ) { while (cur_tpos < low_pos)
{
curt = LEVEL_NEXT(curt); curt = LEVEL_NEXT(curt);
tlen--; tlen--;
cur_tpos++; cur_tpos++;
if ( tlen==0 ) if (tlen == 0)
return false; return false;
if ( ptr && ptr->q ) if (ptr && ptr->q)
ptr->nt++; ptr->nt++;
} }
if ( ptr && curq->flag & LQL_NOT ) { if (ptr && curq->flag & LQL_NOT)
if ( !(prevq && prevq->numvar == 0) ) {
if (!(prevq && prevq->numvar == 0))
prevq = curq; prevq = curq;
if ( ptr->q == NULL ) { if (ptr->q == NULL)
{
ptr->t = prevt; ptr->t = prevt;
ptr->q = prevq; ptr->q = prevq;
ptr->nt=1; ptr->nt = 1;
ptr->nq=1 + ( (prevq==curq) ? 0 : 1 ); ptr->nq = 1 + ((prevq == curq) ? 0 : 1);
ptr->posq = query_numlevel - qlen - ( (prevq==curq) ? 0 : 1 ); ptr->posq = query_numlevel - qlen - ((prevq == curq) ? 0 : 1);
ptr->post = cur_tpos; ptr->post = cur_tpos;
} else { }
else
{
ptr->nt++; ptr->nt++;
ptr->nq++; ptr->nq++;
} }
if ( qlen == 1 && ptr->q->numvar==0 ) if (qlen == 1 && ptr->q->numvar == 0)
ptr->nt = tree_numlevel - ptr->post; ptr->nt = tree_numlevel - ptr->post;
curt = LEVEL_NEXT(curt); curt = LEVEL_NEXT(curt);
tlen--; tlen--;
cur_tpos++; cur_tpos++;
if ( high_pos < cur_tpos ) if (high_pos < cur_tpos)
high_pos++; high_pos++;
} else { }
else
{
isok = false; isok = false;
while( cur_tpos <= high_pos && tlen > 0 && !isok) { while (cur_tpos <= high_pos && tlen > 0 && !isok)
{
isok = checkLevel(curq, curt); isok = checkLevel(curq, curt);
curt = LEVEL_NEXT(curt); curt = LEVEL_NEXT(curt);
tlen--; tlen--;
cur_tpos++; cur_tpos++;
if ( !isok && ptr ) if (!isok && ptr)
ptr->nt++; ptr->nt++;
} }
if ( !isok ) if (!isok)
return false; return false;
if (ptr && ptr->q) { if (ptr && ptr->q)
if ( checkCond(ptr->q,ptr->nq,ptr->t,ptr->nt,NULL) ) {
if (checkCond(ptr->q, ptr->nq, ptr->t, ptr->nt, NULL))
return false; return false;
ptr->q = NULL; ptr->q = NULL;
} }
low_pos=cur_tpos; high_pos=cur_tpos; low_pos = cur_tpos;
high_pos = cur_tpos;
} }
} else { }
else
{
low_pos = cur_tpos + curq->low; low_pos = cur_tpos + curq->low;
high_pos = cur_tpos + curq->high; high_pos = cur_tpos + curq->high;
if ( ptr && ptr->q ) { if (ptr && ptr->q)
{
ptr->nq++; ptr->nq++;
if ( qlen==1 ) if (qlen == 1)
ptr->nt = tree_numlevel - ptr->post; ptr->nt = tree_numlevel - ptr->post;
} }
} }
...@@ -183,14 +214,18 @@ checkCond( lquery_level *curq, int query_numlevel, ltree_level *curt, int tree_n ...@@ -183,14 +214,18 @@ checkCond( lquery_level *curq, int query_numlevel, ltree_level *curt, int tree_n
qlen--; qlen--;
} }
if ( low_pos > tree_numlevel || tree_numlevel > high_pos ) if (low_pos > tree_numlevel || tree_numlevel > high_pos)
return false; return false;
while( qlen>0 ) { while (qlen > 0)
if ( curq->numvar ) { {
if ( ! (curq->flag & LQL_NOT) ) if (curq->numvar)
{
if (!(curq->flag & LQL_NOT))
return false; return false;
} else { }
else
{
low_pos = cur_tpos + curq->low; low_pos = cur_tpos + curq->low;
high_pos = cur_tpos + curq->high; high_pos = cur_tpos + curq->high;
} }
...@@ -199,42 +234,47 @@ checkCond( lquery_level *curq, int query_numlevel, ltree_level *curt, int tree_n ...@@ -199,42 +234,47 @@ checkCond( lquery_level *curq, int query_numlevel, ltree_level *curt, int tree_n
qlen--; qlen--;
} }
if ( low_pos > tree_numlevel || tree_numlevel > high_pos ) if (low_pos > tree_numlevel || tree_numlevel > high_pos)
return false; return false;
if ( ptr && ptr->q && checkCond(ptr->q,ptr->nq,ptr->t,ptr->nt,NULL) ) if (ptr && ptr->q && checkCond(ptr->q, ptr->nq, ptr->t, ptr->nt, NULL))
return false; return false;
return true; return true;
} }
Datum Datum
ltq_regex(PG_FUNCTION_ARGS) { ltq_regex(PG_FUNCTION_ARGS)
{
ltree *tree = PG_GETARG_LTREE(0); ltree *tree = PG_GETARG_LTREE(0);
lquery *query = PG_GETARG_LQUERY(1); lquery *query = PG_GETARG_LQUERY(1);
bool res= false; bool res = false;
if ( query->flag & LQUERY_HASNOT ) { if (query->flag & LQUERY_HASNOT)
{
FieldNot fn; FieldNot fn;
fn.q=NULL; fn.q = NULL;
res = checkCond( LQUERY_FIRST(query), query->numlevel, res = checkCond(LQUERY_FIRST(query), query->numlevel,
LTREE_FIRST(tree), tree->numlevel, &fn ); LTREE_FIRST(tree), tree->numlevel, &fn);
} else { }
res = checkCond( LQUERY_FIRST(query), query->numlevel, else
LTREE_FIRST(tree), tree->numlevel, NULL ); {
res = checkCond(LQUERY_FIRST(query), query->numlevel,
LTREE_FIRST(tree), tree->numlevel, NULL);
} }
PG_FREE_IF_COPY(tree,0); PG_FREE_IF_COPY(tree, 0);
PG_FREE_IF_COPY(query,1); PG_FREE_IF_COPY(query, 1);
PG_RETURN_BOOL(res); PG_RETURN_BOOL(res);
} }
Datum Datum
ltq_rregex(PG_FUNCTION_ARGS) { ltq_rregex(PG_FUNCTION_ARGS)
PG_RETURN_DATUM( DirectFunctionCall2( ltq_regex, {
PG_RETURN_DATUM(DirectFunctionCall2(ltq_regex,
PG_GETARG_DATUM(1), PG_GETARG_DATUM(1),
PG_GETARG_DATUM(0) PG_GETARG_DATUM(0)
) ); ));
} }
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
#include "utils/palloc.h" #include "utils/palloc.h"
#include "utils/builtins.h" #include "utils/builtins.h"
typedef struct { typedef struct
{
uint8 len; uint8 len;
char name[1]; char name[1];
} ltree_level; } ltree_level;
...@@ -14,7 +15,8 @@ typedef struct { ...@@ -14,7 +15,8 @@ typedef struct {
#define LEVEL_HDRSIZE (sizeof(uint8)) #define LEVEL_HDRSIZE (sizeof(uint8))
#define LEVEL_NEXT(x) ( (ltree_level*)( ((char*)(x)) + MAXALIGN(((ltree_level*)(x))->len + LEVEL_HDRSIZE) ) ) #define LEVEL_NEXT(x) ( (ltree_level*)( ((char*)(x)) + MAXALIGN(((ltree_level*)(x))->len + LEVEL_HDRSIZE) ) )
typedef struct { typedef struct
{
int32 len; int32 len;
uint16 numlevel; uint16 numlevel;
char data[1]; char data[1];
...@@ -26,7 +28,8 @@ typedef struct { ...@@ -26,7 +28,8 @@ typedef struct {
/* lquery */ /* lquery */
typedef struct { typedef struct
{
int4 val; int4 val;
uint8 len; uint8 len;
uint8 flag; uint8 flag;
...@@ -40,7 +43,8 @@ typedef struct { ...@@ -40,7 +43,8 @@ typedef struct {
#define LVAR_INCASE 0x02 #define LVAR_INCASE 0x02
#define LVAR_SUBLEXEM 0x04 #define LVAR_SUBLEXEM 0x04
typedef struct { typedef struct
{
uint16 totallen; uint16 totallen;
uint16 flag; uint16 flag;
uint16 numvar; uint16 numvar;
...@@ -61,7 +65,8 @@ typedef struct { ...@@ -61,7 +65,8 @@ typedef struct {
#endif #endif
#define LQL_CANLOOKSIGN(x) FLG_CANLOOKSIGN( ((lquery_level*)(x))->flag ) #define LQL_CANLOOKSIGN(x) FLG_CANLOOKSIGN( ((lquery_level*)(x))->flag )
typedef struct { typedef struct
{
int32 len; int32 len;
uint16 numlevel; uint16 numlevel;
uint16 firstgood; uint16 firstgood;
...@@ -155,11 +160,11 @@ Datum ltree_in(PG_FUNCTION_ARGS); ...@@ -155,11 +160,11 @@ Datum ltree_in(PG_FUNCTION_ARGS);
bool ltree_execute(ITEM * curitem, void *checkval, bool ltree_execute(ITEM * curitem, void *checkval,
bool calcnot, bool (*chkcond) (void *checkval, ITEM * val)); bool calcnot, bool (*chkcond) (void *checkval, ITEM * val));
int ltree_compare(const ltree *a, const ltree *b); int ltree_compare(const ltree * a, const ltree * b);
bool inner_isparent(const ltree *c, const ltree *p); bool inner_isparent(const ltree * c, const ltree * p);
bool compare_subnode( ltree_level *t, char *q, int len, bool compare_subnode(ltree_level * t, char *q, int len,
int (*cmpptr)(const char *,const char *,size_t), bool anyend ); int (*cmpptr) (const char *, const char *, size_t), bool anyend);
ltree* lca_inner(ltree** a, int len); ltree *lca_inner(ltree ** a, int len);
#define PG_GETARG_LTREE(x) ((ltree*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x)))) #define PG_GETARG_LTREE(x) ((ltree*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
#define PG_GETARG_LQUERY(x) ((lquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x)))) #define PG_GETARG_LQUERY(x) ((lquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
...@@ -203,7 +208,8 @@ typedef unsigned char *BITVECP; ...@@ -203,7 +208,8 @@ typedef unsigned char *BITVECP;
* *
*/ */
typedef struct { typedef struct
{
int4 len; int4 len;
uint32 flag; uint32 flag;
char data[1]; char data[1];
...@@ -249,4 +255,3 @@ typedef unsigned char ABITVEC[ASIGLEN]; ...@@ -249,4 +255,3 @@ typedef unsigned char ABITVEC[ASIGLEN];
/* type of key is the same to ltree_gist */ /* type of key is the same to ltree_gist */
#endif #endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
PG_FUNCTION_INFO_V1(ltxtq_in); PG_FUNCTION_INFO_V1(ltxtq_in);
Datum ltxtq_in(PG_FUNCTION_ARGS); Datum ltxtq_in(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(ltxtq_out); PG_FUNCTION_INFO_V1(ltxtq_out);
Datum ltxtq_out(PG_FUNCTION_ARGS); Datum ltxtq_out(PG_FUNCTION_ARGS);
...@@ -22,7 +23,8 @@ Datum ltxtq_out(PG_FUNCTION_ARGS); ...@@ -22,7 +23,8 @@ Datum ltxtq_out(PG_FUNCTION_ARGS);
* node of query tree, also used * node of query tree, also used
* for storing polish notation in parser * for storing polish notation in parser
*/ */
typedef struct NODE { typedef struct NODE
{
int4 type; int4 type;
int4 val; int4 val;
int2 distance; int2 distance;
...@@ -31,7 +33,8 @@ typedef struct NODE { ...@@ -31,7 +33,8 @@ typedef struct NODE {
struct NODE *next; struct NODE *next;
} NODE; } NODE;
typedef struct { typedef struct
{
char *buf; char *buf;
int4 state; int4 state;
int4 count; int4 count;
...@@ -70,27 +73,31 @@ gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, uint1 ...@@ -70,27 +73,31 @@ gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, uint1
(state->buf)++; (state->buf)++;
return OPEN; return OPEN;
} }
else if ( ISALNUM(*(state->buf)) ) else if (ISALNUM(*(state->buf)))
{ {
state->state = INOPERAND; state->state = INOPERAND;
*strval = state->buf; *strval = state->buf;
*lenval = 1; *lenval = 1;
*flag = 0; *flag = 0;
} else if ( !isspace((unsigned int)*(state->buf)) ) }
elog(ERROR,"Operand syntax error"); else if (!isspace((unsigned int) *(state->buf)))
elog(ERROR, "Operand syntax error");
break; break;
case INOPERAND: case INOPERAND:
if ( ISALNUM(*(state->buf)) ) { if (ISALNUM(*(state->buf)))
if ( *flag ) {
elog(ERROR,"Modificators syntax error"); if (*flag)
elog(ERROR, "Modificators syntax error");
(*lenval)++; (*lenval)++;
} else if ( *(state->buf) == '%' ) { }
else if (*(state->buf) == '%')
*flag |= LVAR_SUBLEXEM; *flag |= LVAR_SUBLEXEM;
} else if ( *(state->buf) == '@' ) { else if (*(state->buf) == '@')
*flag |= LVAR_INCASE; *flag |= LVAR_INCASE;
} else if ( *(state->buf) == '*' ) { else if (*(state->buf) == '*')
*flag |= LVAR_ANYEND; *flag |= LVAR_ANYEND;
} else { else
{
state->state = WAITOPERATOR; state->state = WAITOPERATOR;
return VAL; return VAL;
} }
...@@ -188,11 +195,12 @@ makepol(QPRS_STATE * state) ...@@ -188,11 +195,12 @@ makepol(QPRS_STATE * state)
int4 lenstack = 0; int4 lenstack = 0;
uint16 flag; uint16 flag;
while ((type = gettoken_query(state, &val, &lenval, &strval,&flag)) != END) { while ((type = gettoken_query(state, &val, &lenval, &strval, &flag)) != END)
{
switch (type) switch (type)
{ {
case VAL: case VAL:
pushval_asis(state, VAL, strval, lenval,flag); pushval_asis(state, VAL, strval, lenval, flag);
while (lenstack && (stack[lenstack - 1] == (int4) '&' || while (lenstack && (stack[lenstack - 1] == (int4) '&' ||
stack[lenstack - 1] == (int4) '!')) stack[lenstack - 1] == (int4) '!'))
{ {
...@@ -236,7 +244,8 @@ makepol(QPRS_STATE * state) ...@@ -236,7 +244,8 @@ makepol(QPRS_STATE * state)
} }
} }
while (lenstack) { while (lenstack)
{
lenstack--; lenstack--;
pushquery(state, OPR, stack[lenstack], 0, 0, 0); pushquery(state, OPR, stack[lenstack], 0, 0, 0);
}; };
...@@ -379,20 +388,24 @@ infix(INFIX * in, bool first) ...@@ -379,20 +388,24 @@ infix(INFIX * in, bool first)
char *op = in->op + in->curpol->distance; char *op = in->op + in->curpol->distance;
RESIZEBUF(in, in->curpol->length * 2 + 5); RESIZEBUF(in, in->curpol->length * 2 + 5);
while (*op) { while (*op)
{
*(in->cur) = *op; *(in->cur) = *op;
op++; op++;
in->cur++; in->cur++;
} }
if ( in->curpol->flag & LVAR_SUBLEXEM ) { if (in->curpol->flag & LVAR_SUBLEXEM)
{
*(in->cur) = '%'; *(in->cur) = '%';
in->cur++; in->cur++;
} }
if ( in->curpol->flag & LVAR_INCASE ) { if (in->curpol->flag & LVAR_INCASE)
{
*(in->cur) = '@'; *(in->cur) = '@';
in->cur++; in->cur++;
} }
if ( in->curpol->flag & LVAR_ANYEND ) { if (in->curpol->flag & LVAR_ANYEND)
{
*(in->cur) = '*'; *(in->cur) = '*';
in->cur++; in->cur++;
} }
...@@ -481,4 +494,3 @@ ltxtq_out(PG_FUNCTION_ARGS) ...@@ -481,4 +494,3 @@ ltxtq_out(PG_FUNCTION_ARGS)
PG_FREE_IF_COPY(query, 0); PG_FREE_IF_COPY(query, 0);
PG_RETURN_POINTER(nrm.buf); PG_RETURN_POINTER(nrm.buf);
} }
This diff is collapsed.
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
* pg_dumplo * pg_dumplo
* *
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_export.c,v 1.9 2002/08/15 02:58:29 momjian Exp $ * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_export.c,v 1.10 2002/09/04 20:31:06 momjian Exp $
* *
* Karel Zak 1999-2000 * Karel Zak 1999-2000
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
......
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
* pg_dumplo * pg_dumplo
* *
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_import.c,v 1.7 2002/08/15 02:58:29 momjian Exp $ * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_import.c,v 1.8 2002/09/04 20:31:06 momjian Exp $
* *
* Karel Zak 1999-2000 * Karel Zak 1999-2000
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
......
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
* pg_dumplo * pg_dumplo
* *
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.10 2001/11/12 17:44:14 momjian Exp $ * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.11 2002/09/04 20:31:07 momjian Exp $
* *
* Karel Zak 1999-2000 * Karel Zak 1999-2000
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -31,4 +31,3 @@ ...@@ -31,4 +31,3 @@
extern const char *descr[]; extern const char *descr[];
#endif #endif
This diff is collapsed.
...@@ -114,7 +114,7 @@ initmorph(void) ...@@ -114,7 +114,7 @@ initmorph(void)
needinit[i] = false; needinit[i] = false;
PGLC_current(&lc); PGLC_current(&lc);
if ( lc.lc_ctype ) if (lc.lc_ctype)
for (i = 1; i < lengthof(dicts); i++) for (i = 1; i < lengthof(dicts); i++)
if (strcmp(dicts[i].localename, lc.lc_ctype) == 0) if (strcmp(dicts[i].localename, lc.lc_ctype) == 0)
{ {
......
This diff is collapsed.
...@@ -402,7 +402,7 @@ compareWORD(const void *a, const void *b) ...@@ -402,7 +402,7 @@ compareWORD(const void *a, const void *b)
} }
static int static int
uniqueWORD(WORD *a, int4 l) uniqueWORD(WORD * a, int4 l)
{ {
WORD *ptr, WORD *ptr,
*res; *res;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/gist/gistget.c,v 1.34 2002/06/20 20:29:24 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/gist/gistget.c,v 1.35 2002/09/04 20:31:09 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment