PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ltree.h File Reference
#include "fmgr.h"
#include "tsearch/ts_locale.h"
#include "utils/memutils.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
 
struct  LtreeGistOptions
 

Macros

#define LTREE_LABEL_MAX_CHARS   1000
 
#define LOWER_NODE
 
#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 LTREE_MAX_LEVELS   PG_UINT16_MAX /* ltree.numlevel is uint16 */
 
#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 /* '*' flag: prefix match */
 
#define LVAR_INCASE   0x02 /* '@' flag: case-insensitive match */
 
#define LVAR_SUBLEXEME   0x04 /* '%' flag: word-wise match */
 
#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 /* level has '!' (NOT) prefix */
 
#define LQL_COUNT   0x20 /* level is non-'*' and has repeat counts */
 
#define FLG_CANLOOKSIGN(x)   ( ( (x) & ( LQL_NOT | LVAR_ANYEND | LVAR_SUBLEXEME ) ) == 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_MAX_LEVELS   PG_UINT16_MAX /* lquery.numlevel is uint16 */
 
#define LQUERY_HASNOT   0x01
 
#define ISLABEL(x)   ( t_isalnum(x) || t_iseq(x, '_') || t_iseq(x, '-') )
 
#define HDRSIZEQT   MAXALIGN(VARHDRSZ + sizeof(int32))
 
#define COMPUTESIZE(size, lenofoperand)   ( HDRSIZEQT + (size) * sizeof(ITEM) + (lenofoperand) )
 
#define LTXTQUERY_TOO_BIG(size, lenofoperand)    ((size) > (MaxAllocSize - HDRSIZEQT - (lenofoperand)) / sizeof(ITEM))
 
#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 /* for stop words */
 
#define VALFALSE   7
 
#define DatumGetLtreeP(X)   ((ltree *) PG_DETOAST_DATUM(X))
 
#define DatumGetLtreePCopy(X)   ((ltree *) PG_DETOAST_DATUM_COPY(X))
 
#define PG_GETARG_LTREE_P(n)   DatumGetLtreeP(PG_GETARG_DATUM(n))
 
#define PG_GETARG_LTREE_P_COPY(n)   DatumGetLtreePCopy(PG_GETARG_DATUM(n))
 
#define DatumGetLqueryP(X)   ((lquery *) PG_DETOAST_DATUM(X))
 
#define DatumGetLqueryPCopy(X)   ((lquery *) PG_DETOAST_DATUM_COPY(X))
 
#define PG_GETARG_LQUERY_P(n)   DatumGetLqueryP(PG_GETARG_DATUM(n))
 
#define PG_GETARG_LQUERY_P_COPY(n)   DatumGetLqueryPCopy(PG_GETARG_DATUM(n))
 
#define DatumGetLtxtqueryP(X)   ((ltxtquery *) PG_DETOAST_DATUM(X))
 
#define DatumGetLtxtqueryPCopy(X)   ((ltxtquery *) PG_DETOAST_DATUM_COPY(X))
 
#define PG_GETARG_LTXTQUERY_P(n)   DatumGetLtxtqueryP(PG_GETARG_DATUM(n))
 
#define PG_GETARG_LTXTQUERY_P_COPY(n)   DatumGetLtxtqueryPCopy(PG_GETARG_DATUM(n))
 
#define BITBYTE   8
 
#define SIGLENBIT(siglen)   ((siglen) * BITBYTE)
 
#define LTREE_SIGLEN_DEFAULT   (2 * sizeof(int32))
 
#define LTREE_SIGLEN_MAX   GISTMaxIndexKeySize
 
#define LTREE_GET_SIGLEN()
 
#define LOOPBYTE(siglen)    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, siglen)   (((unsigned int)(val)) % SIGLENBIT(siglen))
 
#define HASH(sign, val, siglen)   SETBIT((sign), HASHVAL(val, siglen))
 
#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, siglen)   ( (ltree*)( ( ((char*)(x))+LTG_HDRSIZE ) + ( LTG_ISALLTRUE(x) ? 0 : (siglen) ) ) )
 
#define LTG_RENODE(x, siglen)   ( (ltree*)( ((char*)LTG_LNODE(x, siglen)) + VARSIZE(LTG_LNODE(x, siglen))) )
 
#define LTG_RNODE(x, siglen)   ( LTG_ISNORIGHT(x) ? LTG_LNODE(x, siglen) : LTG_RENODE(x, siglen) )
 
#define LTG_GETLNODE(x, siglen)   ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_LNODE(x, siglen) )
 
#define LTG_GETRNODE(x, siglen)   ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_RNODE(x, siglen) )
 
#define LTREE_ASIGLEN_DEFAULT   (7 * sizeof(int32))
 
#define LTREE_ASIGLEN_MAX   GISTMaxIndexKeySize
 
#define LTREE_GET_ASIGLEN()
 
#define ASIGLENBIT(siglen)   ((siglen) * BITBYTE)
 
#define ALOOPBYTE(siglen)    for (i = 0; i < (siglen); i++)
 
#define AHASHVAL(val, siglen)   (((unsigned int)(val)) % ASIGLENBIT(siglen))
 
#define AHASH(sign, val, siglen)   SETBIT((sign), AHASHVAL(val, siglen))
 

Typedefs

typedef struct ITEM ITEM
 
typedef unsigned char * BITVECP
 

Functions

PGDLLEXPORT Datum ltree_isparent (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum ltree_risparent (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum ltq_regex (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum ltq_rregex (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum lt_q_regex (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum lt_q_rregex (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum ltxtq_exec (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum ltxtq_rexec (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum _ltq_regex (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum _ltq_rregex (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum _lt_q_regex (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum _lt_q_rregex (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum _ltxtq_exec (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum _ltxtq_rexec (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum _ltree_isparent (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum _ltree_risparent (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum ltree_addltree (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum ltree_addtext (PG_FUNCTION_ARGS)
 
PGDLLEXPORT Datum ltree_textadd (PG_FUNCTION_ARGS)
 
PGDLLEXPORT 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 *qn, 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)
 
ltree_gistltree_gist_alloc (bool isalltrue, BITVECP sign, int siglen, ltree *left, ltree *right)
 

Macro Definition Documentation

◆ AHASH

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

Definition at line 306 of file ltree.h.

◆ AHASHVAL

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

Definition at line 305 of file ltree.h.

◆ ALOOPBYTE

#define ALOOPBYTE (   siglen)     for (i = 0; i < (siglen); i++)

Definition at line 302 of file ltree.h.

◆ ASIGLENBIT

#define ASIGLENBIT (   siglen)    ((siglen) * BITBYTE)

Definition at line 300 of file ltree.h.

◆ BITBYTE

#define BITBYTE   8

Definition at line 233 of file ltree.h.

◆ CLOSE

#define CLOSE   5

Definition at line 174 of file ltree.h.

◆ CLRBIT

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

Definition at line 248 of file ltree.h.

◆ COMPUTESIZE

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

Definition at line 161 of file ltree.h.

◆ DatumGetLqueryP

#define DatumGetLqueryP (   X)    ((lquery *) PG_DETOAST_DATUM(X))

Definition at line 221 of file ltree.h.

◆ DatumGetLqueryPCopy

#define DatumGetLqueryPCopy (   X)    ((lquery *) PG_DETOAST_DATUM_COPY(X))

Definition at line 222 of file ltree.h.

◆ DatumGetLtreeP

#define DatumGetLtreeP (   X)    ((ltree *) PG_DETOAST_DATUM(X))

Definition at line 216 of file ltree.h.

◆ DatumGetLtreePCopy

#define DatumGetLtreePCopy (   X)    ((ltree *) PG_DETOAST_DATUM_COPY(X))

Definition at line 217 of file ltree.h.

◆ DatumGetLtxtqueryP

#define DatumGetLtxtqueryP (   X)    ((ltxtquery *) PG_DETOAST_DATUM(X))

Definition at line 226 of file ltree.h.

◆ DatumGetLtxtqueryPCopy

#define DatumGetLtxtqueryPCopy (   X)    ((ltxtquery *) PG_DETOAST_DATUM_COPY(X))

Definition at line 227 of file ltree.h.

◆ END

#define END   0

Definition at line 169 of file ltree.h.

◆ ERR

#define ERR   1

Definition at line 170 of file ltree.h.

◆ FLG_CANLOOKSIGN

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

Definition at line 107 of file ltree.h.

◆ GETBIT

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

Definition at line 250 of file ltree.h.

◆ GETBITBYTE

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

Definition at line 247 of file ltree.h.

◆ GETBYTE

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

Definition at line 246 of file ltree.h.

◆ GETOPERAND

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

Definition at line 165 of file ltree.h.

◆ GETQUERY

#define GETQUERY (   x)    (ITEM*)( (char*)(x)+HDRSIZEQT )

Definition at line 164 of file ltree.h.

◆ HASH

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

Definition at line 253 of file ltree.h.

◆ HASHVAL

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

Definition at line 252 of file ltree.h.

◆ HDRSIZEQT

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

Definition at line 160 of file ltree.h.

◆ ISLABEL

#define ISLABEL (   x)    ( t_isalnum(x) || t_iseq(x, '_') || t_iseq(x, '-') )

Definition at line 130 of file ltree.h.

◆ ISOPERATOR

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

Definition at line 167 of file ltree.h.

◆ LEVEL_HDRSIZE

#define LEVEL_HDRSIZE   (offsetof(ltree_level,name))

Definition at line 39 of file ltree.h.

◆ LEVEL_NEXT

#define LEVEL_NEXT (   x)    ( (ltree_level*)( ((char*)(x)) + MAXALIGN(((ltree_level*)(x))->len + LEVEL_HDRSIZE) ) )

Definition at line 40 of file ltree.h.

◆ LOOPBYTE

#define LOOPBYTE (   siglen)     for(i = 0; i < (siglen); i++)

Definition at line 243 of file ltree.h.

◆ LOWER_NODE

#define LOWER_NODE

Definition at line 30 of file ltree.h.

◆ LQL_CANLOOKSIGN

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

Definition at line 111 of file ltree.h.

◆ LQL_COUNT

#define LQL_COUNT   0x20 /* level is non-'*' and has repeat counts */

Definition at line 104 of file ltree.h.

◆ LQL_FIRST

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

Definition at line 101 of file ltree.h.

◆ LQL_HDRSIZE

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

Definition at line 99 of file ltree.h.

◆ LQL_NEXT

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

Definition at line 100 of file ltree.h.

◆ LQL_NOT

#define LQL_NOT   0x10 /* level has '!' (NOT) prefix */

Definition at line 103 of file ltree.h.

◆ LQUERY_FIRST

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

Definition at line 124 of file ltree.h.

◆ LQUERY_HASNOT

#define LQUERY_HASNOT   0x01

Definition at line 127 of file ltree.h.

◆ LQUERY_HDRSIZE

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

Definition at line 123 of file ltree.h.

◆ LQUERY_MAX_LEVELS

#define LQUERY_MAX_LEVELS   PG_UINT16_MAX /* lquery.numlevel is uint16 */

Definition at line 125 of file ltree.h.

◆ LTG_ALLTRUE

#define LTG_ALLTRUE   0x02

Definition at line 274 of file ltree.h.

◆ LTG_GETLNODE

#define LTG_GETLNODE (   x,
  siglen 
)    ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_LNODE(x, siglen) )

Definition at line 287 of file ltree.h.

◆ LTG_GETRNODE

#define LTG_GETRNODE (   x,
  siglen 
)    ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_RNODE(x, siglen) )

Definition at line 288 of file ltree.h.

◆ LTG_HDRSIZE

#define LTG_HDRSIZE   MAXALIGN(VARHDRSZ + sizeof(uint32))

Definition at line 277 of file ltree.h.

◆ LTG_ISALLTRUE

#define LTG_ISALLTRUE (   x)    ( ((ltree_gist*)(x))->flag & LTG_ALLTRUE )

Definition at line 281 of file ltree.h.

◆ LTG_ISNORIGHT

#define LTG_ISNORIGHT (   x)    ( ((ltree_gist*)(x))->flag & LTG_NORIGHT )

Definition at line 282 of file ltree.h.

◆ LTG_ISONENODE

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

Definition at line 280 of file ltree.h.

◆ LTG_LNODE

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

Definition at line 283 of file ltree.h.

◆ LTG_NODE

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

Definition at line 279 of file ltree.h.

◆ LTG_NORIGHT

#define LTG_NORIGHT   0x04

Definition at line 275 of file ltree.h.

◆ LTG_ONENODE

#define LTG_ONENODE   0x01

Definition at line 273 of file ltree.h.

◆ LTG_RENODE

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

Definition at line 284 of file ltree.h.

◆ LTG_RNODE

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

Definition at line 285 of file ltree.h.

◆ LTG_SIGN

#define LTG_SIGN (   x)    ( (BITVECP)( ((char*)(x))+LTG_HDRSIZE ) )

Definition at line 278 of file ltree.h.

◆ LTREE_ASIGLEN_DEFAULT

#define LTREE_ASIGLEN_DEFAULT   (7 * sizeof(int32))

Definition at line 295 of file ltree.h.

◆ LTREE_ASIGLEN_MAX

#define LTREE_ASIGLEN_MAX   GISTMaxIndexKeySize

Definition at line 296 of file ltree.h.

◆ LTREE_FIRST

#define LTREE_FIRST (   x)    ( (ltree_level*)( ((char*)(x))+LTREE_HDRSIZE ) )

Definition at line 51 of file ltree.h.

◆ LTREE_GET_ASIGLEN

#define LTREE_GET_ASIGLEN ( )
Value:
#define PG_GET_OPCLASS_OPTIONS()
Definition: fmgr.h:342
#define PG_HAS_OPCLASS_OPTIONS()
Definition: fmgr.h:341
#define LTREE_ASIGLEN_DEFAULT
Definition: ltree.h:295

Definition at line 297 of file ltree.h.

◆ LTREE_GET_SIGLEN

#define LTREE_GET_SIGLEN ( )
Value:
#define LTREE_SIGLEN_DEFAULT
Definition: ltree.h:235

Definition at line 237 of file ltree.h.

◆ LTREE_HDRSIZE

#define LTREE_HDRSIZE   MAXALIGN( offsetof(ltree, data) )

Definition at line 50 of file ltree.h.

◆ LTREE_LABEL_MAX_CHARS

#define LTREE_LABEL_MAX_CHARS   1000

Definition at line 18 of file ltree.h.

◆ LTREE_MAX_LEVELS

#define LTREE_MAX_LEVELS   PG_UINT16_MAX /* ltree.numlevel is uint16 */

Definition at line 52 of file ltree.h.

◆ LTREE_SIGLEN_DEFAULT

#define LTREE_SIGLEN_DEFAULT   (2 * sizeof(int32))

Definition at line 235 of file ltree.h.

◆ LTREE_SIGLEN_MAX

#define LTREE_SIGLEN_MAX   GISTMaxIndexKeySize

Definition at line 236 of file ltree.h.

◆ LTXTQUERY_TOO_BIG

#define LTXTQUERY_TOO_BIG (   size,
  lenofoperand 
)     ((size) > (MaxAllocSize - HDRSIZEQT - (lenofoperand)) / sizeof(ITEM))

Definition at line 162 of file ltree.h.

◆ LVAR_ANYEND

#define LVAR_ANYEND   0x01 /* '*' flag: prefix match */

Definition at line 74 of file ltree.h.

◆ LVAR_HDRSIZE

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

Definition at line 71 of file ltree.h.

◆ LVAR_INCASE

#define LVAR_INCASE   0x02 /* '@' flag: case-insensitive match */

Definition at line 75 of file ltree.h.

◆ LVAR_NEXT

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

Definition at line 72 of file ltree.h.

◆ LVAR_SUBLEXEME

#define LVAR_SUBLEXEME   0x04 /* '%' flag: word-wise match */

Definition at line 76 of file ltree.h.

◆ OPEN

#define OPEN   4

Definition at line 173 of file ltree.h.

◆ OPR

#define OPR   3

Definition at line 172 of file ltree.h.

◆ PG_GETARG_LQUERY_P

#define PG_GETARG_LQUERY_P (   n)    DatumGetLqueryP(PG_GETARG_DATUM(n))

Definition at line 223 of file ltree.h.

◆ PG_GETARG_LQUERY_P_COPY

#define PG_GETARG_LQUERY_P_COPY (   n)    DatumGetLqueryPCopy(PG_GETARG_DATUM(n))

Definition at line 224 of file ltree.h.

◆ PG_GETARG_LTREE_P

#define PG_GETARG_LTREE_P (   n)    DatumGetLtreeP(PG_GETARG_DATUM(n))

Definition at line 218 of file ltree.h.

◆ PG_GETARG_LTREE_P_COPY

#define PG_GETARG_LTREE_P_COPY (   n)    DatumGetLtreePCopy(PG_GETARG_DATUM(n))

Definition at line 219 of file ltree.h.

◆ PG_GETARG_LTXTQUERY_P

#define PG_GETARG_LTXTQUERY_P (   n)    DatumGetLtxtqueryP(PG_GETARG_DATUM(n))

Definition at line 228 of file ltree.h.

◆ PG_GETARG_LTXTQUERY_P_COPY

#define PG_GETARG_LTXTQUERY_P_COPY (   n)    DatumGetLtxtqueryPCopy(PG_GETARG_DATUM(n))

Definition at line 229 of file ltree.h.

◆ SETBIT

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

Definition at line 249 of file ltree.h.

◆ SIGLENBIT

#define SIGLENBIT (   siglen)    ((siglen) * BITBYTE)

Definition at line 234 of file ltree.h.

◆ VAL

#define VAL   2

Definition at line 171 of file ltree.h.

◆ VALFALSE

#define VALFALSE   7

Definition at line 176 of file ltree.h.

◆ VALTRUE

#define VALTRUE   6 /* for stop words */

Definition at line 175 of file ltree.h.

Typedef Documentation

◆ BITVECP

typedef unsigned char* BITVECP

Definition at line 241 of file ltree.h.

◆ ITEM

typedef struct ITEM ITEM

Function Documentation

◆ _lt_q_regex()

PGDLLEXPORT Datum _lt_q_regex ( PG_FUNCTION_ARGS  )

Definition at line 135 of file _ltree_op.c.

136 {
137  ArrayType *_tree = PG_GETARG_ARRAYTYPE_P(0);
138  ArrayType *_query = PG_GETARG_ARRAYTYPE_P(1);
139  lquery *query = (lquery *) ARR_DATA_PTR(_query);
140  bool res = false;
141  int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
142 
143  if (ARR_NDIM(_query) > 1)
144  ereport(ERROR,
145  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
146  errmsg("array must be one-dimensional")));
147  if (array_contains_nulls(_query))
148  ereport(ERROR,
149  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
150  errmsg("array must not contain nulls")));
151 
152  while (num > 0)
153  {
154  if (array_iterator(_tree, ltq_regex, query, NULL))
155  {
156  res = true;
157  break;
158  }
159  num--;
160  query = (lquery *) NEXTVAL(query);
161  }
162 
163  PG_FREE_IF_COPY(_tree, 0);
164  PG_FREE_IF_COPY(_query, 1);
166 }
#define NEXTVAL(x)
Definition: _ltree_op.c:35
static bool array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found)
Definition: _ltree_op.c:38
#define ARR_NDIM(a)
Definition: array.h:290
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:263
#define ARR_DATA_PTR(a)
Definition: array.h:322
#define ARR_DIMS(a)
Definition: array.h:294
bool array_contains_nulls(ArrayType *array)
Definition: arrayfuncs.c:3767
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:57
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
Datum ltq_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:215
Definition: ltree.h:114

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

Referenced by _lt_q_rregex().

◆ _lt_q_rregex()

PGDLLEXPORT Datum _lt_q_rregex ( PG_FUNCTION_ARGS  )

Definition at line 169 of file _ltree_op.c.

170 {
172  PG_GETARG_DATUM(1),
173  PG_GETARG_DATUM(0)
174  ));
175 }
Datum _lt_q_regex(PG_FUNCTION_ARGS)
Definition: _ltree_op.c:135
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:643
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353

References _lt_q_regex(), DirectFunctionCall2, PG_GETARG_DATUM, and PG_RETURN_DATUM.

◆ _ltq_regex()

Definition at line 114 of file _ltree_op.c.

115 {
117  lquery *query = PG_GETARG_LQUERY_P(1);
118  bool res = array_iterator(la, ltq_regex, query, NULL);
119 
120  PG_FREE_IF_COPY(la, 0);
121  PG_FREE_IF_COPY(query, 1);
123 }
#define PG_GETARG_LQUERY_P(n)
Definition: ltree.h:223

References array_iterator(), ltq_regex(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LQUERY_P, PG_RETURN_BOOL, and res.

Referenced by _ltq_rregex().

◆ _ltq_rregex()

PGDLLEXPORT Datum _ltq_rregex ( PG_FUNCTION_ARGS  )

Definition at line 126 of file _ltree_op.c.

127 {
129  PG_GETARG_DATUM(1),
130  PG_GETARG_DATUM(0)
131  ));
132 }
Datum _ltq_regex(PG_FUNCTION_ARGS)
Definition: _ltree_op.c:114

References _ltq_regex(), DirectFunctionCall2, PG_GETARG_DATUM, and PG_RETURN_DATUM.

◆ _ltree_isparent()

PGDLLEXPORT Datum _ltree_isparent ( PG_FUNCTION_ARGS  )

Definition at line 72 of file _ltree_op.c.

73 {
75  ltree *query = PG_GETARG_LTREE_P(1);
76  bool res = array_iterator(la, ltree_isparent, query, NULL);
77 
78  PG_FREE_IF_COPY(la, 0);
79  PG_FREE_IF_COPY(query, 1);
81 }
PGDLLEXPORT Datum ltree_isparent(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
#define PG_GETARG_LTREE_P(n)
Definition: ltree.h:218
Definition: ltree.h:43

References array_iterator(), ltree_isparent(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LTREE_P, PG_RETURN_BOOL, and res.

Referenced by _ltree_r_isparent().

◆ _ltree_risparent()

PGDLLEXPORT Datum _ltree_risparent ( PG_FUNCTION_ARGS  )

Definition at line 93 of file _ltree_op.c.

94 {
96  ltree *query = PG_GETARG_LTREE_P(1);
97  bool res = array_iterator(la, ltree_risparent, query, NULL);
98 
99  PG_FREE_IF_COPY(la, 0);
100  PG_FREE_IF_COPY(query, 1);
102 }
PGDLLEXPORT Datum ltree_risparent(PG_FUNCTION_ARGS)
Definition: ltree_op.c:246

References array_iterator(), ltree_risparent(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LTREE_P, PG_RETURN_BOOL, and res.

Referenced by _ltree_r_risparent().

◆ _ltxtq_exec()

PGDLLEXPORT Datum _ltxtq_exec ( PG_FUNCTION_ARGS  )

Definition at line 179 of file _ltree_op.c.

180 {
182  ltxtquery *query = PG_GETARG_LTXTQUERY_P(1);
183  bool res = array_iterator(la, ltxtq_exec, query, NULL);
184 
185  PG_FREE_IF_COPY(la, 0);
186  PG_FREE_IF_COPY(query, 1);
188 }
#define PG_GETARG_LTXTQUERY_P(n)
Definition: ltree.h:228
PGDLLEXPORT Datum ltxtq_exec(PG_FUNCTION_ARGS)
Definition: ltxtquery_op.c:84

References array_iterator(), ltxtq_exec(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LTXTQUERY_P, PG_RETURN_BOOL, and res.

Referenced by _ltxtq_rexec().

◆ _ltxtq_rexec()

PGDLLEXPORT Datum _ltxtq_rexec ( PG_FUNCTION_ARGS  )

Definition at line 191 of file _ltree_op.c.

192 {
194  PG_GETARG_DATUM(1),
195  PG_GETARG_DATUM(0)
196  ));
197 }
Datum _ltxtq_exec(PG_FUNCTION_ARGS)
Definition: _ltree_op.c:179

References _ltxtq_exec(), DirectFunctionCall2, PG_GETARG_DATUM, and PG_RETURN_DATUM.

◆ compare_subnode()

bool compare_subnode ( ltree_level t,
char *  qn,
int  len,
int(*)(const char *, const char *, size_t)  cmpptr,
bool  anyend 
)

Definition at line 44 of file lquery_op.c.

45 {
46  char *endt = t->name + t->len;
47  char *endq = qn + len;
48  char *tn;
49  int lent,
50  lenq;
51  bool isok;
52 
53  while ((qn = getlexeme(qn, endq, &lenq)) != NULL)
54  {
55  tn = t->name;
56  isok = false;
57  while ((tn = getlexeme(tn, endt, &lent)) != NULL)
58  {
59  if ((lent == lenq || (lent > lenq && anyend)) &&
60  (*cmpptr) (qn, tn, lenq) == 0)
61  {
62 
63  isok = true;
64  break;
65  }
66  tn += lent;
67  }
68 
69  if (!isok)
70  return false;
71  qn += lenq;
72  }
73 
74  return true;
75 }
static char * getlexeme(char *start, char *end, int *len)
Definition: lquery_op.c:25
const void size_t len
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:36
uint16 len
Definition: ltree.h:35

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

Referenced by checkcondition_str(), and checkLevel().

◆ inner_isparent()

bool inner_isparent ( const ltree c,
const ltree p 
)

Definition at line 210 of file ltree_op.c.

211 {
212  ltree_level *cl = LTREE_FIRST(c);
213  ltree_level *pl = LTREE_FIRST(p);
214  int pn = p->numlevel;
215 
216  if (pn > c->numlevel)
217  return false;
218 
219  while (pn > 0)
220  {
221  if (cl->len != pl->len)
222  return false;
223  if (memcmp(cl->name, pl->name, cl->len) != 0)
224  return false;
225 
226  pn--;
227  cl = LEVEL_NEXT(cl);
228  pl = LEVEL_NEXT(pl);
229  }
230  return true;
231 }
#define LTREE_FIRST(x)
Definition: ltree.h:51
#define LEVEL_NEXT(x)
Definition: ltree.h:40
char * c
uint16 numlevel
Definition: ltree.h:45

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

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

◆ lca_inner()

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

Definition at line 493 of file ltree_op.c.

494 {
495  int tmp,
496  num,
497  i,
498  reslen;
499  ltree **ptr;
500  ltree_level *l1,
501  *l2;
502  ltree *res;
503 
504  if (len <= 0)
505  return NULL; /* no inputs? */
506  if ((*a)->numlevel == 0)
507  return NULL; /* any empty input means NULL result */
508 
509  /* num is the length of the longest common ancestor so far */
510  num = (*a)->numlevel - 1;
511 
512  /* Compare each additional input to *a */
513  ptr = a + 1;
514  while (ptr - a < len)
515  {
516  if ((*ptr)->numlevel == 0)
517  return NULL;
518  else if ((*ptr)->numlevel == 1)
519  num = 0;
520  else
521  {
522  l1 = LTREE_FIRST(*a);
523  l2 = LTREE_FIRST(*ptr);
524  tmp = Min(num, (*ptr)->numlevel - 1);
525  num = 0;
526  for (i = 0; i < tmp; i++)
527  {
528  if (l1->len == l2->len &&
529  memcmp(l1->name, l2->name, l1->len) == 0)
530  num = i + 1;
531  else
532  break;
533  l1 = LEVEL_NEXT(l1);
534  l2 = LEVEL_NEXT(l2);
535  }
536  }
537  ptr++;
538  }
539 
540  /* Now compute size of result ... */
541  reslen = LTREE_HDRSIZE;
542  l1 = LTREE_FIRST(*a);
543  for (i = 0; i < num; i++)
544  {
545  reslen += MAXALIGN(l1->len + LEVEL_HDRSIZE);
546  l1 = LEVEL_NEXT(l1);
547  }
548 
549  /* ... and construct it by copying from *a */
550  res = (ltree *) palloc0(reslen);
551  SET_VARSIZE(res, reslen);
552  res->numlevel = num;
553 
554  l1 = LTREE_FIRST(*a);
555  l2 = LTREE_FIRST(res);
556 
557  for (i = 0; i < num; i++)
558  {
559  memcpy(l2, l1, MAXALIGN(l1->len + LEVEL_HDRSIZE));
560  l1 = LEVEL_NEXT(l1);
561  l2 = LEVEL_NEXT(l2);
562  }
563 
564  return res;
565 }
#define Min(x, y)
Definition: c.h:983
#define MAXALIGN(LEN)
Definition: c.h:790
int a
Definition: isn.c:68
int i
Definition: isn.c:72
#define LEVEL_HDRSIZE
Definition: ltree.h:39
#define LTREE_HDRSIZE
Definition: ltree.h:50
void * palloc0(Size size)
Definition: mcxt.c:1347
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305

References a, i, ltree_level::len, len, LEVEL_HDRSIZE, LEVEL_NEXT, LTREE_FIRST, LTREE_HDRSIZE, MAXALIGN, Min, ltree_level::name, palloc0(), res, and SET_VARSIZE.

Referenced by _lca(), and lca().

◆ lt_q_regex()

Definition at line 239 of file lquery_op.c.

240 {
242  ArrayType *_query = PG_GETARG_ARRAYTYPE_P(1);
243  lquery *query = (lquery *) ARR_DATA_PTR(_query);
244  bool res = false;
245  int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
246 
247  if (ARR_NDIM(_query) > 1)
248  ereport(ERROR,
249  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
250  errmsg("array must be one-dimensional")));
251  if (array_contains_nulls(_query))
252  ereport(ERROR,
253  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
254  errmsg("array must not contain nulls")));
255 
256  while (num > 0)
257  {
260  {
261 
262  res = true;
263  break;
264  }
265  num--;
266  query = NEXTVAL(query);
267  }
268 
269  PG_FREE_IF_COPY(tree, 0);
270  PG_FREE_IF_COPY(_query, 1);
272 }
#define NEXTVAL(x)
Definition: lquery_op.c:22
static bool DatumGetBool(Datum X)
Definition: postgres.h:90
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
tree
Definition: radixtree.h:1834

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_P, PG_RETURN_BOOL, PointerGetDatum(), res, and tree.

Referenced by lt_q_rregex(), and ltree_consistent().

◆ lt_q_rregex()

PGDLLEXPORT Datum lt_q_rregex ( PG_FUNCTION_ARGS  )

Definition at line 275 of file lquery_op.c.

276 {
278  PG_GETARG_DATUM(1),
279  PG_GETARG_DATUM(0)
280  ));
281 }
Datum lt_q_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:239

References DirectFunctionCall2, lt_q_regex(), PG_GETARG_DATUM, and PG_RETURN_DATUM.

◆ ltq_regex()

Definition at line 215 of file lquery_op.c.

216 {
218  lquery *query = PG_GETARG_LQUERY_P(1);
219  bool res;
220 
221  res = checkCond(LQUERY_FIRST(query), query->numlevel,
222  LTREE_FIRST(tree), tree->numlevel);
223 
224  PG_FREE_IF_COPY(tree, 0);
225  PG_FREE_IF_COPY(query, 1);
227 }
static bool checkCond(lquery_level *curq, int qlen, ltree_level *curt, int tlen)
Definition: lquery_op.c:136
#define LQUERY_FIRST(x)
Definition: ltree.h:124
uint16 numlevel
Definition: ltree.h:116

References checkCond(), LQUERY_FIRST, LTREE_FIRST, lquery::numlevel, PG_FREE_IF_COPY, PG_GETARG_LQUERY_P, PG_GETARG_LTREE_P, PG_RETURN_BOOL, res, and tree.

Referenced by _lt_q_regex(), _ltq_extract_regex(), _ltq_regex(), lt_q_regex(), ltq_rregex(), and ltree_consistent().

◆ ltq_rregex()

Definition at line 230 of file lquery_op.c.

231 {
233  PG_GETARG_DATUM(1),
234  PG_GETARG_DATUM(0)
235  ));
236 }

References DirectFunctionCall2, ltq_regex(), PG_GETARG_DATUM, and PG_RETURN_DATUM.

◆ ltree_addltree()

PGDLLEXPORT Datum ltree_addltree ( PG_FUNCTION_ARGS  )

Definition at line 364 of file ltree_op.c.

365 {
366  ltree *a = PG_GETARG_LTREE_P(0);
367  ltree *b = PG_GETARG_LTREE_P(1);
368  ltree *r;
369 
370  r = ltree_concat(a, b);
371  PG_FREE_IF_COPY(a, 0);
372  PG_FREE_IF_COPY(b, 1);
374 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
int b
Definition: isn.c:69
static ltree * ltree_concat(ltree *a, ltree *b)
Definition: ltree_op.c:341

References a, b, ltree_concat(), PG_FREE_IF_COPY, PG_GETARG_LTREE_P, and PG_RETURN_POINTER.

◆ ltree_addtext()

PGDLLEXPORT Datum ltree_addtext ( PG_FUNCTION_ARGS  )

Definition at line 377 of file ltree_op.c.

378 {
379  ltree *a = PG_GETARG_LTREE_P(0);
380  text *b = PG_GETARG_TEXT_PP(1);
381  char *s;
382  ltree *r,
383  *tmp;
384 
385  s = text_to_cstring(b);
386 
388  PointerGetDatum(s)));
389 
390  pfree(s);
391 
392  r = ltree_concat(a, tmp);
393 
394  pfree(tmp);
395 
396  PG_FREE_IF_COPY(a, 0);
397  PG_FREE_IF_COPY(b, 1);
399 }
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:641
PGDLLEXPORT Datum ltree_in(PG_FUNCTION_ARGS)
Definition: ltree_io.c:174
void pfree(void *pointer)
Definition: mcxt.c:1521
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
Definition: c.h:666
char * text_to_cstring(const text *t)
Definition: varlena.c:217

References a, b, DatumGetPointer(), DirectFunctionCall1, ltree_concat(), ltree_in(), pfree(), PG_FREE_IF_COPY, PG_GETARG_LTREE_P, PG_GETARG_TEXT_PP, PG_RETURN_POINTER, PointerGetDatum(), and text_to_cstring().

◆ ltree_compare()

int ltree_compare ( const ltree a,
const ltree b 
)

Definition at line 43 of file ltree_op.c.

44 {
45  ltree_level *al = LTREE_FIRST(a);
46  ltree_level *bl = LTREE_FIRST(b);
47  int an = a->numlevel;
48  int bn = b->numlevel;
49 
50  while (an > 0 && bn > 0)
51  {
52  int res;
53 
54  if ((res = memcmp(al->name, bl->name, Min(al->len, bl->len))) == 0)
55  {
56  if (al->len != bl->len)
57  return (al->len - bl->len) * 10 * (an + 1);
58  }
59  else
60  {
61  if (res < 0)
62  res = -1;
63  else
64  res = 1;
65  return res * 10 * (an + 1);
66  }
67 
68  an--;
69  bn--;
70  al = LEVEL_NEXT(al);
71  bl = LEVEL_NEXT(bl);
72  }
73 
74  return (a->numlevel - b->numlevel) * 10 * (an + 1);
75 }

References a, b, ltree_level::len, LEVEL_NEXT, LTREE_FIRST, Min, ltree_level::name, and res.

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

◆ ltree_execute()

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

Definition at line 20 of file ltxtquery_op.c.

21 {
22  /* since this function recurses, it could be driven to stack overflow */
24 
25  if (curitem->type == VAL)
26  return (*chkcond) (checkval, curitem);
27  else if (curitem->val == (int32) '!')
28  {
29  return calcnot ?
30  ((ltree_execute(curitem + 1, checkval, calcnot, chkcond)) ? false : true)
31  : true;
32  }
33  else if (curitem->val == (int32) '&')
34  {
35  if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond))
36  return ltree_execute(curitem + 1, checkval, calcnot, chkcond);
37  else
38  return false;
39  }
40  else
41  { /* |-operator */
42  if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond))
43  return true;
44  else
45  return ltree_execute(curitem + 1, checkval, calcnot, chkcond);
46  }
47 }
#define VAL
Definition: _int.h:162
signed int int32
Definition: c.h:482
return true
Definition: isn.c:125
bool ltree_execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *val))
Definition: ltxtquery_op.c:20
void check_stack_depth(void)
Definition: postgres.c:3574
int16 left
Definition: _int.h:143
int32 val
Definition: _int.h:144
int16 type
Definition: _int.h:142

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

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

◆ ltree_gist_alloc()

ltree_gist* ltree_gist_alloc ( bool  isalltrue,
BITVECP  sign,
int  siglen,
ltree left,
ltree right 
)

Definition at line 42 of file ltree_gist.c.

44 {
45  int32 size = LTG_HDRSIZE + (isalltrue ? 0 : siglen) +
46  (left ? VARSIZE(left) + (right ? VARSIZE(right) : 0) : 0);
47  ltree_gist *result = palloc(size);
48 
49  SET_VARSIZE(result, size);
50 
51  if (siglen)
52  {
53  result->flag = 0;
54 
55  if (isalltrue)
56  result->flag |= LTG_ALLTRUE;
57  else if (sign)
58  memcpy(LTG_SIGN(result), sign, siglen);
59  else
60  memset(LTG_SIGN(result), 0, siglen);
61 
62  if (left)
63  {
64  memcpy(LTG_LNODE(result, siglen), left, VARSIZE(left));
65 
66  if (!right || left == right || ISEQ(left, right))
67  result->flag |= LTG_NORIGHT;
68  else
69  memcpy(LTG_RNODE(result, siglen), right, VARSIZE(right));
70  }
71  }
72  else
73  {
74  Assert(left);
75  result->flag = LTG_ONENODE;
76  memcpy(LTG_NODE(result), left, VARSIZE(left));
77  }
78 
79  return result;
80 }
#define Assert(condition)
Definition: c.h:837
char sign
Definition: informix.c:693
#define LTG_HDRSIZE
Definition: ltree.h:277
#define LTG_RNODE(x, siglen)
Definition: ltree.h:285
#define LTG_ONENODE
Definition: ltree.h:273
#define LTG_ALLTRUE
Definition: ltree.h:274
#define LTG_NORIGHT
Definition: ltree.h:275
#define LTG_SIGN(x)
Definition: ltree.h:278
#define LTG_LNODE(x, siglen)
Definition: ltree.h:283
#define LTG_NODE(x)
Definition: ltree.h:279
#define ISEQ(a, b)
Definition: ltree_gist.c:16
void * palloc(Size size)
Definition: mcxt.c:1317
static pg_noinline void Size size
Definition: slab.c:607
uint32 flag
Definition: ltree.h:269
#define VARSIZE(PTR)
Definition: varatt.h:279

References Assert, ltree_gist::flag, ISEQ, LTG_ALLTRUE, LTG_HDRSIZE, LTG_LNODE, LTG_NODE, LTG_NORIGHT, LTG_ONENODE, LTG_RNODE, LTG_SIGN, palloc(), SET_VARSIZE, sign, size, and VARSIZE.

Referenced by _ltree_compress(), _ltree_picksplit(), _ltree_union(), ltree_compress(), ltree_picksplit(), and ltree_union().

◆ ltree_in()

Definition at line 174 of file ltree_io.c.

175 {
176  char *buf = (char *) PG_GETARG_POINTER(0);
177  ltree *res;
178 
179  if ((res = parse_ltree(buf, fcinfo->context)) == NULL)
180  PG_RETURN_NULL();
181 
183 }
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_NULL()
Definition: fmgr.h:345
static ltree * parse_ltree(const char *buf, struct Node *escontext)
Definition: ltree_io.c:36
static char * buf
Definition: pg_test_fsync.c:72

References buf, parse_ltree(), PG_GETARG_POINTER, PG_RETURN_NULL, PG_RETURN_POINTER, and res.

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

◆ ltree_isparent()

PGDLLEXPORT Datum ltree_isparent ( PG_FUNCTION_ARGS  )

Definition at line 234 of file ltree_op.c.

235 {
236  ltree *c = PG_GETARG_LTREE_P(1);
237  ltree *p = PG_GETARG_LTREE_P(0);
238  bool res = inner_isparent(c, p);
239 
240  PG_FREE_IF_COPY(c, 1);
241  PG_FREE_IF_COPY(p, 0);
243 }
bool inner_isparent(const ltree *c, const ltree *p)
Definition: ltree_op.c:210

References inner_isparent(), PG_FREE_IF_COPY, PG_GETARG_LTREE_P, PG_RETURN_BOOL, and res.

Referenced by _ltree_extract_isparent(), and _ltree_isparent().

◆ ltree_risparent()

PGDLLEXPORT Datum ltree_risparent ( PG_FUNCTION_ARGS  )

Definition at line 246 of file ltree_op.c.

247 {
248  ltree *c = PG_GETARG_LTREE_P(0);
249  ltree *p = PG_GETARG_LTREE_P(1);
250  bool res = inner_isparent(c, p);
251 
252  PG_FREE_IF_COPY(c, 0);
253  PG_FREE_IF_COPY(p, 1);
255 }

References inner_isparent(), PG_FREE_IF_COPY, PG_GETARG_LTREE_P, PG_RETURN_BOOL, and res.

Referenced by _ltree_extract_risparent(), and _ltree_risparent().

◆ ltree_strncasecmp()

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

Definition at line 78 of file lquery_op.c.

79 {
80  char *al = str_tolower(a, s, DEFAULT_COLLATION_OID);
81  char *bl = str_tolower(b, s, DEFAULT_COLLATION_OID);
82  int res;
83 
84  res = strncmp(al, bl, s);
85 
86  pfree(al);
87  pfree(bl);
88 
89  return res;
90 }
char * str_tolower(const char *buff, size_t nbytes, Oid collid)
Definition: formatting.c:1636

References a, b, pfree(), res, and str_tolower().

Referenced by checkcondition_str(), and checkLevel().

◆ ltree_textadd()

PGDLLEXPORT Datum ltree_textadd ( PG_FUNCTION_ARGS  )

Definition at line 462 of file ltree_op.c.

463 {
464  ltree *a = PG_GETARG_LTREE_P(1);
465  text *b = PG_GETARG_TEXT_PP(0);
466  char *s;
467  ltree *r,
468  *tmp;
469 
470  s = text_to_cstring(b);
471 
473  PointerGetDatum(s)));
474 
475  pfree(s);
476 
477  r = ltree_concat(tmp, a);
478 
479  pfree(tmp);
480 
481  PG_FREE_IF_COPY(a, 1);
482  PG_FREE_IF_COPY(b, 0);
484 }

References a, b, DatumGetPointer(), DirectFunctionCall1, ltree_concat(), ltree_in(), pfree(), PG_FREE_IF_COPY, PG_GETARG_LTREE_P, PG_GETARG_TEXT_PP, PG_RETURN_POINTER, PointerGetDatum(), and text_to_cstring().

◆ ltxtq_exec()

Definition at line 84 of file ltxtquery_op.c.

85 {
87  ltxtquery *query = PG_GETARG_LTXTQUERY_P(1);
88  CHKVAL chkval;
89  bool result;
90 
91  chkval.node = val;
92  chkval.operand = GETOPERAND(query);
93 
94  result = ltree_execute(GETQUERY(query),
95  &chkval,
96  true,
98 
99  PG_FREE_IF_COPY(val, 0);
100  PG_FREE_IF_COPY(query, 1);
101  PG_RETURN_BOOL(result);
102 }
#define GETQUERY(x)
Definition: _int.h:157
long val
Definition: informix.c:689
#define GETOPERAND(x)
Definition: ltree.h:165
static bool checkcondition_str(void *checkval, ITEM *val)
Definition: ltxtquery_op.c:56
char * operand
Definition: ltxtquery_op.c:52
ltree * node
Definition: ltxtquery_op.c:51

References checkcondition_str(), GETOPERAND, GETQUERY, ltree_execute(), CHKVAL::node, CHKVAL::operand, PG_FREE_IF_COPY, PG_GETARG_LTREE_P, PG_GETARG_LTXTQUERY_P, PG_RETURN_BOOL, and val.

Referenced by _ltxtq_exec(), _ltxtq_extract_exec(), ltree_consistent(), and ltxtq_rexec().

◆ ltxtq_rexec()

PGDLLEXPORT Datum ltxtq_rexec ( PG_FUNCTION_ARGS  )

Definition at line 105 of file ltxtquery_op.c.

106 {
108  PG_GETARG_DATUM(1),
109  PG_GETARG_DATUM(0)
110  ));
111 }
Datum ltxtq_exec(PG_FUNCTION_ARGS)
Definition: ltxtquery_op.c:84

References DirectFunctionCall2, ltxtq_exec(), PG_GETARG_DATUM, and PG_RETURN_DATUM.