Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Data Structures | Macros | Enumerations | Functions
pat.c File Reference
#include "groonga_in.h"
#include <string.h>
#include <limits.h>
#include "pat.h"
#include "output.h"
#include "util.h"
#include "normalizer_in.h"
Include dependency graph for pat.c:

Go to the source code of this file.

Data Structures

struct  pat_node
struct  sis_node
struct  rk_tree_node

Macros

#define GRN_PAT_DELETED   (GRN_ID_MAX + 1)
#define GRN_PAT_SEGMENT_SIZE   0x400000
#define W_OF_KEY_IN_A_SEGMENT   22
#define W_OF_PAT_IN_A_SEGMENT   18
#define W_OF_SIS_IN_A_SEGMENT   19
#define KEY_MASK_IN_A_SEGMENT   0x3fffff
#define PAT_MASK_IN_A_SEGMENT   0x3ffff
#define SIS_MASK_IN_A_SEGMENT   0x7ffff
#define SEG_NOT_ASSIGNED   0xffff
#define GRN_PAT_MAX_SEGMENT   0x1000
#define GRN_PAT_MDELINFOS   (GRN_PAT_NDELINFOS - 1)
#define GRN_PAT_BIN_KEY   0x70000
#define PAT_DELETING   (1<<1)
#define PAT_IMMEDIATE   (1<<2)
#define PAT_DEL(x)   ((x)->bits & PAT_DELETING)
#define PAT_IMD(x)   ((x)->bits & PAT_IMMEDIATE)
#define PAT_LEN(x)   (((x)->bits >> 3) + 1)
#define PAT_CHK(x)   ((x)->check)
#define PAT_DEL_ON(x)   ((x)->bits |= PAT_DELETING)
#define PAT_IMD_ON(x)   ((x)->bits |= PAT_IMMEDIATE)
#define PAT_DEL_OFF(x)   ((x)->bits &= ~PAT_DELETING)
#define PAT_IMD_OFF(x)   ((x)->bits &= ~PAT_IMMEDIATE)
#define PAT_LEN_SET(x, v)   ((x)->bits = ((x)->bits & ((1<<3) - 1))|(((v) - 1) << 3))
#define PAT_CHK_SET(x, v)   ((x)->check = (v))
#define nth_bit(key, n, l)   ((((key)[(n)>>4]) >> (7 - (((n)>>1) & 7))) & 1)
#define PAT_AT(pat, id, n)
#define MAX_LEVEL   16
#define KEY_AT(pat, pos, ptr, addp)
#define MAX_FIXED_KEY_SIZE   (sizeof(int64_t))
#define KEY_NEEDS_CONVERT(pat, size)   (!((pat)->obj.header.flags & GRN_OBJ_KEY_VAR_SIZE) && (size) <= MAX_FIXED_KEY_SIZE)
#define KEY_ENC(pat, keybuf, key, size)
#define KEY_DEC(pat, keybuf, key, size)
#define KEY_ENCODE(pat, keybuf, key, size)
#define INITIAL_SIZE   512
#define RK_OUTPUT(e, l)

Enumerations

enum  { segment_key = 0, segment_pat = 1, segment_sis = 2 }
enum  { DL_EMPTY = 0, DL_PHASE1, DL_PHASE2 }

Functions

grn_patgrn_pat_create (grn_ctx *ctx, const char *path, uint32_t key_size, uint32_t value_size, uint32_t flags)
grn_rc grn_pat_cache_enable (grn_ctx *ctx, grn_pat *pat, uint32_t cache_size)
void grn_pat_cache_disable (grn_ctx *ctx, grn_pat *pat)
grn_patgrn_pat_open (grn_ctx *ctx, const char *path)
grn_rc grn_pat_close (grn_ctx *ctx, grn_pat *pat)
grn_rc grn_pat_remove (grn_ctx *ctx, const char *path)
grn_rc grn_pat_truncate (grn_ctx *ctx, grn_pat *pat)
grn_id grn_pat_add (grn_ctx *ctx, grn_pat *pat, const void *key, uint32_t key_size, void **value, int *added)
grn_id grn_pat_get (grn_ctx *ctx, grn_pat *pat, const void *key, uint32_t key_size, void **value)
grn_id grn_pat_nextid (grn_ctx *ctx, grn_pat *pat, const void *key, uint32_t key_size)
grn_rc grn_pat_prefix_search (grn_ctx *ctx, grn_pat *pat, const void *key, uint32_t key_size, grn_hash *h)
grn_hashgrn_pat_prefix_search2 (grn_ctx *ctx, grn_pat *pat, const void *key, uint32_t key_size)
grn_rc grn_pat_suffix_search (grn_ctx *ctx, grn_pat *pat, const void *key, uint32_t key_size, grn_hash *h)
grn_hashgrn_pat_suffix_search2 (grn_ctx *ctx, grn_pat *pat, const void *key, uint32_t key_size)
grn_id grn_pat_lcp_search (grn_ctx *ctx, grn_pat *pat, const void *key, uint32_t key_size)
grn_rc grn_pat_delete (grn_ctx *ctx, grn_pat *pat, const void *key, uint32_t key_size, grn_table_delete_optarg *optarg)
uint32_t grn_pat_size (grn_ctx *ctx, grn_pat *pat)
const char * _grn_pat_key (grn_ctx *ctx, grn_pat *pat, grn_id id, uint32_t *key_size)
grn_rc grn_pat_delete_by_id (grn_ctx *ctx, grn_pat *pat, grn_id id, grn_table_delete_optarg *optarg)
int grn_pat_get_key (grn_ctx *ctx, grn_pat *pat, grn_id id, void *keybuf, int bufsize)
int grn_pat_get_key2 (grn_ctx *ctx, grn_pat *pat, grn_id id, grn_obj *bulk)
int grn_pat_get_value (grn_ctx *ctx, grn_pat *pat, grn_id id, void *valuebuf)
const char * grn_pat_get_value_ (grn_ctx *ctx, grn_pat *pat, grn_id id, uint32_t *size)
grn_rc grn_pat_set_value (grn_ctx *ctx, grn_pat *pat, grn_id id, const void *value, int flags)
grn_rc grn_pat_info (grn_ctx *ctx, grn_pat *pat, int *key_size, unsigned int *flags, grn_encoding *encoding, unsigned int *n_entries, unsigned int *file_size)
int grn_pat_delete_with_sis (grn_ctx *ctx, grn_pat *pat, grn_id id, grn_table_delete_optarg *optarg)
grn_id grn_pat_next (grn_ctx *ctx, grn_pat *pat, grn_id id)
grn_id grn_pat_at (grn_ctx *ctx, grn_pat *pat, grn_id id)
grn_id grn_pat_curr_id (grn_ctx *ctx, grn_pat *pat)
int grn_pat_scan (grn_ctx *ctx, grn_pat *pat, const char *str, unsigned int str_len, grn_pat_scan_hit *sh, unsigned int sh_size, const char **rest)
grn_id grn_pat_cursor_next (grn_ctx *ctx, grn_pat_cursor *c)
void grn_pat_cursor_close (grn_ctx *ctx, grn_pat_cursor *c)
grn_pat_cursorgrn_pat_cursor_open (grn_ctx *ctx, grn_pat *pat, const void *min, uint32_t min_size, const void *max, uint32_t max_size, int offset, int limit, int flags)
int grn_pat_cursor_get_key (grn_ctx *ctx, grn_pat_cursor *c, void **key)
int grn_pat_cursor_get_value (grn_ctx *ctx, grn_pat_cursor *c, void **value)
int grn_pat_cursor_get_key_value (grn_ctx *ctx, grn_pat_cursor *c, void **key, uint32_t *key_size, void **value)
grn_rc grn_pat_cursor_set_value (grn_ctx *ctx, grn_pat_cursor *c, const void *value, int flags)
grn_rc grn_pat_cursor_delete (grn_ctx *ctx, grn_pat_cursor *c, grn_table_delete_optarg *optarg)
void grn_pat_check (grn_ctx *ctx, grn_pat *pat)
void grn_pat_inspect_nodes (grn_ctx *ctx, grn_pat *pat, grn_obj *buf)
void grn_pat_cursor_inspect (grn_ctx *ctx, grn_pat_cursor *c, grn_obj *buf)

Macro Definition Documentation

#define GRN_PAT_BIN_KEY   0x70000

Definition at line 38 of file pat.c.

#define GRN_PAT_DELETED   (GRN_ID_MAX + 1)

Definition at line 25 of file pat.c.

#define GRN_PAT_MAX_SEGMENT   0x1000

Definition at line 35 of file pat.c.

#define GRN_PAT_MDELINFOS   (GRN_PAT_NDELINFOS - 1)

Definition at line 36 of file pat.c.

#define GRN_PAT_SEGMENT_SIZE   0x400000

Definition at line 27 of file pat.c.

#define INITIAL_SIZE   512

Definition at line 1607 of file pat.c.

#define KEY_AT (   pat,
  pos,
  ptr,
  addp 
)
Value:
do {\
int flags = addp;\
GRN_IO_ARRAY_AT(pat->io, segment_key, pos, &flags, ptr);\
} while (0)

Definition at line 186 of file pat.c.

#define KEY_DEC (   pat,
  keybuf,
  key,
  size 
)
Value:
do {\
switch ((pat)->obj.header.flags & GRN_OBJ_KEY_MASK) {\
if (((pat)->obj.header.domain != GRN_DB_TOKYO_GEO_POINT) &&\
((pat)->obj.header.domain != GRN_DB_WGS84_GEO_POINT)) {\
grn_ntoh((keybuf), (key), (size));\
break;\
}\
grn_ntog((keybuf), (key), (size));\
break;\
grn_ntohi((keybuf), (key), (size));\
break;\
if ((size) == sizeof(int64_t)) {\
int64_t v;\
grn_hton(&v, (key), (size));\
*((int64_t *)(keybuf)) = v ^ (((v^(1LL<<63))>> 63)|(1LL<<63)); \
}\
break;\
}\
} while (0)

Definition at line 792 of file pat.c.

#define KEY_ENC (   pat,
  keybuf,
  key,
  size 
)
Value:
do {\
switch ((pat)->obj.header.flags & GRN_OBJ_KEY_MASK) {\
if (((pat)->obj.header.domain != GRN_DB_TOKYO_GEO_POINT) &&\
((pat)->obj.header.domain != GRN_DB_WGS84_GEO_POINT)) {\
grn_hton((keybuf), (key), (size));\
break;\
}\
grn_gton((keybuf), (key), (size));\
break;\
grn_hton((keybuf), (key), (size));\
*((uint8_t *)(keybuf)) ^= 0x80;\
break;\
if ((size) == sizeof(int64_t)) {\
int64_t v = *(int64_t *)(key);\
v ^= ((v >> 63)|(1LL << 63));\
grn_hton((keybuf), &v, (size));\
}\
break;\
}\
} while (0)

Definition at line 767 of file pat.c.

#define KEY_ENCODE (   pat,
  keybuf,
  key,
  size 
)
Value:
do {\
if (KEY_NEEDS_CONVERT(pat,size)) {\
KEY_ENC((pat), (keybuf), (key), (size));\
(key) = (keybuf);\
}\
} while (0)

Definition at line 816 of file pat.c.

#define KEY_MASK_IN_A_SEGMENT   0x3fffff

Definition at line 31 of file pat.c.

#define KEY_NEEDS_CONVERT (   pat,
  size 
)    (!((pat)->obj.header.flags & GRN_OBJ_KEY_VAR_SIZE) && (size) <= MAX_FIXED_KEY_SIZE)

Definition at line 764 of file pat.c.

#define MAX_FIXED_KEY_SIZE   (sizeof(int64_t))

Definition at line 762 of file pat.c.

#define MAX_LEVEL   16

Definition at line 162 of file pat.c.

#define nth_bit (   key,
  n,
 
)    ((((key)[(n)>>4]) >> (7 - (((n)>>1) & 7))) & 1)

Definition at line 105 of file pat.c.

#define PAT_AT (   pat,
  id,
 
)
Value:
do {\
int flags = 0;\
GRN_IO_ARRAY_AT(pat->io, segment_pat, id, &flags, n);\
} while (0)

Definition at line 111 of file pat.c.

#define PAT_CHK (   x)    ((x)->check)

Definition at line 84 of file pat.c.

#define PAT_CHK_SET (   x,
 
)    ((x)->check = (v))

Definition at line 90 of file pat.c.

#define PAT_DEL (   x)    ((x)->bits & PAT_DELETING)

Definition at line 81 of file pat.c.

#define PAT_DEL_OFF (   x)    ((x)->bits &= ~PAT_DELETING)

Definition at line 87 of file pat.c.

#define PAT_DEL_ON (   x)    ((x)->bits |= PAT_DELETING)

Definition at line 85 of file pat.c.

#define PAT_DELETING   (1<<1)

Definition at line 78 of file pat.c.

#define PAT_IMD (   x)    ((x)->bits & PAT_IMMEDIATE)

Definition at line 82 of file pat.c.

#define PAT_IMD_OFF (   x)    ((x)->bits &= ~PAT_IMMEDIATE)

Definition at line 88 of file pat.c.

#define PAT_IMD_ON (   x)    ((x)->bits |= PAT_IMMEDIATE)

Definition at line 86 of file pat.c.

#define PAT_IMMEDIATE   (1<<2)

Definition at line 79 of file pat.c.

#define PAT_LEN (   x)    (((x)->bits >> 3) + 1)

Definition at line 83 of file pat.c.

#define PAT_LEN_SET (   x,
 
)    ((x)->bits = ((x)->bits & ((1<<3) - 1))|(((v) - 1) << 3))

Definition at line 89 of file pat.c.

#define PAT_MASK_IN_A_SEGMENT   0x3ffff

Definition at line 32 of file pat.c.

#define RK_OUTPUT (   e,
 
)
Value:
do {\
if (oc < oe) {\
uint32_t l_ = (oc + (l) < oe) ? (l) : (oe - oc);\
memcpy(oc, (e), l_);\
oc += l_;\
ic_ = ic;\
}\
} while (0)

Definition at line 2770 of file pat.c.

#define SEG_NOT_ASSIGNED   0xffff

Definition at line 34 of file pat.c.

#define SIS_MASK_IN_A_SEGMENT   0x7ffff

Definition at line 33 of file pat.c.

#define W_OF_KEY_IN_A_SEGMENT   22

Definition at line 28 of file pat.c.

#define W_OF_PAT_IN_A_SEGMENT   18

Definition at line 29 of file pat.c.

#define W_OF_SIS_IN_A_SEGMENT   19

Definition at line 30 of file pat.c.

Enumeration Type Documentation

anonymous enum
Enumerator:
segment_key 
segment_pat 
segment_sis 

Definition at line 97 of file pat.c.

anonymous enum
Enumerator:
DL_EMPTY 
DL_PHASE1 
DL_PHASE2 

Definition at line 240 of file pat.c.

Function Documentation

const char* _grn_pat_key ( grn_ctx ctx,
grn_pat pat,
grn_id  id,
uint32_t *  key_size 
)

Definition at line 1250 of file pat.c.

Here is the caller graph for this function:

grn_id grn_pat_add ( grn_ctx ctx,
grn_pat pat,
const void *  key,
uint32_t  key_size,
void **  value,
int *  added 
)

Definition at line 824 of file pat.c.

grn_id grn_pat_at ( grn_ctx ctx,
grn_pat pat,
grn_id  id 
)

Definition at line 1527 of file pat.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void grn_pat_cache_disable ( grn_ctx ctx,
grn_pat pat 
)

Definition at line 494 of file pat.c.

Here is the caller graph for this function:

grn_rc grn_pat_cache_enable ( grn_ctx ctx,
grn_pat pat,
uint32_t  cache_size 
)

Definition at line 476 of file pat.c.

Here is the caller graph for this function:

void grn_pat_check ( grn_ctx ctx,
grn_pat pat 
)

Definition at line 2295 of file pat.c.

Here is the call graph for this function:

grn_rc grn_pat_close ( grn_ctx ctx,
grn_pat pat 
)

Definition at line 549 of file pat.c.

Here is the call graph for this function:

Here is the caller graph for this function:

grn_pat* grn_pat_create ( grn_ctx ctx,
const char *  path,
uint32_t  key_size,
uint32_t  value_size,
uint32_t  flags 
)

Definition at line 453 of file pat.c.

grn_id grn_pat_curr_id ( grn_ctx ctx,
grn_pat pat 
)

Definition at line 1536 of file pat.c.

Here is the caller graph for this function:

void grn_pat_cursor_close ( grn_ctx ctx,
grn_pat_cursor c 
)

Definition at line 1727 of file pat.c.

Here is the caller graph for this function:

grn_rc grn_pat_cursor_delete ( grn_ctx ctx,
grn_pat_cursor c,
grn_table_delete_optarg optarg 
)

Definition at line 2288 of file pat.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int grn_pat_cursor_get_key ( grn_ctx ctx,
grn_pat_cursor c,
void **  key 
)

Definition at line 2230 of file pat.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int grn_pat_cursor_get_key_value ( grn_ctx ctx,
grn_pat_cursor c,
void **  key,
uint32_t *  key_size,
void **  value 
)

Definition at line 2256 of file pat.c.

Here is the call graph for this function:

int grn_pat_cursor_get_value ( grn_ctx ctx,
grn_pat_cursor c,
void **  value 
)

Definition at line 2237 of file pat.c.

void grn_pat_cursor_inspect ( grn_ctx ctx,
grn_pat_cursor c,
grn_obj buf 
)

Definition at line 2436 of file pat.c.

Here is the call graph for this function:

Here is the caller graph for this function:

grn_id grn_pat_cursor_next ( grn_ctx ctx,
grn_pat_cursor c 
)

Definition at line 1660 of file pat.c.

Here is the caller graph for this function:

grn_pat_cursor* grn_pat_cursor_open ( grn_ctx ctx,
grn_pat pat,
const void *  min,
uint32_t  min_size,
const void *  max,
uint32_t  max_size,
int  offset,
int  limit,
int  flags 
)

Definition at line 2127 of file pat.c.

Here is the call graph for this function:

grn_rc grn_pat_cursor_set_value ( grn_ctx ctx,
grn_pat_cursor c,
const void *  value,
int  flags 
)

Definition at line 2281 of file pat.c.

Here is the call graph for this function:

Here is the caller graph for this function:

grn_rc grn_pat_delete ( grn_ctx ctx,
grn_pat pat,
const void *  key,
uint32_t  key_size,
grn_table_delete_optarg optarg 
)

Definition at line 1233 of file pat.c.

grn_rc grn_pat_delete_by_id ( grn_ctx ctx,
grn_pat pat,
grn_id  id,
grn_table_delete_optarg optarg 
)

Definition at line 1269 of file pat.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int grn_pat_delete_with_sis ( grn_ctx ctx,
grn_pat pat,
grn_id  id,
grn_table_delete_optarg optarg 
)

Definition at line 1437 of file pat.c.

Here is the call graph for this function:

grn_id grn_pat_get ( grn_ctx ctx,
grn_pat pat,
const void *  key,
uint32_t  key_size,
void **  value 
)

Definition at line 916 of file pat.c.

int grn_pat_get_key ( grn_ctx ctx,
grn_pat pat,
grn_id  id,
void *  keybuf,
int  bufsize 
)

Definition at line 1281 of file pat.c.

Here is the caller graph for this function:

int grn_pat_get_key2 ( grn_ctx ctx,
grn_pat pat,
grn_id  id,
grn_obj bulk 
)

Definition at line 1302 of file pat.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int grn_pat_get_value ( grn_ctx ctx,
grn_pat pat,
grn_id  id,
void *  valuebuf 
)

Definition at line 1333 of file pat.c.

Here is the caller graph for this function:

const char* grn_pat_get_value_ ( grn_ctx ctx,
grn_pat pat,
grn_id  id,
uint32_t *  size 
)

Definition at line 1353 of file pat.c.

Here is the caller graph for this function:

grn_rc grn_pat_info ( grn_ctx ctx,
grn_pat pat,
int *  key_size,
unsigned int *  flags,
grn_encoding encoding,
unsigned int *  n_entries,
unsigned int *  file_size 
)

Definition at line 1416 of file pat.c.

Here is the call graph for this function:

void grn_pat_inspect_nodes ( grn_ctx ctx,
grn_pat pat,
grn_obj buf 
)

Definition at line 2399 of file pat.c.

grn_id grn_pat_lcp_search ( grn_ctx ctx,
grn_pat pat,
const void *  key,
uint32_t  key_size 
)

Definition at line 1050 of file pat.c.

grn_id grn_pat_next ( grn_ctx ctx,
grn_pat pat,
grn_id  id 
)

Definition at line 1514 of file pat.c.

Here is the call graph for this function:

Here is the caller graph for this function:

grn_id grn_pat_nextid ( grn_ctx ctx,
grn_pat pat,
const void *  key,
uint32_t  key_size 
)

Definition at line 924 of file pat.c.

grn_pat* grn_pat_open ( grn_ctx ctx,
const char *  path 
)

Definition at line 504 of file pat.c.

Here is the call graph for this function:

Here is the caller graph for this function:

grn_rc grn_pat_prefix_search ( grn_ctx ctx,
grn_pat pat,
const void *  key,
uint32_t  key_size,
grn_hash h 
)

Definition at line 965 of file pat.c.

Here is the call graph for this function:

grn_hash* grn_pat_prefix_search2 ( grn_ctx ctx,
grn_pat pat,
const void *  key,
uint32_t  key_size 
)

Definition at line 1006 of file pat.c.

Here is the call graph for this function:

grn_rc grn_pat_remove ( grn_ctx ctx,
const char *  path 
)

Definition at line 562 of file pat.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int grn_pat_scan ( grn_ctx ctx,
grn_pat pat,
const char *  str,
unsigned int  str_len,
grn_pat_scan_hit sh,
unsigned int  sh_size,
const char **  rest 
)

Definition at line 1542 of file pat.c.

Here is the call graph for this function:

Here is the caller graph for this function:

grn_rc grn_pat_set_value ( grn_ctx ctx,
grn_pat pat,
grn_id  id,
const void *  value,
int  flags 
)

Definition at line 1366 of file pat.c.

Here is the caller graph for this function:

uint32_t grn_pat_size ( grn_ctx ctx,
grn_pat pat 
)

Definition at line 1243 of file pat.c.

Here is the caller graph for this function:

grn_rc grn_pat_suffix_search ( grn_ctx ctx,
grn_pat pat,
const void *  key,
uint32_t  key_size,
grn_hash h 
)

Definition at line 1020 of file pat.c.

Here is the call graph for this function:

grn_hash* grn_pat_suffix_search2 ( grn_ctx ctx,
grn_pat pat,
const void *  key,
uint32_t  key_size 
)

Definition at line 1036 of file pat.c.

Here is the call graph for this function:

grn_rc grn_pat_truncate ( grn_ctx ctx,
grn_pat pat 
)

Definition at line 572 of file pat.c.

Here is the call graph for this function:

Here is the caller graph for this function: