Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Defines | Typedefs | Functions

ltree.h File Reference

#include "fmgr.h"
#include "tsearch/ts_locale.h"
Include dependency graph for ltree.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ltree_level
struct  ltree
struct  lquery_variant
struct  lquery_level
struct  lquery
struct  ITEM
struct  ltxtquery
struct  ltree_gist

Defines

#define LEVEL_HDRSIZE   (offsetof(ltree_level,name))
#define LEVEL_NEXT(x)   ( (ltree_level*)( ((char*)(x)) + MAXALIGN(((ltree_level*)(x))->len + LEVEL_HDRSIZE) ) )
#define LTREE_HDRSIZE   MAXALIGN( offsetof(ltree, data) )
#define LTREE_FIRST(x)   ( (ltree_level*)( ((char*)(x))+LTREE_HDRSIZE ) )
#define LVAR_HDRSIZE   MAXALIGN(offsetof(lquery_variant, name))
#define LVAR_NEXT(x)   ( (lquery_variant*)( ((char*)(x)) + MAXALIGN(((lquery_variant*)(x))->len) + LVAR_HDRSIZE ) )
#define LVAR_ANYEND   0x01
#define LVAR_INCASE   0x02
#define LVAR_SUBLEXEME   0x04
#define LQL_HDRSIZE   MAXALIGN( offsetof(lquery_level,variants) )
#define LQL_NEXT(x)   ( (lquery_level*)( ((char*)(x)) + MAXALIGN(((lquery_level*)(x))->totallen) ) )
#define LQL_FIRST(x)   ( (lquery_variant*)( ((char*)(x))+LQL_HDRSIZE ) )
#define LQL_NOT   0x10
#define FLG_CANLOOKSIGN(x)   ( ( (x) & ( LQL_NOT | LVAR_ANYEND | LVAR_SUBLEXEME | LVAR_INCASE ) ) == 0 )
#define LQL_CANLOOKSIGN(x)   FLG_CANLOOKSIGN( ((lquery_level*)(x))->flag )
#define LQUERY_HDRSIZE   MAXALIGN( offsetof(lquery, data) )
#define LQUERY_FIRST(x)   ( (lquery_level*)( ((char*)(x))+LQUERY_HDRSIZE ) )
#define LQUERY_HASNOT   0x01
#define ISALNUM(x)   ( t_isalpha(x) || t_isdigit(x) || ( pg_mblen(x) == 1 && t_iseq((x), '_') ) )
#define HDRSIZEQT   MAXALIGN(VARHDRSZ + sizeof(int32))
#define COMPUTESIZE(size, lenofoperand)   ( HDRSIZEQT + (size) * sizeof(ITEM) + (lenofoperand) )
#define GETQUERY(x)   (ITEM*)( (char*)(x)+HDRSIZEQT )
#define GETOPERAND(x)   ( (char*)GETQUERY(x) + ((ltxtquery*)x)->size * sizeof(ITEM) )
#define ISOPERATOR(x)   ( (x)=='!' || (x)=='&' || (x)=='|' || (x)=='(' || (x)==')' )
#define END   0
#define ERR   1
#define VAL   2
#define OPR   3
#define OPEN   4
#define CLOSE   5
#define VALTRUE   6
#define VALFALSE   7
#define PG_GETARG_LTREE(x)   ((ltree*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
#define PG_GETARG_LTREE_COPY(x)   ((ltree*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))
#define PG_GETARG_LQUERY(x)   ((lquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
#define PG_GETARG_LQUERY_COPY(x)   ((lquery*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))
#define PG_GETARG_LTXTQUERY(x)   ((ltxtquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
#define PG_GETARG_LTXTQUERY_COPY(x)   ((ltxtquery*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))
#define BITBYTE   8
#define SIGLENINT   2
#define SIGLEN   ( sizeof(int32)*SIGLENINT )
#define SIGLENBIT   (SIGLEN*BITBYTE)
#define LOOPBYTE   for(i=0;i<SIGLEN;i++)
#define GETBYTE(x, i)   ( *( (BITVECP)(x) + (int)( (i) / BITBYTE ) ) )
#define GETBITBYTE(x, i)   ( ((unsigned char)(x)) >> i & 0x01 )
#define CLRBIT(x, i)   GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITBYTE ) )
#define SETBIT(x, i)   GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) )
#define GETBIT(x, i)   ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 )
#define HASHVAL(val)   (((unsigned int)(val)) % SIGLENBIT)
#define HASH(sign, val)   SETBIT((sign), HASHVAL(val))
#define LTG_ONENODE   0x01
#define LTG_ALLTRUE   0x02
#define LTG_NORIGHT   0x04
#define LTG_HDRSIZE   MAXALIGN(VARHDRSZ + sizeof(uint32))
#define LTG_SIGN(x)   ( (BITVECP)( ((char*)(x))+LTG_HDRSIZE ) )
#define LTG_NODE(x)   ( (ltree*)( ((char*)(x))+LTG_HDRSIZE ) )
#define LTG_ISONENODE(x)   ( ((ltree_gist*)(x))->flag & LTG_ONENODE )
#define LTG_ISALLTRUE(x)   ( ((ltree_gist*)(x))->flag & LTG_ALLTRUE )
#define LTG_ISNORIGHT(x)   ( ((ltree_gist*)(x))->flag & LTG_NORIGHT )
#define LTG_LNODE(x)   ( (ltree*)( ( ((char*)(x))+LTG_HDRSIZE ) + ( LTG_ISALLTRUE(x) ? 0 : SIGLEN ) ) )
#define LTG_RENODE(x)   ( (ltree*)( ((char*)LTG_LNODE(x)) + VARSIZE(LTG_LNODE(x))) )
#define LTG_RNODE(x)   ( LTG_ISNORIGHT(x) ? LTG_LNODE(x) : LTG_RENODE(x) )
#define LTG_GETLNODE(x)   ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_LNODE(x) )
#define LTG_GETRNODE(x)   ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_RNODE(x) )
#define ASIGLENINT   (7)
#define ASIGLEN   (sizeof(int32)*ASIGLENINT)
#define ASIGLENBIT   (ASIGLEN*BITBYTE)
#define ALOOPBYTE   for(i=0;i<ASIGLEN;i++)
#define AHASHVAL(val)   (((unsigned int)(val)) % ASIGLENBIT)
#define AHASH(sign, val)   SETBIT((sign), AHASHVAL(val))

Typedefs

typedef struct ITEM ITEM
typedef unsigned char BITVEC [SIGLEN]
typedef unsigned char * BITVECP
typedef unsigned char ABITVEC [ASIGLEN]

Functions

Datum ltree_isparent (PG_FUNCTION_ARGS)
Datum ltree_risparent (PG_FUNCTION_ARGS)
Datum ltq_regex (PG_FUNCTION_ARGS)
Datum ltq_rregex (PG_FUNCTION_ARGS)
Datum lt_q_regex (PG_FUNCTION_ARGS)
Datum lt_q_rregex (PG_FUNCTION_ARGS)
Datum ltxtq_exec (PG_FUNCTION_ARGS)
Datum ltxtq_rexec (PG_FUNCTION_ARGS)
Datum _ltq_regex (PG_FUNCTION_ARGS)
Datum _ltq_rregex (PG_FUNCTION_ARGS)
Datum _lt_q_regex (PG_FUNCTION_ARGS)
Datum _lt_q_rregex (PG_FUNCTION_ARGS)
Datum _ltxtq_exec (PG_FUNCTION_ARGS)
Datum _ltxtq_rexec (PG_FUNCTION_ARGS)
Datum _ltree_isparent (PG_FUNCTION_ARGS)
Datum _ltree_risparent (PG_FUNCTION_ARGS)
Datum ltree_addltree (PG_FUNCTION_ARGS)
Datum ltree_addtext (PG_FUNCTION_ARGS)
Datum ltree_textadd (PG_FUNCTION_ARGS)
Datum ltree_in (PG_FUNCTION_ARGS)
bool ltree_execute (ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *val))
int ltree_compare (const ltree *a, const ltree *b)
bool inner_isparent (const ltree *c, const ltree *p)
bool compare_subnode (ltree_level *t, char *q, int len, int(*cmpptr)(const char *, const char *, size_t), bool anyend)
ltreelca_inner (ltree **a, int len)
int ltree_strncasecmp (const char *a, const char *b, size_t s)

Define Documentation

#define AHASH (   sign,
  val 
)    SETBIT((sign), AHASHVAL(val))

Definition at line 240 of file ltree.h.

Referenced by hashing().

#define AHASHVAL (   val  )     (((unsigned int)(val)) % ASIGLENBIT)

Definition at line 239 of file ltree.h.

Referenced by checkcondition_bit(), gist_qe(), and gist_te().

#define ALOOPBYTE   for(i=0;i<ASIGLEN;i++)
#define ASIGLEN   (sizeof(int32)*ASIGLENINT)

Definition at line 232 of file ltree.h.

Referenced by _ltree_picksplit(), and _ltree_union().

#define ASIGLENBIT   (ASIGLEN*BITBYTE)

Definition at line 233 of file ltree.h.

Referenced by hemdist().

#define ASIGLENINT   (7)

Definition at line 231 of file ltree.h.

#define BITBYTE   8

Definition at line 174 of file ltree.h.

#define CLOSE   5

Definition at line 124 of file ltree.h.

#define CLRBIT (   x,
  i 
)    GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITBYTE ) )

Definition at line 186 of file ltree.h.

#define COMPUTESIZE (   size,
  lenofoperand 
)    ( HDRSIZEQT + (size) * sizeof(ITEM) + (lenofoperand) )

Definition at line 113 of file ltree.h.

#define END   0

Definition at line 119 of file ltree.h.

#define ERR   1

Definition at line 120 of file ltree.h.

#define FLG_CANLOOKSIGN (   x  )     ( ( (x) & ( LQL_NOT | LVAR_ANYEND | LVAR_SUBLEXEME | LVAR_INCASE ) ) == 0 )

Definition at line 64 of file ltree.h.

Referenced by checkcondition_bit().

#define GETBIT (   x,
  i 
)    ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 )

Definition at line 188 of file ltree.h.

#define GETBITBYTE (   x,
  i 
)    ( ((unsigned char)(x)) >> i & 0x01 )

Definition at line 185 of file ltree.h.

#define GETBYTE (   x,
  i 
)    ( *( (BITVECP)(x) + (int)( (i) / BITBYTE ) ) )

Definition at line 184 of file ltree.h.

#define GETOPERAND (   x  )     ( (char*)GETQUERY(x) + ((ltxtquery*)x)->size * sizeof(ITEM) )
#define GETQUERY (   x  )     (ITEM*)( (char*)(x)+HDRSIZEQT )

Definition at line 114 of file ltree.h.

#define HASH (   sign,
  val 
)    SETBIT((sign), HASHVAL(val))

Definition at line 191 of file ltree.h.

#define HASHVAL (   val  )     (((unsigned int)(val)) % SIGLENBIT)

Definition at line 190 of file ltree.h.

#define HDRSIZEQT   MAXALIGN(VARHDRSZ + sizeof(int32))

Definition at line 112 of file ltree.h.

#define ISALNUM (   x  )     ( t_isalpha(x) || t_isdigit(x) || ( pg_mblen(x) == 1 && t_iseq((x), '_') ) )

Definition at line 82 of file ltree.h.

Referenced by gettoken_query(), lquery_in(), and ltree_in().

#define ISOPERATOR (   x  )     ( (x)=='!' || (x)=='&' || (x)=='|' || (x)=='(' || (x)==')' )

Definition at line 117 of file ltree.h.

#define LEVEL_HDRSIZE   (offsetof(ltree_level,name))

Definition at line 15 of file ltree.h.

Referenced by lca_inner(), and ltree_in().

#define LEVEL_NEXT (   x  )     ( (ltree_level*)( ((char*)(x)) + MAXALIGN(((ltree_level*)(x))->len + LEVEL_HDRSIZE) ) )
#define LOOPBYTE   for(i=0;i<SIGLEN;i++)

Definition at line 181 of file ltree.h.

#define LQL_CANLOOKSIGN (   x  )     FLG_CANLOOKSIGN( ((lquery_level*)(x))->flag )

Definition at line 66 of file ltree.h.

Referenced by gist_qe().

#define LQL_FIRST (   x  )     ( (lquery_variant*)( ((char*)(x))+LQL_HDRSIZE ) )

Definition at line 58 of file ltree.h.

Referenced by checkLevel(), gist_qe(), gist_tqcmp(), lquery_in(), and lquery_out().

#define LQL_HDRSIZE   MAXALIGN( offsetof(lquery_level,variants) )

Definition at line 56 of file ltree.h.

Referenced by lquery_in().

#define LQL_NEXT (   x  )     ( (lquery_level*)( ((char*)(x)) + MAXALIGN(((lquery_level*)(x))->totallen) ) )

Definition at line 57 of file ltree.h.

Referenced by checkCond(), gist_qe(), gist_tqcmp(), lquery_in(), and lquery_out().

#define LQL_NOT   0x10

Definition at line 60 of file ltree.h.

Referenced by checkCond(), and lquery_out().

#define LQUERY_FIRST (   x  )     ( (lquery_level*)( ((char*)(x))+LQUERY_HDRSIZE ) )

Definition at line 78 of file ltree.h.

Referenced by gist_qe(), gist_tqcmp(), lquery_in(), lquery_out(), and ltq_regex().

#define LQUERY_HASNOT   0x01

Definition at line 80 of file ltree.h.

Referenced by ltq_regex().

#define LQUERY_HDRSIZE   MAXALIGN( offsetof(lquery, data) )

Definition at line 77 of file ltree.h.

#define LTG_ALLTRUE   0x02

Definition at line 212 of file ltree.h.

#define LTG_GETLNODE (   x  )     ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_LNODE(x) )
#define LTG_GETRNODE (   x  )     ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_RNODE(x) )
#define LTG_HDRSIZE   MAXALIGN(VARHDRSZ + sizeof(uint32))
#define LTG_ISALLTRUE (   x  )     ( ((ltree_gist*)(x))->flag & LTG_ALLTRUE )
#define LTG_ISNORIGHT (   x  )     ( ((ltree_gist*)(x))->flag & LTG_NORIGHT )

Definition at line 220 of file ltree.h.

#define LTG_ISONENODE (   x  )     ( ((ltree_gist*)(x))->flag & LTG_ONENODE )

Definition at line 218 of file ltree.h.

Referenced by ltree_picksplit(), ltree_same(), and ltree_union().

#define LTG_LNODE (   x  )     ( (ltree*)( ( ((char*)(x))+LTG_HDRSIZE ) + ( LTG_ISALLTRUE(x) ? 0 : SIGLEN ) ) )

Definition at line 221 of file ltree.h.

Referenced by ltree_picksplit(), ltree_same(), and ltree_union().

#define LTG_NODE (   x  )     ( (ltree*)( ((char*)(x))+LTG_HDRSIZE ) )

Definition at line 217 of file ltree.h.

Referenced by ltree_compress(), ltree_consistent(), ltree_picksplit(), ltree_same(), and ltree_union().

#define LTG_NORIGHT   0x04

Definition at line 213 of file ltree.h.

#define LTG_ONENODE   0x01

Definition at line 211 of file ltree.h.

#define LTG_RENODE (   x  )     ( (ltree*)( ((char*)LTG_LNODE(x)) + VARSIZE(LTG_LNODE(x))) )

Definition at line 222 of file ltree.h.

#define LTG_RNODE (   x  )     ( LTG_ISNORIGHT(x) ? LTG_LNODE(x) : LTG_RENODE(x) )

Definition at line 223 of file ltree.h.

Referenced by ltree_picksplit(), ltree_same(), and ltree_union().

#define LTG_SIGN (   x  )     ( (BITVECP)( ((char*)(x))+LTG_HDRSIZE ) )
#define LTREE_FIRST (   x  )     ( (ltree_level*)( ((char*)(x))+LTREE_HDRSIZE ) )
#define LTREE_HDRSIZE   MAXALIGN( offsetof(ltree, data) )

Definition at line 25 of file ltree.h.

Referenced by inner_subltree(), lca_inner(), ltree_concat(), and ltree_in().

#define LVAR_ANYEND   0x01

Definition at line 42 of file ltree.h.

Referenced by checkcondition_str(), checkLevel(), infix(), and lquery_out().

#define LVAR_HDRSIZE   MAXALIGN(offsetof(lquery_variant, name))

Definition at line 39 of file ltree.h.

Referenced by lquery_in().

#define LVAR_INCASE   0x02

Definition at line 43 of file ltree.h.

Referenced by infix(), and lquery_out().

#define LVAR_NEXT (   x  )     ( (lquery_variant*)( ((char*)(x)) + MAXALIGN(((lquery_variant*)(x))->len) + LVAR_HDRSIZE ) )

Definition at line 40 of file ltree.h.

Referenced by checkLevel(), gist_qe(), lquery_in(), and lquery_out().

#define LVAR_SUBLEXEME   0x04

Definition at line 44 of file ltree.h.

Referenced by checkcondition_str(), checkLevel(), infix(), and lquery_out().

#define OPEN   4

Definition at line 123 of file ltree.h.

#define OPR   3

Definition at line 122 of file ltree.h.

#define PG_GETARG_LQUERY (   x  )     ((lquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))

Definition at line 167 of file ltree.h.

Referenced by _ltq_extract_regex(), _ltq_regex(), lquery_out(), ltq_regex(), and ltree_consistent().

#define PG_GETARG_LQUERY_COPY (   x  )     ((lquery*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))

Definition at line 168 of file ltree.h.

#define PG_GETARG_LTREE (   x  )     ((ltree*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
#define PG_GETARG_LTREE_COPY (   x  )     ((ltree*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))

Definition at line 166 of file ltree.h.

Referenced by ltree_consistent().

#define PG_GETARG_LTXTQUERY (   x  )     ((ltxtquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))

Definition at line 169 of file ltree.h.

Referenced by _ltxtq_exec(), _ltxtq_extract_exec(), ltxtq_exec(), and ltxtq_out().

#define PG_GETARG_LTXTQUERY_COPY (   x  )     ((ltxtquery*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))

Definition at line 170 of file ltree.h.

#define SETBIT (   x,
  i 
)    GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) )

Definition at line 187 of file ltree.h.

#define SIGLEN   ( sizeof(int32)*SIGLENINT )

Definition at line 176 of file ltree.h.

#define SIGLENBIT   (SIGLEN*BITBYTE)

Definition at line 177 of file ltree.h.

#define SIGLENINT   2

Definition at line 175 of file ltree.h.

#define VAL   2

Definition at line 121 of file ltree.h.

#define VALFALSE   7

Definition at line 126 of file ltree.h.

#define VALTRUE   6

Definition at line 125 of file ltree.h.

Referenced by findoprnd().


Typedef Documentation

typedef unsigned char ABITVEC[ASIGLEN]

Definition at line 234 of file ltree.h.

typedef unsigned char BITVEC[SIGLEN]

Definition at line 178 of file ltree.h.

typedef unsigned char* BITVECP

Definition at line 179 of file ltree.h.

typedef struct ITEM ITEM

Function Documentation

Datum _lt_q_regex ( PG_FUNCTION_ARGS   ) 

Definition at line 142 of file _ltree_op.c.

References ARR_DATA_PTR, ARR_DIMS, ARR_NDIM, array_contains_nulls(), array_iterator(), ArrayGetNItems(), ereport, errcode(), errmsg(), ERROR, ltq_regex(), NEXTVAL, NULL, PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, and PG_RETURN_BOOL.

Referenced by _lt_q_rregex().

{
    ArrayType  *_tree = PG_GETARG_ARRAYTYPE_P(0);
    ArrayType  *_query = PG_GETARG_ARRAYTYPE_P(1);
    lquery     *query = (lquery *) ARR_DATA_PTR(_query);
    bool        res = false;
    int         num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));

    if (ARR_NDIM(_query) > 1)
        ereport(ERROR,
                (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
                 errmsg("array must be one-dimensional")));
    if (array_contains_nulls(_query))
        ereport(ERROR,
                (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
                 errmsg("array must not contain nulls")));

    while (num > 0)
    {
        if (array_iterator(_tree, ltq_regex, (void *) query, NULL))
        {
            res = true;
            break;
        }
        num--;
        query = (lquery *) NEXTVAL(query);
    }

    PG_FREE_IF_COPY(_tree, 0);
    PG_FREE_IF_COPY(_query, 1);
    PG_RETURN_BOOL(res);
}

Datum _lt_q_rregex ( PG_FUNCTION_ARGS   ) 
Datum _ltq_regex ( PG_FUNCTION_ARGS   ) 

Definition at line 121 of file _ltree_op.c.

References array_iterator(), ltq_regex(), NULL, PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LQUERY, and PG_RETURN_BOOL.

Referenced by _ltq_rregex().

{
    ArrayType  *la = PG_GETARG_ARRAYTYPE_P(0);
    lquery     *query = PG_GETARG_LQUERY(1);
    bool        res = array_iterator(la, ltq_regex, (void *) query, NULL);

    PG_FREE_IF_COPY(la, 0);
    PG_FREE_IF_COPY(query, 1);
    PG_RETURN_BOOL(res);
}

Datum _ltq_rregex ( PG_FUNCTION_ARGS   ) 
Datum _ltree_isparent ( PG_FUNCTION_ARGS   ) 
Datum _ltree_risparent ( PG_FUNCTION_ARGS   ) 
Datum _ltxtq_exec ( PG_FUNCTION_ARGS   ) 
Datum _ltxtq_rexec ( PG_FUNCTION_ARGS   ) 
bool compare_subnode ( ltree_level t,
char *  q,
int  len,
int(*)(const char *, const char *, size_t)  cmpptr,
bool  anyend 
)

Definition at line 53 of file lquery_op.c.

References getlexeme(), ltree_level::len, ltree_level::name, and NULL.

Referenced by checkcondition_str(), and checkLevel().

{
    char       *endt = t->name + t->len;
    char       *endq = qn + len;
    char       *tn;
    int         lent,
                lenq;
    bool        isok;

    while ((qn = getlexeme(qn, endq, &lenq)) != NULL)
    {
        tn = t->name;
        isok = false;
        while ((tn = getlexeme(tn, endt, &lent)) != NULL)
        {
            if (
                (
                 lent == lenq ||
                 (lent > lenq && anyend)
                 ) &&
                (*cmpptr) (qn, tn, lenq) == 0)
            {

                isok = true;
                break;
            }
            tn += lent;
        }

        if (!isok)
            return false;
        qn += lenq;
    }

    return true;
}

bool inner_isparent ( const ltree c,
const ltree p 
)

Definition at line 155 of file ltree_op.c.

References ltree_level::len, LEVEL_NEXT, LTREE_FIRST, memcmp(), ltree_level::name, and ltree::numlevel.

Referenced by ltree_consistent(), ltree_isparent(), and ltree_risparent().

{
    ltree_level *cl = LTREE_FIRST(c);
    ltree_level *pl = LTREE_FIRST(p);
    int         pn = p->numlevel;

    if (pn > c->numlevel)
        return false;

    while (pn > 0)
    {
        if (cl->len != pl->len)
            return false;
        if (memcmp(cl->name, pl->name, cl->len))
            return false;

        pn--;
        cl = LEVEL_NEXT(cl);
        pl = LEVEL_NEXT(pl);
    }
    return true;
}

ltree* lca_inner ( ltree **  a,
int  len 
)

Definition at line 425 of file ltree_op.c.

References i, LEVEL_HDRSIZE, LEVEL_NEXT, LTREE_FIRST, LTREE_HDRSIZE, MAXALIGN, memcmp(), Min, ltree::numlevel, palloc(), and SET_VARSIZE.

Referenced by _lca(), and lca().

{
    int         tmp,
                num = ((*a)->numlevel) ? (*a)->numlevel - 1 : 0;
    ltree     **ptr = a + 1;
    int         i,
                reslen = LTREE_HDRSIZE;
    ltree_level *l1,
               *l2;
    ltree      *res;


    if ((*a)->numlevel == 0)
        return NULL;

    while (ptr - a < len)
    {
        if ((*ptr)->numlevel == 0)
            return NULL;
        else if ((*ptr)->numlevel == 1)
            num = 0;
        else
        {
            l1 = LTREE_FIRST(*a);
            l2 = LTREE_FIRST(*ptr);
            tmp = num;
            num = 0;
            for (i = 0; i < Min(tmp, (*ptr)->numlevel - 1); i++)
            {
                if (l1->len == l2->len && memcmp(l1->name, l2->name, l1->len) == 0)
                    num = i + 1;
                else
                    break;
                l1 = LEVEL_NEXT(l1);
                l2 = LEVEL_NEXT(l2);
            }
        }
        ptr++;
    }

    l1 = LTREE_FIRST(*a);
    for (i = 0; i < num; i++)
    {
        reslen += MAXALIGN(l1->len + LEVEL_HDRSIZE);
        l1 = LEVEL_NEXT(l1);
    }

    res = (ltree *) palloc(reslen);
    SET_VARSIZE(res, reslen);
    res->numlevel = num;

    l1 = LTREE_FIRST(*a);
    l2 = LTREE_FIRST(res);

    for (i = 0; i < num; i++)
    {
        memcpy(l2, l1, MAXALIGN(l1->len + LEVEL_HDRSIZE));
        l1 = LEVEL_NEXT(l1);
        l2 = LEVEL_NEXT(l2);
    }

    return res;
}

Datum lt_q_regex ( PG_FUNCTION_ARGS   ) 

Definition at line 339 of file lquery_op.c.

References ARR_DATA_PTR, ARR_DIMS, ARR_NDIM, array_contains_nulls(), ArrayGetNItems(), DatumGetBool, DirectFunctionCall2, ereport, errcode(), errmsg(), ERROR, ltq_regex(), NEXTVAL, PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LTREE, PG_RETURN_BOOL, and PointerGetDatum.

Referenced by lt_q_rregex(), and ltree_consistent().

{
    ltree      *tree = PG_GETARG_LTREE(0);
    ArrayType  *_query = PG_GETARG_ARRAYTYPE_P(1);
    lquery     *query = (lquery *) ARR_DATA_PTR(_query);
    bool        res = false;
    int         num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));

    if (ARR_NDIM(_query) > 1)
        ereport(ERROR,
                (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
                 errmsg("array must be one-dimensional")));
    if (array_contains_nulls(_query))
        ereport(ERROR,
                (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
                 errmsg("array must not contain nulls")));

    while (num > 0)
    {
        if (DatumGetBool(DirectFunctionCall2(ltq_regex,
                             PointerGetDatum(tree), PointerGetDatum(query))))
        {

            res = true;
            break;
        }
        num--;
        query = NEXTVAL(query);
    }

    PG_FREE_IF_COPY(tree, 0);
    PG_FREE_IF_COPY(_query, 1);
    PG_RETURN_BOOL(res);
}

Datum lt_q_rregex ( PG_FUNCTION_ARGS   ) 
Datum ltq_regex ( PG_FUNCTION_ARGS   ) 
Datum ltq_rregex ( PG_FUNCTION_ARGS   ) 
Datum ltree_addltree ( PG_FUNCTION_ARGS   ) 
Datum ltree_addtext ( PG_FUNCTION_ARGS   ) 
int ltree_compare ( const ltree a,
const ltree b 
)

Definition at line 61 of file ltree_op.c.

References ltree_level::len, LEVEL_NEXT, LTREE_FIRST, memcmp(), Min, ltree_level::name, and ltree::numlevel.

Referenced by gist_ischild(), gist_isparent(), ltree_consistent(), ltree_penalty(), ltree_picksplit(), ltree_union(), and treekey_cmp().

{
    ltree_level *al = LTREE_FIRST(a);
    ltree_level *bl = LTREE_FIRST(b);
    int         an = a->numlevel;
    int         bn = b->numlevel;
    int         res = 0;

    while (an > 0 && bn > 0)
    {
        if ((res = memcmp(al->name, bl->name, Min(al->len, bl->len))) == 0)
        {
            if (al->len != bl->len)
                return (al->len - bl->len) * 10 * (an + 1);
        }
        else
            return res * 10 * (an + 1);

        an--;
        bn--;
        al = LEVEL_NEXT(al);
        bl = LEVEL_NEXT(bl);
    }

    return (a->numlevel - b->numlevel) * 10 * (an + 1);
}

bool ltree_execute ( ITEM curitem,
void *  checkval,
bool  calcnot,
bool(*)(void *checkval, ITEM *val chkcond 
)

Definition at line 19 of file ltxtquery_op.c.

References ITEM::left, ltree_execute(), ITEM::type, ITEM::val, and VAL.

Referenced by gist_qtxt(), ltree_execute(), and ltxtq_exec().

{
    if (curitem->type == VAL)
        return (*chkcond) (checkval, curitem);
    else if (curitem->val == (int32) '!')
    {
        return (calcnot) ?
            ((ltree_execute(curitem + 1, checkval, calcnot, chkcond)) ? false : true)
            : true;
    }
    else if (curitem->val == (int32) '&')
    {
        if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond))
            return ltree_execute(curitem + 1, checkval, calcnot, chkcond);
        else
            return false;
    }
    else
    {                           /* |-operator */
        if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond))
            return true;
        else
            return ltree_execute(curitem + 1, checkval, calcnot, chkcond);
    }
}

Datum ltree_in ( PG_FUNCTION_ARGS   ) 

Definition at line 44 of file ltree_io.c.

References buf, elog, ereport, errcode(), errdetail(), errmsg(), ERROR, ISALNUM, ltree_level::len, nodeitem::len, LEVEL_HDRSIZE, LEVEL_NEXT, sort-test::list, LTPRS_WAITDELIM, LTPRS_WAITNAME, LTREE_FIRST, LTREE_HDRSIZE, MAXALIGN, ltree_level::name, ltree::numlevel, palloc(), palloc0(), pfree(), PG_GETARG_POINTER, pg_mblen(), PG_RETURN_POINTER, SET_VARSIZE, nodeitem::start, t_iseq, and nodeitem::wlen.

Referenced by ltree_addtext(), ltree_textadd(), and text2ltree().

{
    char       *buf = (char *) PG_GETARG_POINTER(0);
    char       *ptr;
    nodeitem   *list,
               *lptr;
    int         num = 0,
                totallen = 0;
    int         state = LTPRS_WAITNAME;
    ltree      *result;
    ltree_level *curlevel;
    int         charlen;
    int         pos = 0;

    ptr = buf;
    while (*ptr)
    {
        charlen = pg_mblen(ptr);
        if (charlen == 1 && t_iseq(ptr, '.'))
            num++;
        ptr += charlen;
    }

    list = lptr = (nodeitem *) palloc(sizeof(nodeitem) * (num + 1));
    ptr = buf;
    while (*ptr)
    {
        charlen = pg_mblen(ptr);

        if (state == LTPRS_WAITNAME)
        {
            if (ISALNUM(ptr))
            {
                lptr->start = ptr;
                lptr->wlen = 0;
                state = LTPRS_WAITDELIM;
            }
            else
                UNCHAR;
        }
        else if (state == LTPRS_WAITDELIM)
        {
            if (charlen == 1 && t_iseq(ptr, '.'))
            {
                lptr->len = ptr - lptr->start;
                if (lptr->wlen > 255)
                    ereport(ERROR,
                            (errcode(ERRCODE_NAME_TOO_LONG),
                             errmsg("name of level is too long"),
                             errdetail("Name length is %d, must "
                                       "be < 256, in position %d.",
                                       lptr->wlen, pos)));

                totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE);
                lptr++;
                state = LTPRS_WAITNAME;
            }
            else if (!ISALNUM(ptr))
                UNCHAR;
        }
        else
            /* internal error */
            elog(ERROR, "internal error in parser");

        ptr += charlen;
        lptr->wlen++;
        pos++;
    }

    if (state == LTPRS_WAITDELIM)
    {
        lptr->len = ptr - lptr->start;
        if (lptr->wlen > 255)
            ereport(ERROR,
                    (errcode(ERRCODE_NAME_TOO_LONG),
                     errmsg("name of level is too long"),
                     errdetail("Name length is %d, must "
                               "be < 256, in position %d.",
                               lptr->wlen, pos)));

        totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE);
        lptr++;
    }
    else if (!(state == LTPRS_WAITNAME && lptr == list))
        ereport(ERROR,
                (errcode(ERRCODE_SYNTAX_ERROR),
                 errmsg("syntax error"),
                 errdetail("Unexpected end of line.")));

    result = (ltree *) palloc0(LTREE_HDRSIZE + totallen);
    SET_VARSIZE(result, LTREE_HDRSIZE + totallen);
    result->numlevel = lptr - list;
    curlevel = LTREE_FIRST(result);
    lptr = list;
    while (lptr - list < result->numlevel)
    {
        curlevel->len = (uint16) lptr->len;
        memcpy(curlevel->name, lptr->start, lptr->len);
        curlevel = LEVEL_NEXT(curlevel);
        lptr++;
    }

    pfree(list);
    PG_RETURN_POINTER(result);
}

Datum ltree_isparent ( PG_FUNCTION_ARGS   ) 

Definition at line 179 of file ltree_op.c.

References inner_isparent(), PG_FREE_IF_COPY, PG_GETARG_LTREE, and PG_RETURN_BOOL.

Referenced by _ltree_extract_isparent(), and _ltree_isparent().

{
    ltree      *c = PG_GETARG_LTREE(1);
    ltree      *p = PG_GETARG_LTREE(0);
    bool        res = inner_isparent(c, p);

    PG_FREE_IF_COPY(c, 1);
    PG_FREE_IF_COPY(p, 0);
    PG_RETURN_BOOL(res);
}

Datum ltree_risparent ( PG_FUNCTION_ARGS   ) 
int ltree_strncasecmp ( const char *  a,
const char *  b,
size_t  s 
)

Definition at line 91 of file lquery_op.c.

References DEFAULT_COLLATION_OID, pfree(), and str_tolower().

Referenced by checkcondition_str(), and checkLevel().

{
    char       *al = str_tolower(a, s, DEFAULT_COLLATION_OID);
    char       *bl = str_tolower(b, s, DEFAULT_COLLATION_OID);
    int         res;

    res = strncmp(al, bl, s);

    pfree(al);
    pfree(bl);

    return res;
}

Datum ltree_textadd ( PG_FUNCTION_ARGS   ) 
Datum ltxtq_exec ( PG_FUNCTION_ARGS   ) 
Datum ltxtq_rexec ( PG_FUNCTION_ARGS   )