| 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 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | typedef struct _grn_dat grn_dat; |
| 26 | typedef struct _grn_dat_cursor grn_dat_cursor; |
| 27 | typedef struct _grn_table_scan_hit grn_dat_scan_hit; |
| 28 | |
| 29 | GRN_API int grn_dat_scan(grn_ctx *ctx, grn_dat *dat, const char *str, |
| 30 | unsigned int str_size, grn_dat_scan_hit *scan_hits, |
| 31 | unsigned int max_num_scan_hits, const char **str_rest); |
| 32 | |
| 33 | GRN_API grn_id grn_dat_lcp_search(grn_ctx *ctx, grn_dat *dat, |
| 34 | const void *key, unsigned int key_size); |
| 35 | |
| 36 | GRN_API grn_dat *grn_dat_create(grn_ctx *ctx, const char *path, unsigned int key_size, |
| 37 | unsigned int value_size, unsigned int flags); |
| 38 | |
| 39 | GRN_API grn_dat *grn_dat_open(grn_ctx *ctx, const char *path); |
| 40 | |
| 41 | GRN_API grn_rc grn_dat_close(grn_ctx *ctx, grn_dat *dat); |
| 42 | |
| 43 | GRN_API grn_rc grn_dat_remove(grn_ctx *ctx, const char *path); |
| 44 | |
| 45 | GRN_API grn_id grn_dat_get(grn_ctx *ctx, grn_dat *dat, const void *key, |
| 46 | unsigned int key_size, void **value); |
| 47 | GRN_API grn_id grn_dat_add(grn_ctx *ctx, grn_dat *dat, const void *key, |
| 48 | unsigned int key_size, void **value, int *added); |
| 49 | |
| 50 | GRN_API int grn_dat_get_key(grn_ctx *ctx, grn_dat *dat, grn_id id, void *keybuf, int bufsize); |
| 51 | GRN_API int grn_dat_get_key2(grn_ctx *ctx, grn_dat *dat, grn_id id, grn_obj *bulk); |
| 52 | |
| 53 | GRN_API grn_rc grn_dat_delete_by_id(grn_ctx *ctx, grn_dat *dat, grn_id id, |
| 54 | grn_table_delete_optarg *optarg); |
| 55 | GRN_API grn_rc grn_dat_delete(grn_ctx *ctx, grn_dat *dat, const void *key, unsigned int key_size, |
| 56 | grn_table_delete_optarg *optarg); |
| 57 | |
| 58 | GRN_API grn_rc grn_dat_update_by_id(grn_ctx *ctx, grn_dat *dat, grn_id src_key_id, |
| 59 | const void *dest_key, unsigned int dest_key_size); |
| 60 | GRN_API grn_rc grn_dat_update(grn_ctx *ctx, grn_dat *dat, |
| 61 | const void *src_key, unsigned int src_key_size, |
| 62 | const void *dest_key, unsigned int dest_key_size); |
| 63 | |
| 64 | GRN_API unsigned int grn_dat_size(grn_ctx *ctx, grn_dat *dat); |
| 65 | |
| 66 | GRN_API grn_dat_cursor *grn_dat_cursor_open(grn_ctx *ctx, grn_dat *dat, |
| 67 | const void *min, unsigned int min_size, |
| 68 | const void *max, unsigned int max_size, |
| 69 | int offset, int limit, int flags); |
| 70 | GRN_API grn_id grn_dat_cursor_next(grn_ctx *ctx, grn_dat_cursor *c); |
| 71 | GRN_API void grn_dat_cursor_close(grn_ctx *ctx, grn_dat_cursor *c); |
| 72 | |
| 73 | GRN_API int grn_dat_cursor_get_key(grn_ctx *ctx, grn_dat_cursor *c, const void **key); |
| 74 | GRN_API grn_rc grn_dat_cursor_delete(grn_ctx *ctx, grn_dat_cursor *c, |
| 75 | grn_table_delete_optarg *optarg); |
| 76 | |
| 77 | #define GRN_DAT_EACH(ctx,dat,id,key,key_size,block) do {\ |
| 78 | grn_dat_cursor *_sc = grn_dat_cursor_open(ctx, dat, NULL, 0, NULL, 0, 0, -1, 0);\ |
| 79 | if (_sc) {\ |
| 80 | grn_id id;\ |
| 81 | unsigned int *_ks = (key_size);\ |
| 82 | if (_ks) {\ |
| 83 | while ((id = grn_dat_cursor_next(ctx, _sc))) {\ |
| 84 | int _ks_raw = grn_dat_cursor_get_key(ctx, _sc, (const void **)(key));\ |
| 85 | *(_ks) = (unsigned int)_ks_raw;\ |
| 86 | block\ |
| 87 | }\ |
| 88 | } else {\ |
| 89 | while ((id = grn_dat_cursor_next(ctx, _sc))) {\ |
| 90 | grn_dat_cursor_get_key(ctx, _sc, (const void **)(key));\ |
| 91 | block\ |
| 92 | }\ |
| 93 | }\ |
| 94 | grn_dat_cursor_close(ctx, _sc);\ |
| 95 | }\ |
| 96 | } while (0) |
| 97 | |
| 98 | #ifdef __cplusplus |
| 99 | } |
| 100 | #endif |
| 101 | |