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 module groonga_d.hash; 19 20 21 private static import groonga_d.groonga; 22 23 extern(C): 24 nothrow @nogc: 25 26 enum GRN_HASH_TINY = 0x01 << 6; 27 28 extern struct _grn_hash; 29 extern struct _grn_hash_cursor; 30 31 alias grn_hash = _grn_hash; 32 alias grn_hash_cursor = _grn_hash_cursor; 33 34 //GRN_API 35 grn_hash* grn_hash_create(groonga_d.groonga.grn_ctx* ctx, const (char)* path, uint key_size, uint value_size, uint flags); 36 37 //GRN_API 38 grn_hash* grn_hash_open(groonga_d.groonga.grn_ctx* ctx, const (char)* path); 39 40 //GRN_API 41 groonga_d.groonga.grn_rc grn_hash_close(groonga_d.groonga.grn_ctx* ctx, grn_hash* hash); 42 43 //GRN_API 44 groonga_d.groonga.grn_id grn_hash_add(groonga_d.groonga.grn_ctx* ctx, grn_hash* hash, const (void)* key, uint key_size, void** value, int* added); 45 46 //GRN_API 47 groonga_d.groonga.grn_id grn_hash_get(groonga_d.groonga.grn_ctx* ctx, grn_hash* hash, const (void)* key, uint key_size, void** value); 48 49 //GRN_API 50 int grn_hash_get_key(groonga_d.groonga.grn_ctx* ctx, grn_hash* hash, groonga_d.groonga.grn_id id, void* keybuf, int bufsize); 51 52 //GRN_API 53 int grn_hash_get_key2(groonga_d.groonga.grn_ctx* ctx, grn_hash* hash, groonga_d.groonga.grn_id id, groonga_d.groonga.grn_obj* bulk); 54 55 //GRN_API 56 int grn_hash_get_value(groonga_d.groonga.grn_ctx* ctx, grn_hash* hash, groonga_d.groonga.grn_id id, void* valuebuf); 57 58 //GRN_API 59 groonga_d.groonga.grn_rc grn_hash_set_value(groonga_d.groonga.grn_ctx* ctx, grn_hash* hash, groonga_d.groonga.grn_id id, const (void)* value, int flags); 60 61 //GRN_API 62 groonga_d.groonga.grn_rc grn_hash_delete_by_id(groonga_d.groonga.grn_ctx* ctx, grn_hash* hash, groonga_d.groonga.grn_id id, groonga_d.groonga.grn_table_delete_optarg* optarg); 63 64 //GRN_API 65 groonga_d.groonga.grn_rc grn_hash_delete(groonga_d.groonga.grn_ctx* ctx, grn_hash* hash, const (void)* key, uint key_size, groonga_d.groonga.grn_table_delete_optarg* optarg); 66 67 //GRN_API 68 uint grn_hash_size(groonga_d.groonga.grn_ctx* ctx, grn_hash* hash); 69 70 //GRN_API 71 grn_hash_cursor* grn_hash_cursor_open(groonga_d.groonga.grn_ctx* ctx, grn_hash* hash, const (void)* min, uint min_size, const (void)* max, uint max_size, int offset, int limit, int flags); 72 73 //GRN_API 74 groonga_d.groonga.grn_id grn_hash_cursor_next(groonga_d.groonga.grn_ctx* ctx, grn_hash_cursor* c); 75 76 //GRN_API 77 void grn_hash_cursor_close(groonga_d.groonga.grn_ctx* ctx, grn_hash_cursor* c); 78 79 //GRN_API 80 int grn_hash_cursor_get_key(groonga_d.groonga.grn_ctx* ctx, grn_hash_cursor* c, void** key); 81 82 //GRN_API 83 int grn_hash_cursor_get_value(groonga_d.groonga.grn_ctx* ctx, grn_hash_cursor* c, void** value); 84 85 //GRN_API 86 groonga_d.groonga.grn_rc grn_hash_cursor_set_value(groonga_d.groonga.grn_ctx* ctx, grn_hash_cursor* c, const (void)* value, int flags); 87 88 //GRN_API 89 int grn_hash_cursor_get_key_value(groonga_d.groonga.grn_ctx* ctx, grn_hash_cursor* c, void** key, uint* key_size, void** value); 90 91 //GRN_API 92 groonga_d.groonga.grn_rc grn_hash_cursor_delete(groonga_d.groonga.grn_ctx* ctx, grn_hash_cursor* c, groonga_d.groonga.grn_table_delete_optarg* optarg); 93 94 /+ 95 #define GRN_HASH_EACH(ctx, hash, id, key, key_size, value, block) grn_hash_cursor *_sc = grn_hash_cursor_open(ctx, hash, null, 0, null, 0, 0, -1, 0); if (_sc) { groonga_d.groonga.grn_id id; while ((id = grn_hash_cursor_next(ctx, _sc))) { grn_hash_cursor_get_key_value(ctx, _sc, (void **)(key), (key_size), (void **)(value)); block } grn_hash_cursor_close(ctx, _sc); } 96 97 #define GRN_HASH_EACH_BEGIN(ctx, hash, cursor, id) do { grn_hash_cursor *cursor; cursor = grn_hash_cursor_open((ctx), (hash), null, 0, null, 0, 0, -1, GRN_CURSOR_BY_ID); if (cursor) { groonga_d.groonga.grn_id id; while ((id = grn_hash_cursor_next((ctx), cursor)) != groonga_d.groonga.GRN_ID_NIL) { 98 99 #define GRN_HASH_EACH_END(ctx, cursor) } grn_hash_cursor_close((ctx), cursor); } } while(0) 100 +/