| 1 | /* |
| 2 | Copyright(C) 2009-2016 Brazil |
| 3 | |
| 4 | This library is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU Lesser General Public |
| 6 | License as published by the Free Software Foundation; either |
| 7 | version 2.1 of the License, or (at your option) any later version. |
| 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 "hash.h" |
| 22 | |
| 23 | #ifdef __cplusplus |
| 24 | extern "C" { |
| 25 | #endif |
| 26 | |
| 27 | typedef struct _grn_pat grn_pat; |
| 28 | typedef struct _grn_pat_cursor grn_pat_cursor; |
| 29 | typedef struct _grn_table_scan_hit grn_pat_scan_hit; |
| 30 | |
| 31 | GRN_API grn_pat *grn_pat_create(grn_ctx *ctx, const char *path, unsigned int key_size, |
| 32 | unsigned int value_size, unsigned int flags); |
| 33 | |
| 34 | GRN_API grn_pat *grn_pat_open(grn_ctx *ctx, const char *path); |
| 35 | |
| 36 | GRN_API grn_rc grn_pat_close(grn_ctx *ctx, grn_pat *pat); |
| 37 | |
| 38 | GRN_API grn_rc grn_pat_remove(grn_ctx *ctx, const char *path); |
| 39 | |
| 40 | GRN_API grn_id grn_pat_get(grn_ctx *ctx, grn_pat *pat, const void *key, |
| 41 | unsigned int key_size, void **value); |
| 42 | GRN_API grn_id grn_pat_add(grn_ctx *ctx, grn_pat *pat, const void *key, |
| 43 | unsigned int key_size, void **value, int *added); |
| 44 | |
| 45 | GRN_API int grn_pat_get_key(grn_ctx *ctx, grn_pat *pat, grn_id id, void *keybuf, int bufsize); |
| 46 | GRN_API int grn_pat_get_key2(grn_ctx *ctx, grn_pat *pat, grn_id id, grn_obj *bulk); |
| 47 | GRN_API int grn_pat_get_value(grn_ctx *ctx, grn_pat *pat, grn_id id, void *valuebuf); |
| 48 | GRN_API grn_rc grn_pat_set_value(grn_ctx *ctx, grn_pat *pat, grn_id id, |
| 49 | const void *value, int flags); |
| 50 | |
| 51 | GRN_API grn_rc grn_pat_delete_by_id(grn_ctx *ctx, grn_pat *pat, grn_id id, |
| 52 | grn_table_delete_optarg *optarg); |
| 53 | GRN_API grn_rc grn_pat_delete(grn_ctx *ctx, grn_pat *pat, const void *key, unsigned int key_size, |
| 54 | grn_table_delete_optarg *optarg); |
| 55 | GRN_API int grn_pat_delete_with_sis(grn_ctx *ctx, grn_pat *pat, grn_id id, |
| 56 | grn_table_delete_optarg *optarg); |
| 57 | |
| 58 | GRN_API int grn_pat_scan(grn_ctx *ctx, grn_pat *pat, const char *str, unsigned int str_len, |
| 59 | grn_pat_scan_hit *sh, unsigned int sh_size, const char **rest); |
| 60 | |
| 61 | GRN_API grn_rc grn_pat_prefix_search(grn_ctx *ctx, grn_pat *pat, |
| 62 | const void *key, unsigned int key_size, grn_hash *h); |
| 63 | GRN_API grn_rc grn_pat_suffix_search(grn_ctx *ctx, grn_pat *pat, |
| 64 | const void *key, unsigned int key_size, grn_hash *h); |
| 65 | GRN_API grn_id grn_pat_lcp_search(grn_ctx *ctx, grn_pat *pat, |
| 66 | const void *key, unsigned int key_size); |
| 67 | |
| 68 | GRN_API unsigned int grn_pat_size(grn_ctx *ctx, grn_pat *pat); |
| 69 | |
| 70 | GRN_API grn_pat_cursor *grn_pat_cursor_open(grn_ctx *ctx, grn_pat *pat, |
| 71 | const void *min, unsigned int min_size, |
| 72 | const void *max, unsigned int max_size, |
| 73 | int offset, int limit, int flags); |
| 74 | GRN_API grn_id grn_pat_cursor_next(grn_ctx *ctx, grn_pat_cursor *c); |
| 75 | GRN_API void grn_pat_cursor_close(grn_ctx *ctx, grn_pat_cursor *c); |
| 76 | |
| 77 | GRN_API int grn_pat_cursor_get_key(grn_ctx *ctx, grn_pat_cursor *c, void **key); |
| 78 | GRN_API int grn_pat_cursor_get_value(grn_ctx *ctx, grn_pat_cursor *c, void **value); |
| 79 | |
| 80 | GRN_API int grn_pat_cursor_get_key_value(grn_ctx *ctx, grn_pat_cursor *c, |
| 81 | void **key, unsigned int *key_size, void **value); |
| 82 | GRN_API grn_rc grn_pat_cursor_set_value(grn_ctx *ctx, grn_pat_cursor *c, |
| 83 | const void *value, int flags); |
| 84 | GRN_API grn_rc grn_pat_cursor_delete(grn_ctx *ctx, grn_pat_cursor *c, |
| 85 | grn_table_delete_optarg *optarg); |
| 86 | |
| 87 | #define GRN_PAT_EACH(ctx,pat,id,key,key_size,value,block) do { \ |
| 88 | grn_pat_cursor *_sc = grn_pat_cursor_open(ctx, pat, NULL, 0, NULL, 0, 0, -1, 0); \ |
| 89 | if (_sc) {\ |
| 90 | grn_id id;\ |
| 91 | while ((id = grn_pat_cursor_next(ctx, _sc))) {\ |
| 92 | grn_pat_cursor_get_key_value(ctx, _sc, (void **)(key),\ |
| 93 | (key_size), (void **)(value));\ |
| 94 | block\ |
| 95 | }\ |
| 96 | grn_pat_cursor_close(ctx, _sc);\ |
| 97 | }\ |
| 98 | } while (0) |
| 99 | |
| 100 | #ifdef __cplusplus |
| 101 | } |
| 102 | #endif |
| 103 | |