| 1 | /* -*- c-basic-offset: 2 -*- */ |
| 2 | /* |
| 3 | Copyright(C) 2009-2016 Brazil |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License version 2.1 as published by the Free Software Foundation. |
| 8 | |
| 9 | This library is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | Lesser General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public |
| 15 | License along with this library; if not, write to the Free Software |
| 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include "grn.h" |
| 22 | #include "grn_db.h" |
| 23 | #include "grn_hash.h" |
| 24 | |
| 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
| 29 | #define GRN_PAT_MAX_KEY_SIZE GRN_TABLE_MAX_KEY_SIZE |
| 30 | #define GRN_PAT_MAX_TOTAL_KEY_SIZE (UINT32_MAX - 1) |
| 31 | |
| 32 | struct _grn_pat { |
| 33 | grn_db_obj obj; |
| 34 | grn_io *io; |
| 35 | struct grn_pat_header *; |
| 36 | grn_encoding encoding; |
| 37 | uint32_t key_size; |
| 38 | uint32_t value_size; |
| 39 | grn_obj *tokenizer; |
| 40 | grn_obj *normalizer; |
| 41 | grn_obj token_filters; |
| 42 | grn_id *cache; |
| 43 | uint32_t cache_size; |
| 44 | grn_bool is_dirty; |
| 45 | grn_critical_section lock; |
| 46 | }; |
| 47 | |
| 48 | #define GRN_PAT_NDELINFOS 0x100 |
| 49 | |
| 50 | typedef struct { |
| 51 | grn_id d; /* The ID of a deleting node. */ |
| 52 | grn_id ld; /* The ID of the parent node of a deleting node. */ |
| 53 | /* delinfo->ld is set if required. */ |
| 54 | uint32_t stat; /* DL_EMPTY, DL_PHASE1, or DL_PHASE2. */ |
| 55 | uint32_t shared; /* This flag is used if GRN_OBJ_KEY_WITH_SIS is set. */ |
| 56 | } grn_pat_delinfo; |
| 57 | |
| 58 | struct { |
| 59 | uint32_t ; |
| 60 | grn_encoding ; |
| 61 | uint32_t ; |
| 62 | uint32_t ; |
| 63 | grn_id ; |
| 64 | uint32_t ; |
| 65 | uint32_t ; |
| 66 | int32_t ; |
| 67 | int32_t ; |
| 68 | int32_t ; |
| 69 | int32_t ; |
| 70 | uint32_t ; |
| 71 | grn_id ; |
| 72 | uint32_t ; |
| 73 | uint32_t ; |
| 74 | uint32_t [1002]; |
| 75 | grn_pat_delinfo [GRN_PAT_NDELINFOS]; |
| 76 | grn_id [GRN_PAT_MAX_KEY_SIZE + 1]; |
| 77 | }; |
| 78 | |
| 79 | struct _grn_pat_cursor_entry { |
| 80 | grn_id id; |
| 81 | uint16_t check; |
| 82 | }; |
| 83 | |
| 84 | typedef struct _grn_pat_cursor_entry grn_pat_cursor_entry; |
| 85 | |
| 86 | struct _grn_pat_cursor { |
| 87 | grn_db_obj obj; |
| 88 | grn_id curr_rec; /* ID of the latest record */ |
| 89 | grn_pat *pat; |
| 90 | grn_ctx *ctx; |
| 91 | unsigned int size; /* stack size (the maximum number of entries) */ |
| 92 | unsigned int sp; /* stack pointer (the number of entries) */ |
| 93 | grn_id tail; /* sentinel (the end of the traversal) */ |
| 94 | unsigned int rest; /* limit rest (the number of remaining records) */ |
| 95 | grn_pat_cursor_entry *ss; /* stack buffer (pointer to entries) */ |
| 96 | uint8_t curr_key[GRN_TABLE_MAX_KEY_SIZE]; |
| 97 | }; |
| 98 | |
| 99 | GRN_API grn_id grn_pat_curr_id(grn_ctx *ctx, grn_pat *pat); |
| 100 | |
| 101 | /* private */ |
| 102 | GRN_API grn_rc grn_pat_truncate(grn_ctx *ctx, grn_pat *pat); |
| 103 | const char *_grn_pat_key(grn_ctx *ctx, grn_pat *pat, grn_id id, uint32_t *key_size); |
| 104 | grn_id grn_pat_next(grn_ctx *ctx, grn_pat *pat, grn_id id); |
| 105 | const char *grn_pat_get_value_(grn_ctx *ctx, grn_pat *pat, grn_id id, uint32_t *size); |
| 106 | GRN_API grn_id grn_pat_at(grn_ctx *ctx, grn_pat *pat, grn_id id); |
| 107 | void grn_pat_check(grn_ctx *ctx, grn_pat *pat); |
| 108 | void grn_pat_inspect_nodes(grn_ctx *ctx, grn_pat *pat, grn_obj *buf); |
| 109 | void grn_pat_cursor_inspect(grn_ctx *ctx, grn_pat_cursor *c, grn_obj *buf); |
| 110 | |
| 111 | grn_rc grn_pat_cache_enable(grn_ctx *ctx, grn_pat *pat, uint32_t cache_size); |
| 112 | void grn_pat_cache_disable(grn_ctx *ctx, grn_pat *pat); |
| 113 | |
| 114 | GRN_API grn_rc grn_pat_fuzzy_search(grn_ctx *ctx, grn_pat *pat, |
| 115 | const void *key, unsigned int key_size, |
| 116 | grn_fuzzy_search_optarg *args, grn_hash *h); |
| 117 | |
| 118 | uint32_t grn_pat_total_key_size(grn_ctx *ctx, grn_pat *pat); |
| 119 | |
| 120 | grn_bool grn_pat_is_key_encoded(grn_ctx *ctx, grn_pat *pat); |
| 121 | |
| 122 | grn_rc grn_pat_dirty(grn_ctx *ctx, grn_pat *pat); |
| 123 | grn_bool grn_pat_is_dirty(grn_ctx *ctx, grn_pat *pat); |
| 124 | grn_rc grn_pat_clean(grn_ctx *ctx, grn_pat *pat); |
| 125 | grn_rc grn_pat_clear_dirty(grn_ctx *ctx, grn_pat *pat); |
| 126 | |
| 127 | #ifdef __cplusplus |
| 128 | } |
| 129 | #endif |
| 130 | |