tokyocabinet-ruby-1.31/0000755000175000017500000000000011547412351013267 5ustar spkspktokyocabinet-ruby-1.31/tokyocabinet.c0000644000175000017500000035151611547412351016141 0ustar spkspk/************************************************************************************************* * Ruby binding of Tokyo Cabinet * Copyright (C) 2006-2010 FAL Labs * This file is part of Tokyo Cabinet. * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * You should have received a copy of the GNU Lesser General Public License along with Tokyo * Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA. *************************************************************************************************/ #include "ruby.h" #include #include #include #include #include #include #include #include #include #include #include #define HDBVNDATA "@hdb" #define BDBVNDATA "@bdb" #define BDBCURVNDATA "@bdbcur" #define FDBVNDATA "@fdb" #define TDBVNDATA "@tdb" #define TDBQRYVNDATA "@tdbqry" #define ADBVNDATA "@adb" #define NUMBUFSIZ 32 #if !defined(RSTRING_PTR) #define RSTRING_PTR(TC_s) (RSTRING(TC_s)->ptr) #endif #if !defined(RSTRING_LEN) #define RSTRING_LEN(TC_s) (RSTRING(TC_s)->len) #endif #if !defined(RARRAY_LEN) #define RARRAY_LEN(TC_a) (RARRAY(TC_a)->len) #endif /* private function prototypes */ static VALUE StringValueEx(VALUE vobj); static TCLIST *varytolist(VALUE vary); static VALUE listtovary(TCLIST *list); static TCMAP *vhashtomap(VALUE vhash); static VALUE maptovhash(TCMAP *map); static void hdb_init(void); static VALUE hdb_initialize(VALUE vself); static VALUE hdb_errmsg(int argc, VALUE *argv, VALUE vself); static VALUE hdb_ecode(VALUE vself); static VALUE hdb_tune(int argc, VALUE *argv, VALUE vself); static VALUE hdb_setcache(int argc, VALUE *argv, VALUE vself); static VALUE hdb_setxmsiz(int argc, VALUE *argv, VALUE vself); static VALUE hdb_setdfunit(int argc, VALUE *argv, VALUE vself); static VALUE hdb_open(int argc, VALUE *argv, VALUE vself); static VALUE hdb_close(VALUE vself); static VALUE hdb_put(VALUE vself, VALUE vkey, VALUE vval); static VALUE hdb_putkeep(VALUE vself, VALUE vkey, VALUE vval); static VALUE hdb_putcat(VALUE vself, VALUE vkey, VALUE vval); static VALUE hdb_putasync(VALUE vself, VALUE vkey, VALUE vval); static VALUE hdb_out(VALUE vself, VALUE vkey); static VALUE hdb_get(VALUE vself, VALUE vkey); static VALUE hdb_vsiz(VALUE vself, VALUE vkey); static VALUE hdb_iterinit(VALUE vself); static VALUE hdb_iternext(VALUE vself); static VALUE hdb_fwmkeys(int argc, VALUE *argv, VALUE vself); static VALUE hdb_addint(VALUE vself, VALUE vkey, VALUE vnum); static VALUE hdb_adddouble(VALUE vself, VALUE vkey, VALUE vnum); static VALUE hdb_sync(VALUE vself); static VALUE hdb_optimize(int argc, VALUE *argv, VALUE vself); static VALUE hdb_vanish(VALUE vself); static VALUE hdb_copy(VALUE vself, VALUE vpath); static VALUE hdb_tranbegin(VALUE vself); static VALUE hdb_trancommit(VALUE vself); static VALUE hdb_tranabort(VALUE vself); static VALUE hdb_path(VALUE vself); static VALUE hdb_rnum(VALUE vself); static VALUE hdb_fsiz(VALUE vself); static VALUE hdb_fetch(int argc, VALUE *argv, VALUE vself); static VALUE hdb_check(VALUE vself, VALUE vkey); static VALUE hdb_check_value(VALUE vself, VALUE vval); static VALUE hdb_get_reverse(VALUE vself, VALUE vval); static VALUE hdb_empty(VALUE vself); static VALUE hdb_each(VALUE vself); static VALUE hdb_each_key(VALUE vself); static VALUE hdb_each_value(VALUE vself); static VALUE hdb_keys(VALUE vself); static VALUE hdb_values(VALUE vself); static void bdb_init(void); static int bdb_cmpobj(const char *aptr, int asiz, const char *bptr, int bsiz, VALUE vcmp); static VALUE bdb_initialize(VALUE vself); static VALUE bdb_errmsg(int argc, VALUE *argv, VALUE vself); static VALUE bdb_ecode(VALUE vself); static VALUE bdb_setcmpfunc(VALUE vself, VALUE vcmp); static VALUE bdb_tune(int argc, VALUE *argv, VALUE vself); static VALUE bdb_setcache(int argc, VALUE *argv, VALUE vself); static VALUE bdb_setxmsiz(int argc, VALUE *argv, VALUE vself); static VALUE bdb_setdfunit(int argc, VALUE *argv, VALUE vself); static VALUE bdb_open(int argc, VALUE *argv, VALUE vself); static VALUE bdb_close(VALUE vself); static VALUE bdb_put(VALUE vself, VALUE vkey, VALUE vval); static VALUE bdb_putkeep(VALUE vself, VALUE vkey, VALUE vval); static VALUE bdb_putcat(VALUE vself, VALUE vkey, VALUE vval); static VALUE bdb_putdup(VALUE vself, VALUE vkey, VALUE vval); static VALUE bdb_putlist(VALUE vself, VALUE vkey, VALUE vvals); static VALUE bdb_out(VALUE vself, VALUE vkey); static VALUE bdb_outlist(VALUE vself, VALUE vkey); static VALUE bdb_get(VALUE vself, VALUE vkey); static VALUE bdb_getlist(VALUE vself, VALUE vkey); static VALUE bdb_vnum(VALUE vself, VALUE vkey); static VALUE bdb_vsiz(VALUE vself, VALUE vkey); static VALUE bdb_range(int argc, VALUE *argv, VALUE vself); static VALUE bdb_fwmkeys(int argc, VALUE *argv, VALUE vself); static VALUE bdb_addint(VALUE vself, VALUE vkey, VALUE vnum); static VALUE bdb_adddouble(VALUE vself, VALUE vkey, VALUE vnum); static VALUE bdb_sync(VALUE vself); static VALUE bdb_optimize(int argc, VALUE *argv, VALUE vself); static VALUE bdb_vanish(VALUE vself); static VALUE bdb_copy(VALUE vself, VALUE vpath); static VALUE bdb_tranbegin(VALUE vself); static VALUE bdb_trancommit(VALUE vself); static VALUE bdb_tranabort(VALUE vself); static VALUE bdb_path(VALUE vself); static VALUE bdb_rnum(VALUE vself); static VALUE bdb_fsiz(VALUE vself); static VALUE bdb_fetch(int argc, VALUE *argv, VALUE vself); static VALUE bdb_check(VALUE vself, VALUE vkey); static VALUE bdb_check_value(VALUE vself, VALUE vval); static VALUE bdb_get_reverse(VALUE vself, VALUE vval); static VALUE bdb_empty(VALUE vself); static VALUE bdb_each(VALUE vself); static VALUE bdb_each_key(VALUE vself); static VALUE bdb_each_value(VALUE vself); static VALUE bdb_keys(VALUE vself); static VALUE bdb_values(VALUE vself); static void bdbcur_init(void); static VALUE bdbcur_initialize(VALUE vself, VALUE vbdb); static VALUE bdbcur_first(VALUE vself); static VALUE bdbcur_last(VALUE vself); static VALUE bdbcur_jump(VALUE vself, VALUE vkey); static VALUE bdbcur_prev(VALUE vself); static VALUE bdbcur_next(VALUE vself); static VALUE bdbcur_put(int argc, VALUE *argv, VALUE vself); static VALUE bdbcur_out(VALUE vself); static VALUE bdbcur_key(VALUE vself); static VALUE bdbcur_val(VALUE vself); static void fdb_init(void); static VALUE fdb_initialize(VALUE vself); static VALUE fdb_errmsg(int argc, VALUE *argv, VALUE vself); static VALUE fdb_ecode(VALUE vself); static VALUE fdb_tune(int argc, VALUE *argv, VALUE vself); static VALUE fdb_open(int argc, VALUE *argv, VALUE vself); static VALUE fdb_close(VALUE vself); static VALUE fdb_put(VALUE vself, VALUE vkey, VALUE vval); static VALUE fdb_putkeep(VALUE vself, VALUE vkey, VALUE vval); static VALUE fdb_putcat(VALUE vself, VALUE vkey, VALUE vval); static VALUE fdb_out(VALUE vself, VALUE vkey); static VALUE fdb_get(VALUE vself, VALUE vkey); static VALUE fdb_vsiz(VALUE vself, VALUE vkey); static VALUE fdb_iterinit(VALUE vself); static VALUE fdb_iternext(VALUE vself); static VALUE fdb_range(int argc, VALUE *argv, VALUE vself); static VALUE fdb_addint(VALUE vself, VALUE vkey, VALUE vnum); static VALUE fdb_adddouble(VALUE vself, VALUE vkey, VALUE vnum); static VALUE fdb_sync(VALUE vself); static VALUE fdb_optimize(int argc, VALUE *argv, VALUE vself); static VALUE fdb_vanish(VALUE vself); static VALUE fdb_copy(VALUE vself, VALUE vpath); static VALUE fdb_tranbegin(VALUE vself); static VALUE fdb_trancommit(VALUE vself); static VALUE fdb_tranabort(VALUE vself); static VALUE fdb_path(VALUE vself); static VALUE fdb_rnum(VALUE vself); static VALUE fdb_fsiz(VALUE vself); static VALUE fdb_fetch(int argc, VALUE *argv, VALUE vself); static VALUE fdb_check(VALUE vself, VALUE vkey); static VALUE fdb_check_value(VALUE vself, VALUE vval); static VALUE fdb_get_reverse(VALUE vself, VALUE vval); static VALUE fdb_empty(VALUE vself); static VALUE fdb_each(VALUE vself); static VALUE fdb_each_key(VALUE vself); static VALUE fdb_each_value(VALUE vself); static VALUE fdb_keys(VALUE vself); static VALUE fdb_values(VALUE vself); static void tdb_init(void); static VALUE tdb_initialize(VALUE vself); static VALUE tdb_errmsg(int argc, VALUE *argv, VALUE vself); static VALUE tdb_ecode(VALUE vself); static VALUE tdb_tune(int argc, VALUE *argv, VALUE vself); static VALUE tdb_setcache(int argc, VALUE *argv, VALUE vself); static VALUE tdb_setxmsiz(int argc, VALUE *argv, VALUE vself); static VALUE tdb_setdfunit(int argc, VALUE *argv, VALUE vself); static VALUE tdb_open(int argc, VALUE *argv, VALUE vself); static VALUE tdb_close(VALUE vself); static VALUE tdb_put(VALUE vself, VALUE vkey, VALUE vcols); static VALUE tdb_putkeep(VALUE vself, VALUE vkey, VALUE vcols); static VALUE tdb_putcat(VALUE vself, VALUE vkey, VALUE vcols); static VALUE tdb_out(VALUE vself, VALUE vkey); static VALUE tdb_get(VALUE vself, VALUE vkey); static VALUE tdb_vsiz(VALUE vself, VALUE vkey); static VALUE tdb_iterinit(VALUE vself); static VALUE tdb_iternext(VALUE vself); static VALUE tdb_fwmkeys(int argc, VALUE *argv, VALUE vself); static VALUE tdb_addint(VALUE vself, VALUE vkey, VALUE vnum); static VALUE tdb_adddouble(VALUE vself, VALUE vkey, VALUE vnum); static VALUE tdb_sync(VALUE vself); static VALUE tdb_optimize(int argc, VALUE *argv, VALUE vself); static VALUE tdb_vanish(VALUE vself); static VALUE tdb_copy(VALUE vself, VALUE vpath); static VALUE tdb_tranbegin(VALUE vself); static VALUE tdb_trancommit(VALUE vself); static VALUE tdb_tranabort(VALUE vself); static VALUE tdb_path(VALUE vself); static VALUE tdb_rnum(VALUE vself); static VALUE tdb_fsiz(VALUE vself); static VALUE tdb_setindex(VALUE vself, VALUE vname, VALUE vtype); static VALUE tdb_genuid(VALUE vself); static VALUE tdb_fetch(int argc, VALUE *argv, VALUE vself); static VALUE tdb_check(VALUE vself, VALUE vkey); static VALUE tdb_empty(VALUE vself); static VALUE tdb_each(VALUE vself); static VALUE tdb_each_key(VALUE vself); static VALUE tdb_each_value(VALUE vself); static VALUE tdb_keys(VALUE vself); static VALUE tdb_values(VALUE vself); static void tdbqry_init(void); static int tdbqry_procrec(const void *pkbuf, int pksiz, TCMAP *cols, void *opq); static VALUE tdbqry_initialize(VALUE vself, VALUE vtdb); static VALUE tdbqry_addcond(VALUE vself, VALUE vname, VALUE vop, VALUE vexpr); static VALUE tdbqry_setorder(int argc, VALUE *argv, VALUE vself); static VALUE tdbqry_setlimit(int argc, VALUE *argv, VALUE vself); static VALUE tdbqry_search(VALUE vself); static VALUE tdbqry_searchout(VALUE vself); static VALUE tdbqry_proc(VALUE vself, VALUE vproc); static VALUE tdbqry_hint(VALUE vself); static VALUE tdbqry_metasearch(int argc, VALUE *argv, VALUE vself); static VALUE tdbqry_kwic(int argc, VALUE *argv, VALUE vself); static void adb_init(void); static VALUE adb_initialize(VALUE vself); static VALUE adb_open(VALUE vself, VALUE vname); static VALUE adb_close(VALUE vself); static VALUE adb_put(VALUE vself, VALUE vkey, VALUE vval); static VALUE adb_putkeep(VALUE vself, VALUE vkey, VALUE vval); static VALUE adb_putcat(VALUE vself, VALUE vkey, VALUE vval); static VALUE adb_out(VALUE vself, VALUE vkey); static VALUE adb_get(VALUE vself, VALUE vkey); static VALUE adb_vsiz(VALUE vself, VALUE vkey); static VALUE adb_iterinit(VALUE vself); static VALUE adb_iternext(VALUE vself); static VALUE adb_fwmkeys(int argc, VALUE *argv, VALUE vself); static VALUE adb_addint(VALUE vself, VALUE vkey, VALUE vnum); static VALUE adb_adddouble(VALUE vself, VALUE vkey, VALUE vnum); static VALUE adb_sync(VALUE vself); static VALUE adb_optimize(int argc, VALUE *argv, VALUE vself); static VALUE adb_vanish(VALUE vself); static VALUE adb_copy(VALUE vself, VALUE vpath); static VALUE adb_tranbegin(VALUE vself); static VALUE adb_trancommit(VALUE vself); static VALUE adb_tranabort(VALUE vself); static VALUE adb_path(VALUE vself); static VALUE adb_rnum(VALUE vself); static VALUE adb_size(VALUE vself); static VALUE adb_misc(int argc, VALUE *argv, VALUE vself); static VALUE adb_fetch(int argc, VALUE *argv, VALUE vself); static VALUE adb_check(VALUE vself, VALUE vkey); static VALUE adb_check_value(VALUE vself, VALUE vval); static VALUE adb_get_reverse(VALUE vself, VALUE vval); static VALUE adb_empty(VALUE vself); static VALUE adb_each(VALUE vself); static VALUE adb_each_key(VALUE vself); static VALUE adb_each_value(VALUE vself); static VALUE adb_keys(VALUE vself); static VALUE adb_values(VALUE vself); /************************************************************************************************* * public objects *************************************************************************************************/ VALUE mod_tokyocabinet; VALUE cls_hdb; VALUE cls_hdb_data; VALUE cls_bdb; VALUE cls_bdb_data; VALUE cls_bdbcur; VALUE cls_bdbcur_data; ID bdb_cmp_call_mid; VALUE cls_fdb; VALUE cls_fdb_data; VALUE cls_tdb; VALUE cls_tdb_data; VALUE cls_tdbqry; VALUE cls_tdbqry_data; VALUE cls_adb; VALUE cls_adb_data; int Init_tokyocabinet(void){ mod_tokyocabinet = rb_define_module("TokyoCabinet"); rb_define_const(mod_tokyocabinet, "VERSION", rb_str_new2(tcversion)); hdb_init(); bdb_init(); bdbcur_init(); fdb_init(); tdb_init(); tdbqry_init(); adb_init(); return 0; } /************************************************************************************************* * private objects *************************************************************************************************/ static VALUE StringValueEx(VALUE vobj){ char kbuf[NUMBUFSIZ]; int ksiz; switch(TYPE(vobj)){ case T_FIXNUM: ksiz = sprintf(kbuf, "%d", (int)FIX2INT(vobj)); return rb_str_new(kbuf, ksiz); case T_BIGNUM: ksiz = sprintf(kbuf, "%lld", (long long)NUM2LL(vobj)); return rb_str_new(kbuf, ksiz); case T_TRUE: ksiz = sprintf(kbuf, "true"); return rb_str_new(kbuf, ksiz); case T_FALSE: ksiz = sprintf(kbuf, "false"); return rb_str_new(kbuf, ksiz); case T_NIL: ksiz = sprintf(kbuf, "nil"); return rb_str_new(kbuf, ksiz); } return StringValue(vobj); } static TCLIST *varytolist(VALUE vary){ VALUE vval; TCLIST *list; int i, num; num = RARRAY_LEN(vary); list = tclistnew2(num); for(i = 0; i < num; i++){ vval = rb_ary_entry(vary, i); vval = StringValueEx(vval); tclistpush(list, RSTRING_PTR(vval), RSTRING_LEN(vval)); } return list; } static VALUE listtovary(TCLIST *list){ VALUE vary; const char *vbuf; int i, num, vsiz; num = tclistnum(list); vary = rb_ary_new2(num); for(i = 0; i < num; i++){ vbuf = tclistval(list, i, &vsiz); rb_ary_push(vary, rb_str_new(vbuf, vsiz)); } return vary; } static TCMAP *vhashtomap(VALUE vhash){ VALUE vkeys, vkey, vval; TCMAP *map; int i, num; map = tcmapnew2(31); vkeys = rb_funcall(vhash, rb_intern("keys"), 0); num = RARRAY_LEN(vkeys); for(i = 0; i < num; i++){ vkey = rb_ary_entry(vkeys, i); vval = rb_hash_aref(vhash, vkey); vkey = StringValueEx(vkey); vval = StringValueEx(vval); tcmapput(map, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)); } return map; } static VALUE maptovhash(TCMAP *map){ const char *kbuf, *vbuf; int ksiz, vsiz; VALUE vhash; vhash = rb_hash_new(); tcmapiterinit(map); while((kbuf = tcmapiternext(map, &ksiz)) != NULL){ vbuf = tcmapiterval(kbuf, &vsiz); rb_hash_aset(vhash, rb_str_new(kbuf, ksiz), rb_str_new(vbuf, vsiz)); } return vhash; } static void hdb_init(void){ cls_hdb = rb_define_class_under(mod_tokyocabinet, "HDB", rb_cObject); cls_hdb_data = rb_define_class_under(mod_tokyocabinet, "HDB_data", rb_cObject); rb_define_const(cls_hdb, "ESUCCESS", INT2NUM(TCESUCCESS)); rb_define_const(cls_hdb, "ETHREAD", INT2NUM(TCETHREAD)); rb_define_const(cls_hdb, "EINVALID", INT2NUM(TCEINVALID)); rb_define_const(cls_hdb, "ENOFILE", INT2NUM(TCENOFILE)); rb_define_const(cls_hdb, "ENOPERM", INT2NUM(TCENOPERM)); rb_define_const(cls_hdb, "EMETA", INT2NUM(TCEMETA)); rb_define_const(cls_hdb, "ERHEAD", INT2NUM(TCERHEAD)); rb_define_const(cls_hdb, "EOPEN", INT2NUM(TCEOPEN)); rb_define_const(cls_hdb, "ECLOSE", INT2NUM(TCECLOSE)); rb_define_const(cls_hdb, "ETRUNC", INT2NUM(TCETRUNC)); rb_define_const(cls_hdb, "ESYNC", INT2NUM(TCESYNC)); rb_define_const(cls_hdb, "ESTAT", INT2NUM(TCESTAT)); rb_define_const(cls_hdb, "ESEEK", INT2NUM(TCESEEK)); rb_define_const(cls_hdb, "EREAD", INT2NUM(TCEREAD)); rb_define_const(cls_hdb, "EWRITE", INT2NUM(TCEWRITE)); rb_define_const(cls_hdb, "EMMAP", INT2NUM(TCEMMAP)); rb_define_const(cls_hdb, "ELOCK", INT2NUM(TCELOCK)); rb_define_const(cls_hdb, "EUNLINK", INT2NUM(TCEUNLINK)); rb_define_const(cls_hdb, "ERENAME", INT2NUM(TCERENAME)); rb_define_const(cls_hdb, "EMKDIR", INT2NUM(TCEMKDIR)); rb_define_const(cls_hdb, "ERMDIR", INT2NUM(TCERMDIR)); rb_define_const(cls_hdb, "EKEEP", INT2NUM(TCEKEEP)); rb_define_const(cls_hdb, "ENOREC", INT2NUM(TCENOREC)); rb_define_const(cls_hdb, "EMISC", INT2NUM(TCEMISC)); rb_define_const(cls_hdb, "TLARGE", INT2NUM(HDBTLARGE)); rb_define_const(cls_hdb, "TDEFLATE", INT2NUM(HDBTDEFLATE)); rb_define_const(cls_hdb, "TBZIP", INT2NUM(HDBTBZIP)); rb_define_const(cls_hdb, "TTCBS", INT2NUM(HDBTTCBS)); rb_define_const(cls_hdb, "OREADER", INT2NUM(HDBOREADER)); rb_define_const(cls_hdb, "OWRITER", INT2NUM(HDBOWRITER)); rb_define_const(cls_hdb, "OCREAT", INT2NUM(HDBOCREAT)); rb_define_const(cls_hdb, "OTRUNC", INT2NUM(HDBOTRUNC)); rb_define_const(cls_hdb, "ONOLCK", INT2NUM(HDBONOLCK)); rb_define_const(cls_hdb, "OLCKNB", INT2NUM(HDBOLCKNB)); rb_define_const(cls_hdb, "OTSYNC", INT2NUM(HDBOTSYNC)); rb_define_private_method(cls_hdb, "initialize", hdb_initialize, 0); rb_define_method(cls_hdb, "errmsg", hdb_errmsg, -1); rb_define_method(cls_hdb, "ecode", hdb_ecode, 0); rb_define_method(cls_hdb, "tune", hdb_tune, -1); rb_define_method(cls_hdb, "setcache", hdb_setcache, -1); rb_define_method(cls_hdb, "setxmsiz", hdb_setxmsiz, -1); rb_define_method(cls_hdb, "setdfunit", hdb_setdfunit, -1); rb_define_method(cls_hdb, "open", hdb_open, -1); rb_define_method(cls_hdb, "close", hdb_close, 0); rb_define_method(cls_hdb, "put", hdb_put, 2); rb_define_method(cls_hdb, "putkeep", hdb_putkeep, 2); rb_define_method(cls_hdb, "putcat", hdb_putcat, 2); rb_define_method(cls_hdb, "putasync", hdb_putasync, 2); rb_define_method(cls_hdb, "out", hdb_out, 1); rb_define_method(cls_hdb, "get", hdb_get, 1); rb_define_method(cls_hdb, "vsiz", hdb_vsiz, 1); rb_define_method(cls_hdb, "iterinit", hdb_iterinit, 0); rb_define_method(cls_hdb, "iternext", hdb_iternext, 0); rb_define_method(cls_hdb, "fwmkeys", hdb_fwmkeys, -1); rb_define_method(cls_hdb, "addint", hdb_addint, 2); rb_define_method(cls_hdb, "adddouble", hdb_adddouble, 2); rb_define_method(cls_hdb, "sync", hdb_sync, 0); rb_define_method(cls_hdb, "optimize", hdb_optimize, -1); rb_define_method(cls_hdb, "vanish", hdb_vanish, 0); rb_define_method(cls_hdb, "copy", hdb_copy, 1); rb_define_method(cls_hdb, "tranbegin", hdb_tranbegin, 0); rb_define_method(cls_hdb, "trancommit", hdb_trancommit, 0); rb_define_method(cls_hdb, "tranabort", hdb_tranabort, 0); rb_define_method(cls_hdb, "path", hdb_path, 0); rb_define_method(cls_hdb, "rnum", hdb_rnum, 0); rb_define_method(cls_hdb, "fsiz", hdb_fsiz, 0); rb_define_method(cls_hdb, "[]", hdb_get, 1); rb_define_method(cls_hdb, "[]=", hdb_put, 2); rb_define_method(cls_hdb, "store", hdb_put, 2); rb_define_method(cls_hdb, "delete", hdb_out, 1); rb_define_method(cls_hdb, "fetch", hdb_fetch, -1); rb_define_method(cls_hdb, "has_key?", hdb_check, 1); rb_define_method(cls_hdb, "key?", hdb_check, 1); rb_define_method(cls_hdb, "include?", hdb_check, 1); rb_define_method(cls_hdb, "member?", hdb_check, 1); rb_define_method(cls_hdb, "has_value?", hdb_check_value, 1); rb_define_method(cls_hdb, "value?", hdb_check_value, 1); rb_define_method(cls_hdb, "key", hdb_get_reverse, 1); rb_define_method(cls_hdb, "clear", hdb_vanish, 0); rb_define_method(cls_hdb, "size", hdb_rnum, 0); rb_define_method(cls_hdb, "length", hdb_rnum, 0); rb_define_method(cls_hdb, "empty?", hdb_empty, 0); rb_define_method(cls_hdb, "each", hdb_each, 0); rb_define_method(cls_hdb, "each_pair", hdb_each, 0); rb_define_method(cls_hdb, "each_key", hdb_each_key, 0); rb_define_method(cls_hdb, "each_value", hdb_each_value, 0); rb_define_method(cls_hdb, "keys", hdb_keys, 0); rb_define_method(cls_hdb, "values", hdb_values, 0); } static VALUE hdb_initialize(VALUE vself){ VALUE vhdb; TCHDB *hdb; hdb = tchdbnew(); tchdbsetmutex(hdb); vhdb = Data_Wrap_Struct(cls_hdb_data, 0, tchdbdel, hdb); rb_iv_set(vself, HDBVNDATA, vhdb); return Qnil; } static VALUE hdb_errmsg(int argc, VALUE *argv, VALUE vself){ VALUE vhdb, vecode; TCHDB *hdb; const char *msg; int ecode; rb_scan_args(argc, argv, "01", &vecode); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); ecode = (vecode == Qnil) ? tchdbecode(hdb) : NUM2INT(vecode); msg = tchdberrmsg(ecode); return rb_str_new2(msg); } static VALUE hdb_ecode(VALUE vself){ VALUE vhdb; TCHDB *hdb; vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return INT2NUM(tchdbecode(hdb)); } static VALUE hdb_tune(int argc, VALUE *argv, VALUE vself){ VALUE vhdb, vbnum, vapow, vfpow, vopts; TCHDB *hdb; int apow, fpow, opts; int64_t bnum; rb_scan_args(argc, argv, "04", &vbnum, &vapow, &vfpow, &vopts); bnum = (vbnum == Qnil) ? -1 : NUM2LL(vbnum); apow = (vapow == Qnil) ? -1 : NUM2INT(vapow); fpow = (vfpow == Qnil) ? -1 : NUM2INT(vfpow); opts = (vopts == Qnil) ? 0 : NUM2INT(vopts); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbtune(hdb, bnum, apow, fpow, opts) ? Qtrue : Qfalse; } static VALUE hdb_setcache(int argc, VALUE *argv, VALUE vself){ VALUE vhdb, vrcnum; TCHDB *hdb; int rcnum; rb_scan_args(argc, argv, "01", &vrcnum); rcnum = (vrcnum == Qnil) ? -1 : NUM2INT(vrcnum); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbsetcache(hdb, rcnum) ? Qtrue : Qfalse; } static VALUE hdb_setxmsiz(int argc, VALUE *argv, VALUE vself){ VALUE vhdb, vxmsiz; TCHDB *hdb; int64_t xmsiz; rb_scan_args(argc, argv, "01", &vxmsiz); xmsiz = (vxmsiz == Qnil) ? -1 : NUM2LL(vxmsiz); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbsetxmsiz(hdb, xmsiz) ? Qtrue : Qfalse; } static VALUE hdb_setdfunit(int argc, VALUE *argv, VALUE vself){ VALUE vhdb, vdfunit; TCHDB *hdb; int32_t dfunit; rb_scan_args(argc, argv, "01", &vdfunit); dfunit = (vdfunit == Qnil) ? -1 : NUM2INT(vdfunit); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbsetdfunit(hdb, dfunit) ? Qtrue : Qfalse; } static VALUE hdb_open(int argc, VALUE *argv, VALUE vself){ VALUE vhdb, vpath, vomode; TCHDB *hdb; int omode; rb_scan_args(argc, argv, "11", &vpath, &vomode); Check_Type(vpath, T_STRING); omode = (vomode == Qnil) ? HDBOREADER : NUM2INT(vomode); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbopen(hdb, RSTRING_PTR(vpath), omode) ? Qtrue : Qfalse; } static VALUE hdb_close(VALUE vself){ VALUE vhdb; TCHDB *hdb; vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbclose(hdb) ? Qtrue : Qfalse; } static VALUE hdb_put(VALUE vself, VALUE vkey, VALUE vval){ VALUE vhdb; TCHDB *hdb; vkey = StringValueEx(vkey); vval = StringValueEx(vval); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbput(hdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)) ? Qtrue : Qfalse; } static VALUE hdb_putkeep(VALUE vself, VALUE vkey, VALUE vval){ VALUE vhdb; TCHDB *hdb; vkey = StringValueEx(vkey); vval = StringValueEx(vval); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbputkeep(hdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)) ? Qtrue : Qfalse; } static VALUE hdb_putcat(VALUE vself, VALUE vkey, VALUE vval){ VALUE vhdb; TCHDB *hdb; vkey = StringValueEx(vkey); vval = StringValueEx(vval); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbputcat(hdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)) ? Qtrue : Qfalse; } static VALUE hdb_putasync(VALUE vself, VALUE vkey, VALUE vval){ VALUE vhdb; TCHDB *hdb; vkey = StringValueEx(vkey); vval = StringValueEx(vval); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbputasync(hdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)) ? Qtrue : Qfalse; } static VALUE hdb_out(VALUE vself, VALUE vkey){ VALUE vhdb; TCHDB *hdb; vkey = StringValueEx(vkey); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbout(hdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey)) ? Qtrue : Qfalse; } static VALUE hdb_get(VALUE vself, VALUE vkey){ VALUE vhdb, vval; TCHDB *hdb; char *vbuf; int vsiz; vkey = StringValueEx(vkey); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); if(!(vbuf = tchdbget(hdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), &vsiz))) return Qnil; vval = rb_str_new(vbuf, vsiz); tcfree(vbuf); return vval; } static VALUE hdb_vsiz(VALUE vself, VALUE vkey){ VALUE vhdb; TCHDB *hdb; vkey = StringValueEx(vkey); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return INT2NUM(tchdbvsiz(hdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey))); } static VALUE hdb_iterinit(VALUE vself){ VALUE vhdb; TCHDB *hdb; vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbiterinit(hdb) ? Qtrue : Qfalse; } static VALUE hdb_iternext(VALUE vself){ VALUE vhdb, vval; TCHDB *hdb; char *vbuf; int vsiz; vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); if(!(vbuf = tchdbiternext(hdb, &vsiz))) return Qnil; vval = rb_str_new(vbuf, vsiz); tcfree(vbuf); return vval; } static VALUE hdb_fwmkeys(int argc, VALUE *argv, VALUE vself){ VALUE vhdb, vprefix, vmax, vary; TCHDB *hdb; TCLIST *keys; int max; rb_scan_args(argc, argv, "11", &vprefix, &vmax); vprefix = StringValueEx(vprefix); max = (vmax == Qnil) ? -1 : NUM2INT(vmax); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); keys = tchdbfwmkeys(hdb, RSTRING_PTR(vprefix), RSTRING_LEN(vprefix), max); vary = listtovary(keys); tclistdel(keys); return vary; } static VALUE hdb_addint(VALUE vself, VALUE vkey, VALUE vnum){ VALUE vhdb; TCHDB *hdb; int num; vkey = StringValueEx(vkey); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); num = tchdbaddint(hdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), NUM2INT(vnum)); return num == INT_MIN ? Qnil : INT2NUM(num); } static VALUE hdb_adddouble(VALUE vself, VALUE vkey, VALUE vnum){ VALUE vhdb; TCHDB *hdb; double num; vkey = StringValueEx(vkey); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); num = tchdbadddouble(hdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), NUM2DBL(vnum)); return isnan(num) ? Qnil : rb_float_new(num); } static VALUE hdb_sync(VALUE vself){ VALUE vhdb; TCHDB *hdb; vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbsync(hdb) ? Qtrue : Qfalse; } static VALUE hdb_optimize(int argc, VALUE *argv, VALUE vself){ VALUE vhdb, vbnum, vapow, vfpow, vopts; TCHDB *hdb; int apow, fpow, opts; int64_t bnum; rb_scan_args(argc, argv, "04", &vbnum, &vapow, &vfpow, &vopts); bnum = (vbnum == Qnil) ? -1 : NUM2LL(vbnum); apow = (vapow == Qnil) ? -1 : NUM2INT(vapow); fpow = (vfpow == Qnil) ? -1 : NUM2INT(vfpow); opts = (vopts == Qnil) ? UINT8_MAX : NUM2INT(vopts); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdboptimize(hdb, bnum, apow, fpow, opts) ? Qtrue : Qfalse; } static VALUE hdb_vanish(VALUE vself){ VALUE vhdb; TCHDB *hdb; vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbvanish(hdb) ? Qtrue : Qfalse; } static VALUE hdb_copy(VALUE vself, VALUE vpath){ VALUE vhdb; TCHDB *hdb; Check_Type(vpath, T_STRING); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbcopy(hdb, RSTRING_PTR(vpath)) ? Qtrue : Qfalse; } static VALUE hdb_tranbegin(VALUE vself){ VALUE vhdb; TCHDB *hdb; vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbtranbegin(hdb) ? Qtrue : Qfalse; } static VALUE hdb_trancommit(VALUE vself){ VALUE vhdb; TCHDB *hdb; vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbtrancommit(hdb) ? Qtrue : Qfalse; } static VALUE hdb_tranabort(VALUE vself){ VALUE vhdb; TCHDB *hdb; vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbtranabort(hdb) ? Qtrue : Qfalse; } static VALUE hdb_path(VALUE vself){ VALUE vhdb; TCHDB *hdb; const char *path; vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); if(!(path = tchdbpath(hdb))) return Qnil; return rb_str_new2(path); } static VALUE hdb_rnum(VALUE vself){ VALUE vhdb; TCHDB *hdb; vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return LL2NUM(tchdbrnum(hdb)); } static VALUE hdb_fsiz(VALUE vself){ VALUE vhdb; TCHDB *hdb; vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return LL2NUM(tchdbfsiz(hdb)); } static VALUE hdb_fetch(int argc, VALUE *argv, VALUE vself){ VALUE vhdb, vkey, vdef, vval; TCHDB *hdb; char *vbuf; int vsiz; rb_scan_args(argc, argv, "11", &vkey, &vdef); vkey = StringValueEx(vkey); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); if((vbuf = tchdbget(hdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), &vsiz)) != NULL){ vval = rb_str_new(vbuf, vsiz); tcfree(vbuf); } else { vval = vdef; } return vval; } static VALUE hdb_check(VALUE vself, VALUE vkey){ VALUE vhdb; TCHDB *hdb; vkey = StringValueEx(vkey); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbvsiz(hdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey)) >= 0 ? Qtrue : Qfalse; } static VALUE hdb_check_value(VALUE vself, VALUE vval){ VALUE vhdb; TCHDB *hdb; TCXSTR *kxstr, *vxstr; bool hit; vval = StringValueEx(vval); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); hit = false; kxstr = tcxstrnew(); vxstr = tcxstrnew(); tchdbiterinit(hdb); while(tchdbiternext3(hdb, kxstr, vxstr)){ if(tcxstrsize(vxstr) == RSTRING_LEN(vval) && memcmp(tcxstrptr(vxstr), RSTRING_PTR(vval), RSTRING_LEN(vval)) == 0){ hit = true; break; } } tcxstrdel(vxstr); tcxstrdel(kxstr); return hit ? Qtrue : Qfalse; } static VALUE hdb_get_reverse(VALUE vself, VALUE vval){ VALUE vhdb, vrv; TCHDB *hdb; TCXSTR *kxstr, *vxstr; vval = StringValueEx(vval); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); vrv = Qnil; kxstr = tcxstrnew(); vxstr = tcxstrnew(); tchdbiterinit(hdb); while(tchdbiternext3(hdb, kxstr, vxstr)){ if(tcxstrsize(vxstr) == RSTRING_LEN(vval) && memcmp(tcxstrptr(vxstr), RSTRING_PTR(vval), RSTRING_LEN(vval)) == 0){ vrv = rb_str_new(tcxstrptr(kxstr), tcxstrsize(kxstr)); break; } } tcxstrdel(vxstr); tcxstrdel(kxstr); return vrv; } static VALUE hdb_empty(VALUE vself){ VALUE vhdb; TCHDB *hdb; vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); return tchdbrnum(hdb) < 1 ? Qtrue : Qfalse; } static VALUE hdb_each(VALUE vself){ VALUE vhdb, vrv; TCHDB *hdb; TCXSTR *kxstr, *vxstr; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); vrv = Qnil; kxstr = tcxstrnew(); vxstr = tcxstrnew(); tchdbiterinit(hdb); while(tchdbiternext3(hdb, kxstr, vxstr)){ vrv = rb_yield_values(2, rb_str_new(tcxstrptr(kxstr), tcxstrsize(kxstr)), rb_str_new(tcxstrptr(vxstr), tcxstrsize(vxstr))); } tcxstrdel(vxstr); tcxstrdel(kxstr); return vrv; } static VALUE hdb_each_key(VALUE vself){ VALUE vhdb, vrv; TCHDB *hdb; TCXSTR *kxstr, *vxstr; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); vrv = Qnil; kxstr = tcxstrnew(); vxstr = tcxstrnew(); tchdbiterinit(hdb); while(tchdbiternext3(hdb, kxstr, vxstr)){ vrv = rb_yield(rb_str_new(tcxstrptr(kxstr), tcxstrsize(kxstr))); } tcxstrdel(vxstr); tcxstrdel(kxstr); return vrv; } static VALUE hdb_each_value(VALUE vself){ VALUE vhdb, vrv; TCHDB *hdb; TCXSTR *kxstr, *vxstr; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); vrv = Qnil; kxstr = tcxstrnew(); vxstr = tcxstrnew(); tchdbiterinit(hdb); while(tchdbiternext3(hdb, kxstr, vxstr)){ vrv = rb_yield(rb_str_new(tcxstrptr(vxstr), tcxstrsize(vxstr))); } tcxstrdel(vxstr); tcxstrdel(kxstr); return vrv; } static VALUE hdb_keys(VALUE vself){ VALUE vhdb, vary; TCHDB *hdb; TCXSTR *kxstr, *vxstr; vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); vary = rb_ary_new2(tchdbrnum(hdb)); kxstr = tcxstrnew(); vxstr = tcxstrnew(); tchdbiterinit(hdb); while(tchdbiternext3(hdb, kxstr, vxstr)){ rb_ary_push(vary, rb_str_new(tcxstrptr(kxstr), tcxstrsize(kxstr))); } tcxstrdel(vxstr); tcxstrdel(kxstr); return vary; } static VALUE hdb_values(VALUE vself){ VALUE vhdb, vary; TCHDB *hdb; TCXSTR *kxstr, *vxstr; vhdb = rb_iv_get(vself, HDBVNDATA); Data_Get_Struct(vhdb, TCHDB, hdb); vary = rb_ary_new2(tchdbrnum(hdb)); kxstr = tcxstrnew(); vxstr = tcxstrnew(); tchdbiterinit(hdb); while(tchdbiternext3(hdb, kxstr, vxstr)){ rb_ary_push(vary, rb_str_new(tcxstrptr(vxstr), tcxstrsize(vxstr))); } tcxstrdel(vxstr); tcxstrdel(kxstr); return vary; } static void bdb_init(void){ cls_bdb = rb_define_class_under(mod_tokyocabinet, "BDB", rb_cObject); cls_bdb_data = rb_define_class_under(mod_tokyocabinet, "BDB_data", rb_cObject); bdb_cmp_call_mid = rb_intern("call"); rb_define_const(cls_bdb, "ESUCCESS", INT2NUM(TCESUCCESS)); rb_define_const(cls_bdb, "ETHREAD", INT2NUM(TCETHREAD)); rb_define_const(cls_bdb, "EINVALID", INT2NUM(TCEINVALID)); rb_define_const(cls_bdb, "ENOFILE", INT2NUM(TCENOFILE)); rb_define_const(cls_bdb, "ENOPERM", INT2NUM(TCENOPERM)); rb_define_const(cls_bdb, "EMETA", INT2NUM(TCEMETA)); rb_define_const(cls_bdb, "ERHEAD", INT2NUM(TCERHEAD)); rb_define_const(cls_bdb, "EOPEN", INT2NUM(TCEOPEN)); rb_define_const(cls_bdb, "ECLOSE", INT2NUM(TCECLOSE)); rb_define_const(cls_bdb, "ETRUNC", INT2NUM(TCETRUNC)); rb_define_const(cls_bdb, "ESYNC", INT2NUM(TCESYNC)); rb_define_const(cls_bdb, "ESTAT", INT2NUM(TCESTAT)); rb_define_const(cls_bdb, "ESEEK", INT2NUM(TCESEEK)); rb_define_const(cls_bdb, "EREAD", INT2NUM(TCEREAD)); rb_define_const(cls_bdb, "EWRITE", INT2NUM(TCEWRITE)); rb_define_const(cls_bdb, "EMMAP", INT2NUM(TCEMMAP)); rb_define_const(cls_bdb, "ELOCK", INT2NUM(TCELOCK)); rb_define_const(cls_bdb, "EUNLINK", INT2NUM(TCEUNLINK)); rb_define_const(cls_bdb, "ERENAME", INT2NUM(TCERENAME)); rb_define_const(cls_bdb, "EMKDIR", INT2NUM(TCEMKDIR)); rb_define_const(cls_bdb, "ERMDIR", INT2NUM(TCERMDIR)); rb_define_const(cls_bdb, "EKEEP", INT2NUM(TCEKEEP)); rb_define_const(cls_bdb, "ENOREC", INT2NUM(TCENOREC)); rb_define_const(cls_bdb, "EMISC", INT2NUM(TCEMISC)); rb_define_const(cls_bdb, "CMPLEXICAL", rb_str_new2("CMPLEXICAL")); rb_define_const(cls_bdb, "CMPDECIMAL", rb_str_new2("CMPDECIMAL")); rb_define_const(cls_bdb, "CMPINT32", rb_str_new2("CMPINT32")); rb_define_const(cls_bdb, "CMPINT64", rb_str_new2("CMPINT64")); rb_define_const(cls_bdb, "TLARGE", INT2NUM(BDBTLARGE)); rb_define_const(cls_bdb, "TDEFLATE", INT2NUM(BDBTDEFLATE)); rb_define_const(cls_bdb, "TBZIP", INT2NUM(BDBTBZIP)); rb_define_const(cls_bdb, "TTCBS", INT2NUM(BDBTTCBS)); rb_define_const(cls_bdb, "OREADER", INT2NUM(BDBOREADER)); rb_define_const(cls_bdb, "OWRITER", INT2NUM(BDBOWRITER)); rb_define_const(cls_bdb, "OCREAT", INT2NUM(BDBOCREAT)); rb_define_const(cls_bdb, "OTRUNC", INT2NUM(BDBOTRUNC)); rb_define_const(cls_bdb, "ONOLCK", INT2NUM(BDBONOLCK)); rb_define_const(cls_bdb, "OLCKNB", INT2NUM(BDBOLCKNB)); rb_define_const(cls_bdb, "OTSYNC", INT2NUM(BDBOTSYNC)); rb_define_private_method(cls_bdb, "initialize", bdb_initialize, 0); rb_define_method(cls_bdb, "errmsg", bdb_errmsg, -1); rb_define_method(cls_bdb, "ecode", bdb_ecode, 0); rb_define_method(cls_bdb, "setcmpfunc", bdb_setcmpfunc, 1); rb_define_method(cls_bdb, "tune", bdb_tune, -1); rb_define_method(cls_bdb, "setcache", bdb_setcache, -1); rb_define_method(cls_bdb, "setxmsiz", bdb_setxmsiz, -1); rb_define_method(cls_bdb, "setdfunit", bdb_setdfunit, -1); rb_define_method(cls_bdb, "open", bdb_open, -1); rb_define_method(cls_bdb, "close", bdb_close, 0); rb_define_method(cls_bdb, "put", bdb_put, 2); rb_define_method(cls_bdb, "putkeep", bdb_putkeep, 2); rb_define_method(cls_bdb, "putcat", bdb_putcat, 2); rb_define_method(cls_bdb, "putdup", bdb_putdup, 2); rb_define_method(cls_bdb, "putlist", bdb_putlist, 2); rb_define_method(cls_bdb, "out", bdb_out, 1); rb_define_method(cls_bdb, "outlist", bdb_outlist, 1); rb_define_method(cls_bdb, "get", bdb_get, 1); rb_define_method(cls_bdb, "getlist", bdb_getlist, 1); rb_define_method(cls_bdb, "vnum", bdb_vnum, 1); rb_define_method(cls_bdb, "vsiz", bdb_vsiz, 1); rb_define_method(cls_bdb, "range", bdb_range, -1); rb_define_method(cls_bdb, "fwmkeys", bdb_fwmkeys, -1); rb_define_method(cls_bdb, "addint", bdb_addint, 2); rb_define_method(cls_bdb, "adddouble", bdb_adddouble, 2); rb_define_method(cls_bdb, "sync", bdb_sync, 0); rb_define_method(cls_bdb, "optimize", bdb_optimize, -1); rb_define_method(cls_bdb, "vanish", bdb_vanish, 0); rb_define_method(cls_bdb, "copy", bdb_copy, 1); rb_define_method(cls_bdb, "tranbegin", bdb_tranbegin, 0); rb_define_method(cls_bdb, "trancommit", bdb_trancommit, 0); rb_define_method(cls_bdb, "tranabort", bdb_tranabort, 0); rb_define_method(cls_bdb, "path", bdb_path, 0); rb_define_method(cls_bdb, "rnum", bdb_rnum, 0); rb_define_method(cls_bdb, "fsiz", bdb_fsiz, 0); rb_define_method(cls_bdb, "[]", bdb_get, 1); rb_define_method(cls_bdb, "[]=", bdb_put, 2); rb_define_method(cls_bdb, "store", bdb_put, 2); rb_define_method(cls_bdb, "delete", bdb_out, 1); rb_define_method(cls_bdb, "fetch", bdb_fetch, -1); rb_define_method(cls_bdb, "has_key?", bdb_check, 1); rb_define_method(cls_bdb, "key?", bdb_check, 1); rb_define_method(cls_bdb, "include?", bdb_check, 1); rb_define_method(cls_bdb, "member?", bdb_check, 1); rb_define_method(cls_bdb, "has_value?", bdb_check_value, 1); rb_define_method(cls_bdb, "value?", bdb_check_value, 1); rb_define_method(cls_bdb, "key", bdb_get_reverse, 1); rb_define_method(cls_bdb, "clear", bdb_vanish, 0); rb_define_method(cls_bdb, "size", bdb_rnum, 0); rb_define_method(cls_bdb, "length", bdb_rnum, 0); rb_define_method(cls_bdb, "empty?", bdb_empty, 0); rb_define_method(cls_bdb, "each", bdb_each, 0); rb_define_method(cls_bdb, "each_pair", bdb_each, 0); rb_define_method(cls_bdb, "each_key", bdb_each_key, 0); rb_define_method(cls_bdb, "each_value", bdb_each_value, 0); rb_define_method(cls_bdb, "keys", bdb_keys, 0); rb_define_method(cls_bdb, "values", bdb_values, 0); } static int bdb_cmpobj(const char *aptr, int asiz, const char *bptr, int bsiz, VALUE vcmp){ VALUE vrv; vrv = rb_funcall(vcmp, bdb_cmp_call_mid, 2, rb_str_new(aptr, asiz), rb_str_new(bptr, bsiz)); return (vrv == Qnil) ? 0 : NUM2INT(vrv); } static VALUE bdb_initialize(VALUE vself){ VALUE vbdb; TCBDB *bdb; bdb = tcbdbnew(); tcbdbsetmutex(bdb); vbdb = Data_Wrap_Struct(cls_bdb_data, 0, tcbdbdel, bdb); rb_iv_set(vself, BDBVNDATA, vbdb); return Qnil; } static VALUE bdb_errmsg(int argc, VALUE *argv, VALUE vself){ VALUE vbdb, vecode; TCBDB *bdb; const char *msg; int ecode; rb_scan_args(argc, argv, "01", &vecode); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); ecode = (vecode == Qnil) ? tcbdbecode(bdb) : NUM2INT(vecode); msg = tcbdberrmsg(ecode); return rb_str_new2(msg); } static VALUE bdb_ecode(VALUE vself){ VALUE vbdb; TCBDB *bdb; vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return INT2NUM(tcbdbecode(bdb)); } static VALUE bdb_setcmpfunc(VALUE vself, VALUE vcmp){ VALUE vbdb; TCBDB *bdb; TCCMP cmp; cmp = (TCCMP)bdb_cmpobj; if(TYPE(vcmp) == T_STRING){ if(!strcmp(RSTRING_PTR(vcmp), "CMPLEXICAL")){ cmp = tccmplexical; } else if(!strcmp(RSTRING_PTR(vcmp), "CMPDECIMAL")){ cmp = tccmpdecimal; } else if(!strcmp(RSTRING_PTR(vcmp), "CMPINT32")){ cmp = tccmpint32; } else if(!strcmp(RSTRING_PTR(vcmp), "CMPINT64")){ cmp = tccmpint64; } else { rb_raise(rb_eArgError, "unknown comparison function: %s", RSTRING_PTR(vcmp)); } } else if(!rb_respond_to(vcmp, bdb_cmp_call_mid)){ rb_raise(rb_eArgError, "call method is not implemented"); } vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbsetcmpfunc(bdb, cmp, (void *)(intptr_t)vcmp); } static VALUE bdb_tune(int argc, VALUE *argv, VALUE vself){ VALUE vbdb, vlmemb, vnmemb, vbnum, vapow, vfpow, vopts; TCBDB *bdb; int lmemb, nmemb, apow, fpow, opts; int64_t bnum; rb_scan_args(argc, argv, "06", &vlmemb, &vnmemb, &vbnum, &vapow, &vfpow, &vopts); lmemb = (vlmemb == Qnil) ? -1 : NUM2INT(vlmemb); nmemb = (vnmemb == Qnil) ? -1 : NUM2INT(vnmemb); bnum = (vbnum == Qnil) ? -1 : NUM2LL(vbnum); apow = (vapow == Qnil) ? -1 : NUM2INT(vapow); fpow = (vfpow == Qnil) ? -1 : NUM2INT(vfpow); opts = (vopts == Qnil) ? 0 : NUM2INT(vopts); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts) ? Qtrue : Qfalse; } static VALUE bdb_setcache(int argc, VALUE *argv, VALUE vself){ VALUE vbdb, vlcnum, vncnum; TCBDB *bdb; int lcnum, ncnum; rb_scan_args(argc, argv, "02", &vlcnum, &vncnum); lcnum = (vlcnum == Qnil) ? -1 : NUM2INT(vlcnum); ncnum = (vncnum == Qnil) ? -1 : NUM2INT(vncnum); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbsetcache(bdb, lcnum, ncnum); } static VALUE bdb_setxmsiz(int argc, VALUE *argv, VALUE vself){ VALUE vbdb, vxmsiz; TCBDB *bdb; int64_t xmsiz; rb_scan_args(argc, argv, "01", &vxmsiz); xmsiz = (vxmsiz == Qnil) ? -1 : NUM2LL(vxmsiz); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbsetxmsiz(bdb, xmsiz) ? Qtrue : Qfalse; } static VALUE bdb_setdfunit(int argc, VALUE *argv, VALUE vself){ VALUE vbdb, vdfunit; TCBDB *bdb; int32_t dfunit; rb_scan_args(argc, argv, "01", &vdfunit); dfunit = (vdfunit == Qnil) ? -1 : NUM2INT(vdfunit); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbsetdfunit(bdb, dfunit) ? Qtrue : Qfalse; } static VALUE bdb_open(int argc, VALUE *argv, VALUE vself){ VALUE vbdb, vpath, vomode; TCBDB *bdb; int omode; rb_scan_args(argc, argv, "11", &vpath, &vomode); Check_Type(vpath, T_STRING); omode = (vomode == Qnil) ? BDBOREADER : NUM2INT(vomode); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbopen(bdb, RSTRING_PTR(vpath), omode) ? Qtrue : Qfalse; } static VALUE bdb_close(VALUE vself){ VALUE vbdb; TCBDB *bdb; vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbclose(bdb) ? Qtrue : Qfalse; } static VALUE bdb_put(VALUE vself, VALUE vkey, VALUE vval){ VALUE vbdb; TCBDB *bdb; vkey = StringValueEx(vkey); vval = StringValueEx(vval); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbput(bdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)) ? Qtrue : Qfalse; } static VALUE bdb_putkeep(VALUE vself, VALUE vkey, VALUE vval){ VALUE vbdb; TCBDB *bdb; vkey = StringValueEx(vkey); vval = StringValueEx(vval); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbputkeep(bdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)) ? Qtrue : Qfalse; } static VALUE bdb_putcat(VALUE vself, VALUE vkey, VALUE vval){ VALUE vbdb; TCBDB *bdb; vkey = StringValueEx(vkey); vval = StringValueEx(vval); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbputcat(bdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)) ? Qtrue : Qfalse; } static VALUE bdb_putdup(VALUE vself, VALUE vkey, VALUE vval){ VALUE vbdb; TCBDB *bdb; vkey = StringValueEx(vkey); vval = StringValueEx(vval); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbputdup(bdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)) ? Qtrue : Qfalse; } static VALUE bdb_putlist(VALUE vself, VALUE vkey, VALUE vvals){ VALUE vbdb; TCBDB *bdb; TCLIST *tvals; bool err; vkey = StringValueEx(vkey); Check_Type(vvals, T_ARRAY); tvals = varytolist(vvals); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); err = false; if(!tcbdbputdup3(bdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), tvals)) err = true; tclistdel(tvals); return err ? Qfalse : Qtrue; } static VALUE bdb_out(VALUE vself, VALUE vkey){ VALUE vbdb; TCBDB *bdb; vkey = StringValueEx(vkey); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbout(bdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey)) ? Qtrue : Qfalse; } static VALUE bdb_outlist(VALUE vself, VALUE vkey){ VALUE vbdb; TCBDB *bdb; vkey = StringValueEx(vkey); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbout3(bdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey)) ? Qtrue : Qfalse; } static VALUE bdb_get(VALUE vself, VALUE vkey){ VALUE vbdb; TCBDB *bdb; const char *vbuf; int vsiz; vkey = StringValueEx(vkey); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); if(!(vbuf = tcbdbget3(bdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), &vsiz))) return Qnil; return rb_str_new(vbuf, vsiz); } static VALUE bdb_getlist(VALUE vself, VALUE vkey){ VALUE vbdb, vary; TCBDB *bdb; TCLIST *vals; vkey = StringValueEx(vkey); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); if(!(vals = tcbdbget4(bdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey)))) return Qnil; vary = listtovary(vals); tclistdel(vals); return vary; } static VALUE bdb_vnum(VALUE vself, VALUE vkey){ VALUE vbdb; TCBDB *bdb; vkey = StringValueEx(vkey); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return INT2NUM(tcbdbvnum(bdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey))); } static VALUE bdb_vsiz(VALUE vself, VALUE vkey){ VALUE vbdb; TCBDB *bdb; vkey = StringValueEx(vkey); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return INT2NUM(tcbdbvsiz(bdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey))); } static VALUE bdb_range(int argc, VALUE *argv, VALUE vself){ VALUE vbdb, vbkey, vbinc, vekey, veinc, vmax, vary; TCBDB *bdb; TCLIST *keys; const char *bkbuf, *ekbuf; int bksiz, eksiz, max; bool binc, einc; rb_scan_args(argc, argv, "05", &vbkey, &vbinc, &vekey, &veinc, &vmax); if(vbkey != Qnil) vbkey = StringValueEx(vbkey); if(vekey != Qnil) vekey = StringValueEx(vekey); binc = (vbinc != Qnil && vbinc != Qfalse); einc = (veinc != Qnil && veinc != Qfalse); max = (vmax == Qnil) ? -1 : NUM2INT(vmax); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); if(vbkey != Qnil){ bkbuf = RSTRING_PTR(vbkey); bksiz = RSTRING_LEN(vbkey); } else { bkbuf = NULL; bksiz = -1; } if(vekey != Qnil){ ekbuf = RSTRING_PTR(vekey); eksiz = RSTRING_LEN(vekey); } else { ekbuf = NULL; eksiz = -1; } keys = tcbdbrange(bdb, bkbuf, bksiz, binc, ekbuf, eksiz, einc, max); vary = listtovary(keys); tclistdel(keys); return vary; } static VALUE bdb_fwmkeys(int argc, VALUE *argv, VALUE vself){ VALUE vbdb, vprefix, vmax, vary; TCBDB *bdb; TCLIST *keys; int max; rb_scan_args(argc, argv, "11", &vprefix, &vmax); vprefix = StringValueEx(vprefix); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); max = (vmax == Qnil) ? -1 : NUM2INT(vmax); keys = tcbdbfwmkeys(bdb, RSTRING_PTR(vprefix), RSTRING_LEN(vprefix), max); vary = listtovary(keys); tclistdel(keys); return vary; } static VALUE bdb_addint(VALUE vself, VALUE vkey, VALUE vnum){ VALUE vbdb; TCBDB *bdb; int num; vkey = StringValueEx(vkey); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); num = tcbdbaddint(bdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), NUM2INT(vnum)); return num == INT_MIN ? Qnil : INT2NUM(num); } static VALUE bdb_adddouble(VALUE vself, VALUE vkey, VALUE vnum){ VALUE vbdb; TCBDB *bdb; double num; vkey = StringValueEx(vkey); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); num = tcbdbadddouble(bdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), NUM2DBL(vnum)); return isnan(num) ? Qnil : rb_float_new(num); } static VALUE bdb_sync(VALUE vself){ VALUE vbdb; TCBDB *bdb; vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbsync(bdb) ? Qtrue : Qfalse; } static VALUE bdb_optimize(int argc, VALUE *argv, VALUE vself){ VALUE vbdb, vlmemb, vnmemb, vbnum, vapow, vfpow, vopts; TCBDB *bdb; int lmemb, nmemb, apow, fpow, opts; int64_t bnum; rb_scan_args(argc, argv, "06", &vlmemb, &vnmemb, &vbnum, &vapow, &vfpow, &vopts); lmemb = (vlmemb == Qnil) ? -1 : NUM2INT(vlmemb); nmemb = (vnmemb == Qnil) ? -1 : NUM2INT(vnmemb); bnum = (vbnum == Qnil) ? -1 : NUM2LL(vbnum); apow = (vapow == Qnil) ? -1 : NUM2INT(vapow); fpow = (vfpow == Qnil) ? -1 : NUM2INT(vfpow); opts = (vopts == Qnil) ? UINT8_MAX : NUM2INT(vopts); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdboptimize(bdb, lmemb, nmemb, bnum, apow, fpow, opts) ? Qtrue : Qfalse; } static VALUE bdb_vanish(VALUE vself){ VALUE vbdb; TCBDB *bdb; vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbvanish(bdb) ? Qtrue : Qfalse; } static VALUE bdb_copy(VALUE vself, VALUE vpath){ VALUE vbdb; TCBDB *bdb; Check_Type(vpath, T_STRING); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbcopy(bdb, RSTRING_PTR(vpath)) ? Qtrue : Qfalse; } static VALUE bdb_tranbegin(VALUE vself){ VALUE vbdb; TCBDB *bdb; vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbtranbegin(bdb) ? Qtrue : Qfalse; } static VALUE bdb_trancommit(VALUE vself){ VALUE vbdb; TCBDB *bdb; vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbtrancommit(bdb) ? Qtrue : Qfalse; } static VALUE bdb_tranabort(VALUE vself){ VALUE vbdb; TCBDB *bdb; vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbtranabort(bdb) ? Qtrue : Qfalse; } static VALUE bdb_path(VALUE vself){ VALUE vbdb; TCBDB *bdb; const char *path; vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); if(!(path = tcbdbpath(bdb))) return Qnil; return rb_str_new2(path); } static VALUE bdb_rnum(VALUE vself){ VALUE vbdb; TCBDB *bdb; vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return LL2NUM(tcbdbrnum(bdb)); } static VALUE bdb_fsiz(VALUE vself){ VALUE vbdb; TCBDB *bdb; vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return LL2NUM(tcbdbfsiz(bdb)); } static VALUE bdb_fetch(int argc, VALUE *argv, VALUE vself){ VALUE vbdb, vkey, vdef, vval; TCBDB *bdb; char *vbuf; int vsiz; rb_scan_args(argc, argv, "11", &vkey, &vdef); vkey = StringValueEx(vkey); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); if((vbuf = tcbdbget(bdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), &vsiz)) != NULL){ vval = rb_str_new(vbuf, vsiz); tcfree(vbuf); } else { vval = vdef; } return vval; } static VALUE bdb_check(VALUE vself, VALUE vkey){ VALUE vbdb; TCBDB *bdb; vkey = StringValueEx(vkey); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbvsiz(bdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey)) >= 0 ? Qtrue : Qfalse; } static VALUE bdb_check_value(VALUE vself, VALUE vval){ VALUE vbdb; TCBDB *bdb; BDBCUR *cur; const char *tvbuf; bool hit; int tvsiz; vval = StringValueEx(vval); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); hit = false; cur = tcbdbcurnew(bdb); tcbdbcurfirst(cur); while((tvbuf = tcbdbcurval3(cur, &tvsiz)) != NULL){ if(tvsiz == RSTRING_LEN(vval) && memcmp(tvbuf, RSTRING_PTR(vval), RSTRING_LEN(vval)) == 0){ hit = true; break; } tcbdbcurnext(cur); } tcbdbcurdel(cur); return hit ? Qtrue : Qfalse; } static VALUE bdb_get_reverse(VALUE vself, VALUE vval){ VALUE vbdb, vrv; TCBDB *bdb; BDBCUR *cur; const char *tvbuf, *tkbuf; int tvsiz, tksiz; vval = StringValueEx(vval); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); vrv = Qnil; cur = tcbdbcurnew(bdb); tcbdbcurfirst(cur); while((tvbuf = tcbdbcurval3(cur, &tvsiz)) != NULL){ if(tvsiz == RSTRING_LEN(vval) && memcmp(tvbuf, RSTRING_PTR(vval), RSTRING_LEN(vval)) == 0){ if((tkbuf = tcbdbcurkey3(cur, &tksiz)) != NULL) vrv = rb_str_new(tkbuf, tksiz); break; } tcbdbcurnext(cur); } tcbdbcurdel(cur); return vrv; } static VALUE bdb_empty(VALUE vself){ VALUE vbdb; TCBDB *bdb; vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); return tcbdbrnum(bdb) < 1 ? Qtrue : Qfalse; } static VALUE bdb_each(VALUE vself){ VALUE vbdb, vrv; TCBDB *bdb; BDBCUR *cur; TCXSTR *kxstr, *vxstr; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); vrv = Qnil; kxstr = tcxstrnew(); vxstr = tcxstrnew(); cur = tcbdbcurnew(bdb); tcbdbcurfirst(cur); while(tcbdbcurrec(cur, kxstr, vxstr)){ vrv = rb_yield_values(2, rb_str_new(tcxstrptr(kxstr), tcxstrsize(kxstr)), rb_str_new(tcxstrptr(vxstr), tcxstrsize(vxstr))); tcbdbcurnext(cur); } tcbdbcurdel(cur); tcxstrdel(vxstr); tcxstrdel(kxstr); return vrv; } static VALUE bdb_each_key(VALUE vself){ VALUE vbdb, vrv; TCBDB *bdb; BDBCUR *cur; const char *kbuf; int ksiz; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); vrv = Qnil; cur = tcbdbcurnew(bdb); tcbdbcurfirst(cur); while((kbuf = tcbdbcurkey3(cur, &ksiz)) != NULL){ vrv = rb_yield(rb_str_new(kbuf, ksiz)); tcbdbcurnext(cur); } tcbdbcurdel(cur); return vrv; } static VALUE bdb_each_value(VALUE vself){ VALUE vbdb, vrv; TCBDB *bdb; BDBCUR *cur; const char *vbuf; int vsiz; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); vrv = Qnil; cur = tcbdbcurnew(bdb); tcbdbcurfirst(cur); while((vbuf = tcbdbcurval3(cur, &vsiz)) != NULL){ vrv = rb_yield(rb_str_new(vbuf, vsiz)); tcbdbcurnext(cur); } tcbdbcurdel(cur); return vrv; } static VALUE bdb_keys(VALUE vself){ VALUE vbdb, vary; TCBDB *bdb; BDBCUR *cur; const char *kbuf; int ksiz; vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); vary = rb_ary_new2(tcbdbrnum(bdb)); cur = tcbdbcurnew(bdb); tcbdbcurfirst(cur); while((kbuf = tcbdbcurkey3(cur, &ksiz)) != NULL){ rb_ary_push(vary, rb_str_new(kbuf, ksiz)); tcbdbcurnext(cur); } tcbdbcurdel(cur); return vary; } static VALUE bdb_values(VALUE vself){ VALUE vbdb, vary; TCBDB *bdb; BDBCUR *cur; const char *vbuf; int vsiz; vbdb = rb_iv_get(vself, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); vary = rb_ary_new2(tcbdbrnum(bdb)); cur = tcbdbcurnew(bdb); tcbdbcurfirst(cur); while((vbuf = tcbdbcurval3(cur, &vsiz)) != NULL){ rb_ary_push(vary, rb_str_new(vbuf, vsiz)); tcbdbcurnext(cur); } tcbdbcurdel(cur); return vary; } static void bdbcur_init(void){ cls_bdbcur = rb_define_class_under(mod_tokyocabinet, "BDBCUR", rb_cObject); cls_bdbcur_data = rb_define_class_under(mod_tokyocabinet, "BDBCUR_data", rb_cObject); rb_define_const(cls_bdbcur, "CPCURRENT", INT2NUM(BDBCPCURRENT)); rb_define_const(cls_bdbcur, "CPBEFORE", INT2NUM(BDBCPBEFORE)); rb_define_const(cls_bdbcur, "CPAFTER", INT2NUM(BDBCPAFTER)); rb_define_private_method(cls_bdbcur, "initialize", bdbcur_initialize, 1); rb_define_method(cls_bdbcur, "first", bdbcur_first, 0); rb_define_method(cls_bdbcur, "last", bdbcur_last, 0); rb_define_method(cls_bdbcur, "jump", bdbcur_jump, 1); rb_define_method(cls_bdbcur, "prev", bdbcur_prev, 0); rb_define_method(cls_bdbcur, "next", bdbcur_next, 0); rb_define_method(cls_bdbcur, "put", bdbcur_put, -1); rb_define_method(cls_bdbcur, "out", bdbcur_out, 0); rb_define_method(cls_bdbcur, "key", bdbcur_key, 0); rb_define_method(cls_bdbcur, "val", bdbcur_val, 0); } static VALUE bdbcur_initialize(VALUE vself, VALUE vbdb){ VALUE vcur; TCBDB *bdb; BDBCUR *cur; Check_Type(vbdb, T_OBJECT); vbdb = rb_iv_get(vbdb, BDBVNDATA); Data_Get_Struct(vbdb, TCBDB, bdb); cur = tcbdbcurnew(bdb); vcur = Data_Wrap_Struct(cls_bdbcur_data, 0, tcbdbcurdel, cur); rb_iv_set(vself, BDBCURVNDATA, vcur); rb_iv_set(vself, BDBVNDATA, vbdb); return Qnil; } static VALUE bdbcur_first(VALUE vself){ VALUE vcur; BDBCUR *cur; vcur = rb_iv_get(vself, BDBCURVNDATA); Data_Get_Struct(vcur, BDBCUR, cur); return tcbdbcurfirst(cur) ? Qtrue : Qfalse; } static VALUE bdbcur_last(VALUE vself){ VALUE vcur; BDBCUR *cur; vcur = rb_iv_get(vself, BDBCURVNDATA); Data_Get_Struct(vcur, BDBCUR, cur); return tcbdbcurlast(cur) ? Qtrue : Qfalse; } static VALUE bdbcur_jump(VALUE vself, VALUE vkey){ VALUE vcur; BDBCUR *cur; vkey = StringValueEx(vkey); vcur = rb_iv_get(vself, BDBCURVNDATA); Data_Get_Struct(vcur, BDBCUR, cur); return tcbdbcurjump(cur, RSTRING_PTR(vkey), RSTRING_LEN(vkey)) ? Qtrue : Qfalse; } static VALUE bdbcur_prev(VALUE vself){ VALUE vcur; BDBCUR *cur; vcur = rb_iv_get(vself, BDBCURVNDATA); Data_Get_Struct(vcur, BDBCUR, cur); return tcbdbcurprev(cur) ? Qtrue : Qfalse; } static VALUE bdbcur_next(VALUE vself){ VALUE vcur; BDBCUR *cur; vcur = rb_iv_get(vself, BDBCURVNDATA); Data_Get_Struct(vcur, BDBCUR, cur); return tcbdbcurnext(cur) ? Qtrue : Qfalse; } static VALUE bdbcur_put(int argc, VALUE *argv, VALUE vself){ VALUE vcur, vval, vcpmode; BDBCUR *cur; int cpmode; rb_scan_args(argc, argv, "11", &vval, &vcpmode); vval = StringValueEx(vval); cpmode = (vcpmode == Qnil) ? BDBCPCURRENT : NUM2INT(vcpmode); vcur = rb_iv_get(vself, BDBCURVNDATA); Data_Get_Struct(vcur, BDBCUR, cur); return tcbdbcurput(cur, RSTRING_PTR(vval), RSTRING_LEN(vval), cpmode) ? Qtrue : Qfalse; } static VALUE bdbcur_out(VALUE vself){ VALUE vcur; BDBCUR *cur; vcur = rb_iv_get(vself, BDBCURVNDATA); Data_Get_Struct(vcur, BDBCUR, cur); return tcbdbcurout(cur) ? Qtrue : Qfalse; } static VALUE bdbcur_key(VALUE vself){ VALUE vcur, vkey; BDBCUR *cur; char *kbuf; int ksiz; vcur = rb_iv_get(vself, BDBCURVNDATA); Data_Get_Struct(vcur, BDBCUR, cur); if(!(kbuf = tcbdbcurkey(cur, &ksiz))) return Qnil; vkey = rb_str_new(kbuf, ksiz); tcfree(kbuf); return vkey; } static VALUE bdbcur_val(VALUE vself){ VALUE vcur, vval; BDBCUR *cur; char *vbuf; int vsiz; vcur = rb_iv_get(vself, BDBCURVNDATA); Data_Get_Struct(vcur, BDBCUR, cur); if(!(vbuf = tcbdbcurval(cur, &vsiz))) return Qnil; vval = rb_str_new(vbuf, vsiz); tcfree(vbuf); return vval; } static void fdb_init(void){ cls_fdb = rb_define_class_under(mod_tokyocabinet, "FDB", rb_cObject); cls_fdb_data = rb_define_class_under(mod_tokyocabinet, "FDB_data", rb_cObject); rb_define_const(cls_fdb, "ESUCCESS", INT2NUM(TCESUCCESS)); rb_define_const(cls_fdb, "ETHREAD", INT2NUM(TCETHREAD)); rb_define_const(cls_fdb, "EINVALID", INT2NUM(TCEINVALID)); rb_define_const(cls_fdb, "ENOFILE", INT2NUM(TCENOFILE)); rb_define_const(cls_fdb, "ENOPERM", INT2NUM(TCENOPERM)); rb_define_const(cls_fdb, "EMETA", INT2NUM(TCEMETA)); rb_define_const(cls_fdb, "ERHEAD", INT2NUM(TCERHEAD)); rb_define_const(cls_fdb, "EOPEN", INT2NUM(TCEOPEN)); rb_define_const(cls_fdb, "ECLOSE", INT2NUM(TCECLOSE)); rb_define_const(cls_fdb, "ETRUNC", INT2NUM(TCETRUNC)); rb_define_const(cls_fdb, "ESYNC", INT2NUM(TCESYNC)); rb_define_const(cls_fdb, "ESTAT", INT2NUM(TCESTAT)); rb_define_const(cls_fdb, "ESEEK", INT2NUM(TCESEEK)); rb_define_const(cls_fdb, "EREAD", INT2NUM(TCEREAD)); rb_define_const(cls_fdb, "EWRITE", INT2NUM(TCEWRITE)); rb_define_const(cls_fdb, "EMMAP", INT2NUM(TCEMMAP)); rb_define_const(cls_fdb, "ELOCK", INT2NUM(TCELOCK)); rb_define_const(cls_fdb, "EUNLINK", INT2NUM(TCEUNLINK)); rb_define_const(cls_fdb, "ERENAME", INT2NUM(TCERENAME)); rb_define_const(cls_fdb, "EMKDIR", INT2NUM(TCEMKDIR)); rb_define_const(cls_fdb, "ERMDIR", INT2NUM(TCERMDIR)); rb_define_const(cls_fdb, "EKEEP", INT2NUM(TCEKEEP)); rb_define_const(cls_fdb, "ENOREC", INT2NUM(TCENOREC)); rb_define_const(cls_fdb, "EMISC", INT2NUM(TCEMISC)); rb_define_const(cls_fdb, "OREADER", INT2NUM(FDBOREADER)); rb_define_const(cls_fdb, "OWRITER", INT2NUM(FDBOWRITER)); rb_define_const(cls_fdb, "OCREAT", INT2NUM(FDBOCREAT)); rb_define_const(cls_fdb, "OTRUNC", INT2NUM(FDBOTRUNC)); rb_define_const(cls_fdb, "ONOLCK", INT2NUM(FDBONOLCK)); rb_define_const(cls_fdb, "OLCKNB", INT2NUM(FDBOLCKNB)); rb_define_private_method(cls_fdb, "initialize", fdb_initialize, 0); rb_define_method(cls_fdb, "errmsg", fdb_errmsg, -1); rb_define_method(cls_fdb, "ecode", fdb_ecode, 0); rb_define_method(cls_fdb, "tune", fdb_tune, -1); rb_define_method(cls_fdb, "open", fdb_open, -1); rb_define_method(cls_fdb, "close", fdb_close, 0); rb_define_method(cls_fdb, "put", fdb_put, 2); rb_define_method(cls_fdb, "putkeep", fdb_putkeep, 2); rb_define_method(cls_fdb, "putcat", fdb_putcat, 2); rb_define_method(cls_fdb, "out", fdb_out, 1); rb_define_method(cls_fdb, "get", fdb_get, 1); rb_define_method(cls_fdb, "vsiz", fdb_vsiz, 1); rb_define_method(cls_fdb, "iterinit", fdb_iterinit, 0); rb_define_method(cls_fdb, "iternext", fdb_iternext, 0); rb_define_method(cls_fdb, "range", fdb_range, -1); rb_define_method(cls_fdb, "addint", fdb_addint, 2); rb_define_method(cls_fdb, "adddouble", fdb_adddouble, 2); rb_define_method(cls_fdb, "sync", fdb_sync, 0); rb_define_method(cls_fdb, "optimize", fdb_optimize, -1); rb_define_method(cls_fdb, "vanish", fdb_vanish, 0); rb_define_method(cls_fdb, "copy", fdb_copy, 1); rb_define_method(cls_fdb, "tranbegin", fdb_tranbegin, 0); rb_define_method(cls_fdb, "trancommit", fdb_trancommit, 0); rb_define_method(cls_fdb, "tranabort", fdb_tranabort, 0); rb_define_method(cls_fdb, "path", fdb_path, 0); rb_define_method(cls_fdb, "rnum", fdb_rnum, 0); rb_define_method(cls_fdb, "fsiz", fdb_fsiz, 0); rb_define_method(cls_fdb, "[]", fdb_get, 1); rb_define_method(cls_fdb, "[]=", fdb_put, 2); rb_define_method(cls_fdb, "store", fdb_put, 2); rb_define_method(cls_fdb, "delete", fdb_out, 1); rb_define_method(cls_fdb, "fetch", fdb_fetch, -1); rb_define_method(cls_fdb, "has_key?", fdb_check, 1); rb_define_method(cls_fdb, "key?", fdb_check, 1); rb_define_method(cls_fdb, "include?", fdb_check, 1); rb_define_method(cls_fdb, "member?", fdb_check, 1); rb_define_method(cls_fdb, "has_value?", fdb_check_value, 1); rb_define_method(cls_fdb, "value?", fdb_check_value, 1); rb_define_method(cls_fdb, "key", fdb_get_reverse, 1); rb_define_method(cls_fdb, "clear", fdb_vanish, 0); rb_define_method(cls_fdb, "size", fdb_rnum, 0); rb_define_method(cls_fdb, "length", fdb_rnum, 0); rb_define_method(cls_fdb, "empty?", fdb_empty, 0); rb_define_method(cls_fdb, "each", fdb_each, 0); rb_define_method(cls_fdb, "each_pair", fdb_each, 0); rb_define_method(cls_fdb, "each_key", fdb_each_key, 0); rb_define_method(cls_fdb, "each_value", fdb_each_value, 0); rb_define_method(cls_fdb, "keys", fdb_keys, 0); rb_define_method(cls_fdb, "values", fdb_values, 0); } static VALUE fdb_initialize(VALUE vself){ VALUE vfdb; TCFDB *fdb; fdb = tcfdbnew(); tcfdbsetmutex(fdb); vfdb = Data_Wrap_Struct(cls_fdb_data, 0, tcfdbdel, fdb); rb_iv_set(vself, FDBVNDATA, vfdb); return Qnil; } static VALUE fdb_errmsg(int argc, VALUE *argv, VALUE vself){ VALUE vfdb, vecode; TCFDB *fdb; const char *msg; int ecode; rb_scan_args(argc, argv, "01", &vecode); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); ecode = (vecode == Qnil) ? tcfdbecode(fdb) : NUM2INT(vecode); msg = tcfdberrmsg(ecode); return rb_str_new2(msg); } static VALUE fdb_ecode(VALUE vself){ VALUE vfdb; TCFDB *fdb; vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return INT2NUM(tcfdbecode(fdb)); } static VALUE fdb_tune(int argc, VALUE *argv, VALUE vself){ VALUE vfdb, vwidth, vlimsiz; TCFDB *fdb; int width; int64_t limsiz; rb_scan_args(argc, argv, "02", &vwidth, &vlimsiz); width = (vwidth == Qnil) ? -1 : NUM2INT(vwidth); limsiz = (vlimsiz == Qnil) ? -1 : NUM2LL(vlimsiz); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbtune(fdb, width, limsiz) ? Qtrue : Qfalse; } static VALUE fdb_open(int argc, VALUE *argv, VALUE vself){ VALUE vfdb, vpath, vomode; TCFDB *fdb; int omode; rb_scan_args(argc, argv, "11", &vpath, &vomode); Check_Type(vpath, T_STRING); omode = (vomode == Qnil) ? FDBOREADER : NUM2INT(vomode); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbopen(fdb, RSTRING_PTR(vpath), omode) ? Qtrue : Qfalse; } static VALUE fdb_close(VALUE vself){ VALUE vfdb; TCFDB *fdb; vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbclose(fdb) ? Qtrue : Qfalse; } static VALUE fdb_put(VALUE vself, VALUE vkey, VALUE vval){ VALUE vfdb; TCFDB *fdb; vkey = StringValueEx(vkey); vval = StringValueEx(vval); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbput2(fdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)) ? Qtrue : Qfalse; } static VALUE fdb_putkeep(VALUE vself, VALUE vkey, VALUE vval){ VALUE vfdb; TCFDB *fdb; vkey = StringValueEx(vkey); vval = StringValueEx(vval); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbputkeep2(fdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)) ? Qtrue : Qfalse; } static VALUE fdb_putcat(VALUE vself, VALUE vkey, VALUE vval){ VALUE vfdb; TCFDB *fdb; vkey = StringValueEx(vkey); vval = StringValueEx(vval); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbputcat2(fdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)) ? Qtrue : Qfalse; } static VALUE fdb_out(VALUE vself, VALUE vkey){ VALUE vfdb; TCFDB *fdb; vkey = StringValueEx(vkey); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbout2(fdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey)) ? Qtrue : Qfalse; } static VALUE fdb_get(VALUE vself, VALUE vkey){ VALUE vfdb, vval; TCFDB *fdb; char *vbuf; int vsiz; vkey = StringValueEx(vkey); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); if(!(vbuf = tcfdbget2(fdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), &vsiz))) return Qnil; vval = rb_str_new(vbuf, vsiz); tcfree(vbuf); return vval; } static VALUE fdb_vsiz(VALUE vself, VALUE vkey){ VALUE vfdb; TCFDB *fdb; vkey = StringValueEx(vkey); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return INT2NUM(tcfdbvsiz2(fdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey))); } static VALUE fdb_iterinit(VALUE vself){ VALUE vfdb; TCFDB *fdb; vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbiterinit(fdb) ? Qtrue : Qfalse; } static VALUE fdb_iternext(VALUE vself){ VALUE vfdb, vval; TCFDB *fdb; char *vbuf; int vsiz; vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); if(!(vbuf = tcfdbiternext2(fdb, &vsiz))) return Qnil; vval = rb_str_new(vbuf, vsiz); tcfree(vbuf); return vval; } static VALUE fdb_range(int argc, VALUE *argv, VALUE vself){ VALUE vfdb, vinterval, vmax, vary; TCFDB *fdb; TCLIST *keys; int max; rb_scan_args(argc, argv, "11", &vinterval, &vmax); vinterval = StringValueEx(vinterval); max = (vmax == Qnil) ? -1 : NUM2INT(vmax); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); keys = tcfdbrange4(fdb, RSTRING_PTR(vinterval), RSTRING_LEN(vinterval), max); vary = listtovary(keys); tclistdel(keys); return vary; } static VALUE fdb_addint(VALUE vself, VALUE vkey, VALUE vnum){ VALUE vfdb; TCFDB *fdb; int num; vkey = StringValueEx(vkey); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); num = tcfdbaddint(fdb, tcfdbkeytoid(RSTRING_PTR(vkey), RSTRING_LEN(vkey)), NUM2INT(vnum)); return num == INT_MIN ? Qnil : INT2NUM(num); } static VALUE fdb_adddouble(VALUE vself, VALUE vkey, VALUE vnum){ VALUE vfdb; TCFDB *fdb; double num; vkey = StringValueEx(vkey); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); num = tcfdbadddouble(fdb, tcfdbkeytoid(RSTRING_PTR(vkey), RSTRING_LEN(vkey)), NUM2DBL(vnum)); return isnan(num) ? Qnil : rb_float_new(num); } static VALUE fdb_sync(VALUE vself){ VALUE vfdb; TCFDB *fdb; vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbsync(fdb) ? Qtrue : Qfalse; } static VALUE fdb_optimize(int argc, VALUE *argv, VALUE vself){ VALUE vfdb, vwidth, vlimsiz; TCFDB *fdb; int width; int64_t limsiz; rb_scan_args(argc, argv, "02", &vwidth, &vlimsiz); width = (vwidth == Qnil) ? -1 : NUM2INT(vwidth); limsiz = (vlimsiz == Qnil) ? -1 : NUM2LL(vlimsiz); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdboptimize(fdb, width, limsiz) ? Qtrue : Qfalse; } static VALUE fdb_vanish(VALUE vself){ VALUE vfdb; TCFDB *fdb; vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbvanish(fdb) ? Qtrue : Qfalse; } static VALUE fdb_copy(VALUE vself, VALUE vpath){ VALUE vfdb; TCFDB *fdb; Check_Type(vpath, T_STRING); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbcopy(fdb, RSTRING_PTR(vpath)) ? Qtrue : Qfalse; } static VALUE fdb_tranbegin(VALUE vself){ VALUE vfdb; TCFDB *fdb; vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbtranbegin(fdb) ? Qtrue : Qfalse; } static VALUE fdb_trancommit(VALUE vself){ VALUE vfdb; TCFDB *fdb; vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbtrancommit(fdb) ? Qtrue : Qfalse; } static VALUE fdb_tranabort(VALUE vself){ VALUE vfdb; TCFDB *fdb; vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbtranabort(fdb) ? Qtrue : Qfalse; } static VALUE fdb_path(VALUE vself){ VALUE vfdb; TCFDB *fdb; const char *path; vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); if(!(path = tcfdbpath(fdb))) return Qnil; return rb_str_new2(path); } static VALUE fdb_rnum(VALUE vself){ VALUE vfdb; TCFDB *fdb; vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return LL2NUM(tcfdbrnum(fdb)); } static VALUE fdb_fsiz(VALUE vself){ VALUE vfdb; TCFDB *fdb; vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return LL2NUM(tcfdbfsiz(fdb)); } static VALUE fdb_fetch(int argc, VALUE *argv, VALUE vself){ VALUE vfdb, vkey, vdef, vval; TCFDB *fdb; char *vbuf; int vsiz; rb_scan_args(argc, argv, "11", &vkey, &vdef); vkey = StringValueEx(vkey); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); if((vbuf = tcfdbget2(fdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), &vsiz)) != NULL){ vval = rb_str_new(vbuf, vsiz); tcfree(vbuf); } else { vval = vdef; } return vval; } static VALUE fdb_check(VALUE vself, VALUE vkey){ VALUE vfdb; TCFDB *fdb; vkey = StringValueEx(vkey); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbvsiz2(fdb, RSTRING_PTR(vkey), RSTRING_LEN(vkey)) >= 0 ? Qtrue : Qfalse; } static VALUE fdb_check_value(VALUE vself, VALUE vval){ VALUE vfdb; TCFDB *fdb; char *tvbuf; bool hit; int tvsiz; uint64_t id; vval = StringValueEx(vval); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); hit = false; tcfdbiterinit(fdb); while((id = tcfdbiternext(fdb)) > 0){ tvbuf = tcfdbget(fdb, id, &tvsiz); if(tvbuf && tvsiz == RSTRING_LEN(vval) && memcmp(tvbuf, RSTRING_PTR(vval), RSTRING_LEN(vval)) == 0){ tcfree(tvbuf); hit = true; break; } tcfree(tvbuf); } return hit ? Qtrue : Qfalse; } static VALUE fdb_get_reverse(VALUE vself, VALUE vval){ VALUE vfdb, vrv; TCFDB *fdb; char *tvbuf, kbuf[NUMBUFSIZ]; int tvsiz, ksiz; uint64_t id; vval = StringValueEx(vval); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); vrv = Qnil; tcfdbiterinit(fdb); while((id = tcfdbiternext(fdb)) > 0){ tvbuf = tcfdbget(fdb, id, &tvsiz); if(tvbuf && tvsiz == RSTRING_LEN(vval) && memcmp(tvbuf, RSTRING_PTR(vval), RSTRING_LEN(vval)) == 0){ tcfree(tvbuf); ksiz = sprintf(kbuf, "%llu", (unsigned long long)id); vrv = rb_str_new(kbuf, ksiz); break; } tcfree(tvbuf); } return vrv; } static VALUE fdb_empty(VALUE vself){ VALUE vfdb; TCFDB *fdb; vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); return tcfdbrnum(fdb) < 1 ? Qtrue : Qfalse; } static VALUE fdb_each(VALUE vself){ VALUE vfdb, vrv; TCFDB *fdb; char *vbuf, kbuf[NUMBUFSIZ]; int vsiz, ksiz; uint64_t id; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); vrv = Qnil; tcfdbiterinit(fdb); while((id = tcfdbiternext(fdb)) > 0){ vbuf = tcfdbget(fdb, id, &vsiz); if(vbuf){ ksiz = sprintf(kbuf, "%llu", (unsigned long long)id); vrv = rb_yield_values(2, rb_str_new(kbuf, ksiz), rb_str_new(vbuf, vsiz)); } tcfree(vbuf); } return vrv; } static VALUE fdb_each_key(VALUE vself){ VALUE vfdb, vrv; TCFDB *fdb; char kbuf[NUMBUFSIZ]; int ksiz; uint64_t id; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); vrv = Qnil; tcfdbiterinit(fdb); while((id = tcfdbiternext(fdb)) > 0){ ksiz = sprintf(kbuf, "%llu", (unsigned long long)id); vrv = rb_yield(rb_str_new(kbuf, ksiz)); } return vrv; } static VALUE fdb_each_value(VALUE vself){ VALUE vfdb, vrv; TCFDB *fdb; char *vbuf; int vsiz; uint64_t id; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); vrv = Qnil; tcfdbiterinit(fdb); while((id = tcfdbiternext(fdb)) > 0){ vbuf = tcfdbget(fdb, id, &vsiz); if(vbuf){ vrv = rb_yield(rb_str_new(vbuf, vsiz)); } free(vbuf); } return vrv; } static VALUE fdb_keys(VALUE vself){ VALUE vfdb, vary; TCFDB *fdb; char kbuf[NUMBUFSIZ]; int ksiz; uint64_t id; vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); vary = rb_ary_new2(tcfdbrnum(fdb)); tcfdbiterinit(fdb); while((id = tcfdbiternext(fdb)) > 0){ ksiz = sprintf(kbuf, "%llu", (unsigned long long)id); rb_ary_push(vary, rb_str_new(kbuf, ksiz)); } return vary; } static VALUE fdb_values(VALUE vself){ VALUE vfdb, vary; TCFDB *fdb; char *vbuf; int vsiz; uint64_t id; vfdb = rb_iv_get(vself, FDBVNDATA); Data_Get_Struct(vfdb, TCFDB, fdb); vary = rb_ary_new2(tcfdbrnum(fdb)); tcfdbiterinit(fdb); while((id = tcfdbiternext(fdb)) > 0){ vbuf = tcfdbget(fdb, id, &vsiz); if(vbuf){ rb_ary_push(vary, rb_str_new(vbuf, vsiz)); } free(vbuf); } return vary; } static void tdb_init(void){ cls_tdb = rb_define_class_under(mod_tokyocabinet, "TDB", rb_cObject); cls_tdb_data = rb_define_class_under(mod_tokyocabinet, "TDB_data", rb_cObject); rb_define_const(cls_tdb, "ESUCCESS", INT2NUM(TCESUCCESS)); rb_define_const(cls_tdb, "ETHREAD", INT2NUM(TCETHREAD)); rb_define_const(cls_tdb, "EINVALID", INT2NUM(TCEINVALID)); rb_define_const(cls_tdb, "ENOFILE", INT2NUM(TCENOFILE)); rb_define_const(cls_tdb, "ENOPERM", INT2NUM(TCENOPERM)); rb_define_const(cls_tdb, "EMETA", INT2NUM(TCEMETA)); rb_define_const(cls_tdb, "ERHEAD", INT2NUM(TCERHEAD)); rb_define_const(cls_tdb, "EOPEN", INT2NUM(TCEOPEN)); rb_define_const(cls_tdb, "ECLOSE", INT2NUM(TCECLOSE)); rb_define_const(cls_tdb, "ETRUNC", INT2NUM(TCETRUNC)); rb_define_const(cls_tdb, "ESYNC", INT2NUM(TCESYNC)); rb_define_const(cls_tdb, "ESTAT", INT2NUM(TCESTAT)); rb_define_const(cls_tdb, "ESEEK", INT2NUM(TCESEEK)); rb_define_const(cls_tdb, "EREAD", INT2NUM(TCEREAD)); rb_define_const(cls_tdb, "EWRITE", INT2NUM(TCEWRITE)); rb_define_const(cls_tdb, "EMMAP", INT2NUM(TCEMMAP)); rb_define_const(cls_tdb, "ELOCK", INT2NUM(TCELOCK)); rb_define_const(cls_tdb, "EUNLINK", INT2NUM(TCEUNLINK)); rb_define_const(cls_tdb, "ERENAME", INT2NUM(TCERENAME)); rb_define_const(cls_tdb, "EMKDIR", INT2NUM(TCEMKDIR)); rb_define_const(cls_tdb, "ERMDIR", INT2NUM(TCERMDIR)); rb_define_const(cls_tdb, "EKEEP", INT2NUM(TCEKEEP)); rb_define_const(cls_tdb, "ENOREC", INT2NUM(TCENOREC)); rb_define_const(cls_tdb, "EMISC", INT2NUM(TCEMISC)); rb_define_const(cls_tdb, "TLARGE", INT2NUM(TDBTLARGE)); rb_define_const(cls_tdb, "TDEFLATE", INT2NUM(TDBTDEFLATE)); rb_define_const(cls_tdb, "TBZIP", INT2NUM(TDBTBZIP)); rb_define_const(cls_tdb, "TTCBS", INT2NUM(TDBTTCBS)); rb_define_const(cls_tdb, "OREADER", INT2NUM(TDBOREADER)); rb_define_const(cls_tdb, "OWRITER", INT2NUM(TDBOWRITER)); rb_define_const(cls_tdb, "OCREAT", INT2NUM(TDBOCREAT)); rb_define_const(cls_tdb, "OTRUNC", INT2NUM(TDBOTRUNC)); rb_define_const(cls_tdb, "ONOLCK", INT2NUM(TDBONOLCK)); rb_define_const(cls_tdb, "OLCKNB", INT2NUM(TDBOLCKNB)); rb_define_const(cls_tdb, "OTSYNC", INT2NUM(TDBOTSYNC)); rb_define_const(cls_tdb, "ITLEXICAL", INT2NUM(TDBITLEXICAL)); rb_define_const(cls_tdb, "ITDECIMAL", INT2NUM(TDBITDECIMAL)); rb_define_const(cls_tdb, "ITTOKEN", INT2NUM(TDBITTOKEN)); rb_define_const(cls_tdb, "ITQGRAM", INT2NUM(TDBITQGRAM)); rb_define_const(cls_tdb, "ITVOID", INT2NUM(TDBITVOID)); rb_define_const(cls_tdb, "ITKEEP", INT2NUM(TDBITKEEP)); rb_define_private_method(cls_tdb, "initialize", tdb_initialize, 0); rb_define_method(cls_tdb, "errmsg", tdb_errmsg, -1); rb_define_method(cls_tdb, "ecode", tdb_ecode, 0); rb_define_method(cls_tdb, "tune", tdb_tune, -1); rb_define_method(cls_tdb, "setcache", tdb_setcache, -1); rb_define_method(cls_tdb, "setxmsiz", tdb_setxmsiz, -1); rb_define_method(cls_tdb, "setdfunit", tdb_setdfunit, -1); rb_define_method(cls_tdb, "open", tdb_open, -1); rb_define_method(cls_tdb, "close", tdb_close, 0); rb_define_method(cls_tdb, "put", tdb_put, 2); rb_define_method(cls_tdb, "putkeep", tdb_putkeep, 2); rb_define_method(cls_tdb, "putcat", tdb_putcat, 2); rb_define_method(cls_tdb, "out", tdb_out, 1); rb_define_method(cls_tdb, "get", tdb_get, 1); rb_define_method(cls_tdb, "vsiz", tdb_vsiz, 1); rb_define_method(cls_tdb, "iterinit", tdb_iterinit, 0); rb_define_method(cls_tdb, "iternext", tdb_iternext, 0); rb_define_method(cls_tdb, "fwmkeys", tdb_fwmkeys, -1); rb_define_method(cls_tdb, "addint", tdb_addint, 2); rb_define_method(cls_tdb, "adddouble", tdb_adddouble, 2); rb_define_method(cls_tdb, "sync", tdb_sync, 0); rb_define_method(cls_tdb, "optimize", tdb_optimize, -1); rb_define_method(cls_tdb, "vanish", tdb_vanish, 0); rb_define_method(cls_tdb, "copy", tdb_copy, 1); rb_define_method(cls_tdb, "tranbegin", tdb_tranbegin, 0); rb_define_method(cls_tdb, "trancommit", tdb_trancommit, 0); rb_define_method(cls_tdb, "tranabort", tdb_tranabort, 0); rb_define_method(cls_tdb, "path", tdb_path, 0); rb_define_method(cls_tdb, "rnum", tdb_rnum, 0); rb_define_method(cls_tdb, "fsiz", tdb_fsiz, 0); rb_define_method(cls_tdb, "setindex", tdb_setindex, 2); rb_define_method(cls_tdb, "genuid", tdb_genuid, 0); rb_define_method(cls_tdb, "[]", tdb_get, 1); rb_define_method(cls_tdb, "[]=", tdb_put, 2); rb_define_method(cls_tdb, "store", tdb_put, 2); rb_define_method(cls_tdb, "delete", tdb_out, 1); rb_define_method(cls_tdb, "fetch", tdb_fetch, -1); rb_define_method(cls_tdb, "has_key?", tdb_check, 1); rb_define_method(cls_tdb, "key?", tdb_check, 1); rb_define_method(cls_tdb, "include?", tdb_check, 1); rb_define_method(cls_tdb, "member?", tdb_check, 1); rb_define_method(cls_tdb, "clear", tdb_vanish, 0); rb_define_method(cls_tdb, "size", tdb_rnum, 0); rb_define_method(cls_tdb, "length", tdb_rnum, 0); rb_define_method(cls_tdb, "empty?", tdb_empty, 0); rb_define_method(cls_tdb, "each", tdb_each, 0); rb_define_method(cls_tdb, "each_pair", tdb_each, 0); rb_define_method(cls_tdb, "each_key", tdb_each_key, 0); rb_define_method(cls_tdb, "each_value", tdb_each_value, 0); rb_define_method(cls_tdb, "keys", tdb_keys, 0); rb_define_method(cls_tdb, "values", tdb_values, 0); } static VALUE tdb_initialize(VALUE vself){ VALUE vtdb; TCTDB *tdb; tdb = tctdbnew(); tctdbsetmutex(tdb); vtdb = Data_Wrap_Struct(cls_tdb_data, 0, tctdbdel, tdb); rb_iv_set(vself, TDBVNDATA, vtdb); return Qnil; } static VALUE tdb_errmsg(int argc, VALUE *argv, VALUE vself){ VALUE vtdb, vecode; TCTDB *tdb; const char *msg; int ecode; rb_scan_args(argc, argv, "01", &vecode); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); ecode = (vecode == Qnil) ? tctdbecode(tdb) : NUM2INT(vecode); msg = tctdberrmsg(ecode); return rb_str_new2(msg); } static VALUE tdb_ecode(VALUE vself){ VALUE vtdb; TCTDB *tdb; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return INT2NUM(tctdbecode(tdb)); } static VALUE tdb_tune(int argc, VALUE *argv, VALUE vself){ VALUE vtdb, vbnum, vapow, vfpow, vopts; TCTDB *tdb; int apow, fpow, opts; int64_t bnum; rb_scan_args(argc, argv, "04", &vbnum, &vapow, &vfpow, &vopts); bnum = (vbnum == Qnil) ? -1 : NUM2LL(vbnum); apow = (vapow == Qnil) ? -1 : NUM2INT(vapow); fpow = (vfpow == Qnil) ? -1 : NUM2INT(vfpow); opts = (vopts == Qnil) ? 0 : NUM2INT(vopts); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbtune(tdb, bnum, apow, fpow, opts) ? Qtrue : Qfalse; } static VALUE tdb_setcache(int argc, VALUE *argv, VALUE vself){ VALUE vtdb, vrcnum, vlcnum, vncnum; TCTDB *tdb; int rcnum, lcnum, ncnum; rb_scan_args(argc, argv, "03", &vrcnum, &vlcnum, &vncnum); rcnum = (vrcnum == Qnil) ? -1 : NUM2INT(vrcnum); lcnum = (vlcnum == Qnil) ? -1 : NUM2INT(vlcnum); ncnum = (vncnum == Qnil) ? -1 : NUM2INT(vncnum); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbsetcache(tdb, rcnum, lcnum, ncnum) ? Qtrue : Qfalse; } static VALUE tdb_setxmsiz(int argc, VALUE *argv, VALUE vself){ VALUE vtdb, vxmsiz; TCTDB *tdb; int64_t xmsiz; rb_scan_args(argc, argv, "01", &vxmsiz); xmsiz = (vxmsiz == Qnil) ? -1 : NUM2LL(vxmsiz); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbsetxmsiz(tdb, xmsiz) ? Qtrue : Qfalse; } static VALUE tdb_setdfunit(int argc, VALUE *argv, VALUE vself){ VALUE vtdb, vdfunit; TCTDB *tdb; int32_t dfunit; rb_scan_args(argc, argv, "01", &vdfunit); dfunit = (vdfunit == Qnil) ? -1 : NUM2INT(vdfunit); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbsetdfunit(tdb, dfunit) ? Qtrue : Qfalse; } static VALUE tdb_open(int argc, VALUE *argv, VALUE vself){ VALUE vtdb, vpath, vomode; TCTDB *tdb; int omode; rb_scan_args(argc, argv, "11", &vpath, &vomode); Check_Type(vpath, T_STRING); omode = (vomode == Qnil) ? TDBOREADER : NUM2INT(vomode); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbopen(tdb, RSTRING_PTR(vpath), omode) ? Qtrue : Qfalse; } static VALUE tdb_close(VALUE vself){ VALUE vtdb; TCTDB *tdb; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbclose(tdb) ? Qtrue : Qfalse; } static VALUE tdb_put(VALUE vself, VALUE vpkey, VALUE vcols){ VALUE vtdb, vrv; TCTDB *tdb; TCMAP *cols; vpkey = StringValueEx(vpkey); Check_Type(vcols, T_HASH); cols = vhashtomap(vcols); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); vrv = tctdbput(tdb, RSTRING_PTR(vpkey), RSTRING_LEN(vpkey), cols) ? Qtrue : Qfalse; tcmapdel(cols); return vrv; } static VALUE tdb_putkeep(VALUE vself, VALUE vpkey, VALUE vcols){ VALUE vtdb, vrv; TCTDB *tdb; TCMAP *cols; vpkey = StringValueEx(vpkey); Check_Type(vcols, T_HASH); cols = vhashtomap(vcols); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); vrv = tctdbputkeep(tdb, RSTRING_PTR(vpkey), RSTRING_LEN(vpkey), cols) ? Qtrue : Qfalse; tcmapdel(cols); return vrv; } static VALUE tdb_putcat(VALUE vself, VALUE vpkey, VALUE vcols){ VALUE vtdb, vrv; TCTDB *tdb; TCMAP *cols; vpkey = StringValueEx(vpkey); Check_Type(vcols, T_HASH); cols = vhashtomap(vcols); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); vrv = tctdbputcat(tdb, RSTRING_PTR(vpkey), RSTRING_LEN(vpkey), cols) ? Qtrue : Qfalse; tcmapdel(cols); return vrv; } static VALUE tdb_out(VALUE vself, VALUE vpkey){ VALUE vtdb; TCTDB *tdb; vpkey = StringValueEx(vpkey); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbout(tdb, RSTRING_PTR(vpkey), RSTRING_LEN(vpkey)) ? Qtrue : Qfalse; } static VALUE tdb_get(VALUE vself, VALUE vpkey){ VALUE vtdb, vcols; TCTDB *tdb; TCMAP *cols; vpkey = StringValueEx(vpkey); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); if(!(cols = tctdbget(tdb, RSTRING_PTR(vpkey), RSTRING_LEN(vpkey)))) return Qnil; vcols = maptovhash(cols); tcmapdel(cols); return vcols; } static VALUE tdb_vsiz(VALUE vself, VALUE vpkey){ VALUE vtdb; TCTDB *tdb; vpkey = StringValueEx(vpkey); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return INT2NUM(tctdbvsiz(tdb, RSTRING_PTR(vpkey), RSTRING_LEN(vpkey))); } static VALUE tdb_iterinit(VALUE vself){ VALUE vtdb; TCTDB *tdb; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbiterinit(tdb) ? Qtrue : Qfalse; } static VALUE tdb_iternext(VALUE vself){ VALUE vtdb, vval; TCTDB *tdb; char *vbuf; int vsiz; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); if(!(vbuf = tctdbiternext(tdb, &vsiz))) return Qnil; vval = rb_str_new(vbuf, vsiz); tcfree(vbuf); return vval; } static VALUE tdb_fwmkeys(int argc, VALUE *argv, VALUE vself){ VALUE vtdb, vprefix, vmax, vary; TCTDB *tdb; TCLIST *pkeys; int max; rb_scan_args(argc, argv, "11", &vprefix, &vmax); vprefix = StringValueEx(vprefix); max = (vmax == Qnil) ? -1 : NUM2INT(vmax); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); pkeys = tctdbfwmkeys(tdb, RSTRING_PTR(vprefix), RSTRING_LEN(vprefix), max); vary = listtovary(pkeys); tclistdel(pkeys); return vary; } static VALUE tdb_addint(VALUE vself, VALUE vpkey, VALUE vnum){ VALUE vtdb; TCTDB *tdb; int num; vpkey = StringValueEx(vpkey); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); num = tctdbaddint(tdb, RSTRING_PTR(vpkey), RSTRING_LEN(vpkey), NUM2INT(vnum)); return num == INT_MIN ? Qnil : INT2NUM(num); } static VALUE tdb_adddouble(VALUE vself, VALUE vpkey, VALUE vnum){ VALUE vtdb; TCTDB *tdb; double num; vpkey = StringValueEx(vpkey); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); num = tctdbadddouble(tdb, RSTRING_PTR(vpkey), RSTRING_LEN(vpkey), NUM2DBL(vnum)); return isnan(num) ? Qnil : rb_float_new(num); } static VALUE tdb_sync(VALUE vself){ VALUE vtdb; TCTDB *tdb; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbsync(tdb) ? Qtrue : Qfalse; } static VALUE tdb_optimize(int argc, VALUE *argv, VALUE vself){ VALUE vtdb, vbnum, vapow, vfpow, vopts; TCTDB *tdb; int apow, fpow, opts; int64_t bnum; rb_scan_args(argc, argv, "04", &vbnum, &vapow, &vfpow, &vopts); bnum = (vbnum == Qnil) ? -1 : NUM2LL(vbnum); apow = (vapow == Qnil) ? -1 : NUM2INT(vapow); fpow = (vfpow == Qnil) ? -1 : NUM2INT(vfpow); opts = (vopts == Qnil) ? UINT8_MAX : NUM2INT(vopts); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdboptimize(tdb, bnum, apow, fpow, opts) ? Qtrue : Qfalse; } static VALUE tdb_vanish(VALUE vself){ VALUE vtdb; TCTDB *tdb; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbvanish(tdb) ? Qtrue : Qfalse; } static VALUE tdb_copy(VALUE vself, VALUE vpath){ VALUE vtdb; TCTDB *tdb; Check_Type(vpath, T_STRING); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbcopy(tdb, RSTRING_PTR(vpath)) ? Qtrue : Qfalse; } static VALUE tdb_tranbegin(VALUE vself){ VALUE vtdb; TCTDB *tdb; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbtranbegin(tdb) ? Qtrue : Qfalse; } static VALUE tdb_trancommit(VALUE vself){ VALUE vtdb; TCTDB *tdb; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbtrancommit(tdb) ? Qtrue : Qfalse; } static VALUE tdb_tranabort(VALUE vself){ VALUE vtdb; TCTDB *tdb; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbtranabort(tdb) ? Qtrue : Qfalse; } static VALUE tdb_path(VALUE vself){ VALUE vtdb, vpath; TCTDB *tdb; const char *path; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); if(!(path = tctdbpath(tdb))) return Qnil; vpath = rb_str_new2(path); return vpath; } static VALUE tdb_rnum(VALUE vself){ VALUE vtdb; TCTDB *tdb; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return LL2NUM(tctdbrnum(tdb)); } static VALUE tdb_fsiz(VALUE vself){ VALUE vtdb; TCTDB *tdb; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return LL2NUM(tctdbfsiz(tdb)); } static VALUE tdb_setindex(VALUE vself, VALUE vname, VALUE vtype){ VALUE vtdb; TCTDB *tdb; Check_Type(vname, T_STRING); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbsetindex(tdb, RSTRING_PTR(vname), NUM2INT(vtype)) ? Qtrue : Qfalse; } static VALUE tdb_genuid(VALUE vself){ VALUE vtdb; TCTDB *tdb; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return LL2NUM(tctdbgenuid(tdb)); } static VALUE tdb_fetch(int argc, VALUE *argv, VALUE vself){ VALUE vtdb, vpkey, vdef, vcols; TCTDB *tdb; TCMAP *cols; rb_scan_args(argc, argv, "11", &vpkey, &vdef); vpkey = StringValueEx(vpkey); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); if((cols = tctdbget(tdb, RSTRING_PTR(vpkey), RSTRING_LEN(vpkey))) != NULL){ vcols = maptovhash(cols); tcmapdel(cols); } else { vcols = vdef; } return vcols; } static VALUE tdb_check(VALUE vself, VALUE vpkey){ VALUE vtdb; TCTDB *tdb; vpkey = StringValueEx(vpkey); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbvsiz(tdb, RSTRING_PTR(vpkey), RSTRING_LEN(vpkey)) >= 0 ? Qtrue : Qfalse; } static VALUE tdb_empty(VALUE vself){ VALUE vtdb; TCTDB *tdb; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); return tctdbrnum(tdb) < 1 ? Qtrue : Qfalse; } static VALUE tdb_each(VALUE vself){ VALUE vtdb, vrv; TCTDB *tdb; TCMAP *cols; char *kbuf; int ksiz; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); vrv = Qnil; tctdbiterinit(tdb); while((kbuf = tctdbiternext(tdb, &ksiz)) != NULL){ if((cols = tctdbget(tdb, kbuf, ksiz)) != NULL){ vrv = rb_yield_values(2, rb_str_new(kbuf, ksiz), maptovhash(cols)); tcmapdel(cols); } tcfree(kbuf); } return vrv; } static VALUE tdb_each_key(VALUE vself){ VALUE vtdb, vrv; TCTDB *tdb; char *kbuf; int ksiz; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); vrv = Qnil; tctdbiterinit(tdb); while((kbuf = tctdbiternext(tdb, &ksiz)) != NULL){ vrv = rb_yield(rb_str_new(kbuf, ksiz)); tcfree(kbuf); } return vrv; } static VALUE tdb_each_value(VALUE vself){ VALUE vtdb, vrv; TCTDB *tdb; TCMAP *cols; char *kbuf; int ksiz; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); vrv = Qnil; tctdbiterinit(tdb); while((kbuf = tctdbiternext(tdb, &ksiz)) != NULL){ if((cols = tctdbget(tdb, kbuf, ksiz)) != NULL){ vrv = rb_yield(maptovhash(cols)); tcmapdel(cols); } tcfree(kbuf); } return vrv; } static VALUE tdb_keys(VALUE vself){ VALUE vtdb, vary; TCTDB *tdb; char *kbuf; int ksiz; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); vary = rb_ary_new2(tctdbrnum(tdb)); tctdbiterinit(tdb); while((kbuf = tctdbiternext(tdb, &ksiz)) != NULL){ rb_ary_push(vary, rb_str_new(kbuf, ksiz)); tcfree(kbuf); } return vary; } static VALUE tdb_values(VALUE vself){ VALUE vtdb, vary; TCTDB *tdb; TCMAP *cols; char *kbuf; int ksiz; vtdb = rb_iv_get(vself, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); vary = rb_ary_new2(tctdbrnum(tdb)); tctdbiterinit(tdb); while((kbuf = tctdbiternext(tdb, &ksiz)) != NULL){ if((cols = tctdbget(tdb, kbuf, ksiz)) != NULL){ rb_ary_push(vary, maptovhash(cols)); tcmapdel(cols); } tcfree(kbuf); } return vary; } static void tdbqry_init(void){ cls_tdbqry = rb_define_class_under(mod_tokyocabinet, "TDBQRY", rb_cObject); cls_tdbqry_data = rb_define_class_under(mod_tokyocabinet, "TDBQRY_data", rb_cObject); rb_define_const(cls_tdbqry, "QCSTREQ", INT2NUM(TDBQCSTREQ)); rb_define_const(cls_tdbqry, "QCSTRINC", INT2NUM(TDBQCSTRINC)); rb_define_const(cls_tdbqry, "QCSTRBW", INT2NUM(TDBQCSTRBW)); rb_define_const(cls_tdbqry, "QCSTREW", INT2NUM(TDBQCSTREW)); rb_define_const(cls_tdbqry, "QCSTRAND", INT2NUM(TDBQCSTRAND)); rb_define_const(cls_tdbqry, "QCSTROR", INT2NUM(TDBQCSTROR)); rb_define_const(cls_tdbqry, "QCSTROREQ", INT2NUM(TDBQCSTROREQ)); rb_define_const(cls_tdbqry, "QCSTRRX", INT2NUM(TDBQCSTRRX)); rb_define_const(cls_tdbqry, "QCNUMEQ", INT2NUM(TDBQCNUMEQ)); rb_define_const(cls_tdbqry, "QCNUMGT", INT2NUM(TDBQCNUMGT)); rb_define_const(cls_tdbqry, "QCNUMGE", INT2NUM(TDBQCNUMGE)); rb_define_const(cls_tdbqry, "QCNUMLT", INT2NUM(TDBQCNUMLT)); rb_define_const(cls_tdbqry, "QCNUMLE", INT2NUM(TDBQCNUMLE)); rb_define_const(cls_tdbqry, "QCNUMBT", INT2NUM(TDBQCNUMBT)); rb_define_const(cls_tdbqry, "QCNUMOREQ", INT2NUM(TDBQCNUMOREQ)); rb_define_const(cls_tdbqry, "QCFTSPH", INT2NUM(TDBQCFTSPH)); rb_define_const(cls_tdbqry, "QCFTSAND", INT2NUM(TDBQCFTSAND)); rb_define_const(cls_tdbqry, "QCFTSOR", INT2NUM(TDBQCFTSOR)); rb_define_const(cls_tdbqry, "QCFTSEX", INT2NUM(TDBQCFTSEX)); rb_define_const(cls_tdbqry, "QCNEGATE", INT2NUM(TDBQCNEGATE)); rb_define_const(cls_tdbqry, "QCNOIDX", INT2NUM(TDBQCNOIDX)); rb_define_const(cls_tdbqry, "QOSTRASC", INT2NUM(TDBQOSTRASC)); rb_define_const(cls_tdbqry, "QOSTRDESC", INT2NUM(TDBQOSTRDESC)); rb_define_const(cls_tdbqry, "QONUMASC", INT2NUM(TDBQONUMASC)); rb_define_const(cls_tdbqry, "QONUMDESC", INT2NUM(TDBQONUMDESC)); rb_define_const(cls_tdbqry, "QPPUT", INT2NUM(TDBQPPUT)); rb_define_const(cls_tdbqry, "QPOUT", INT2NUM(TDBQPOUT)); rb_define_const(cls_tdbqry, "QPSTOP", INT2NUM(TDBQPSTOP)); rb_define_const(cls_tdbqry, "MSUNION", INT2NUM(TDBMSUNION)); rb_define_const(cls_tdbqry, "MSISECT", INT2NUM(TDBMSISECT)); rb_define_const(cls_tdbqry, "MSDIFF", INT2NUM(TDBMSDIFF)); rb_define_const(cls_tdbqry, "KWMUTAB", INT2NUM(TCKWMUTAB)); rb_define_const(cls_tdbqry, "KWMUCTRL", INT2NUM(TCKWMUCTRL)); rb_define_const(cls_tdbqry, "KWMUBRCT", INT2NUM(TCKWMUBRCT)); rb_define_const(cls_tdbqry, "KWNOOVER", INT2NUM(TCKWNOOVER)); rb_define_const(cls_tdbqry, "KWPULEAD", INT2NUM(TCKWPULEAD)); rb_define_private_method(cls_tdbqry, "initialize", tdbqry_initialize, 1); rb_define_method(cls_tdbqry, "addcond", tdbqry_addcond, 3); rb_define_method(cls_tdbqry, "setorder", tdbqry_setorder, -1); rb_define_method(cls_tdbqry, "setlimit", tdbqry_setlimit, -1); rb_define_method(cls_tdbqry, "setmax", tdbqry_setlimit, -1); rb_define_method(cls_tdbqry, "search", tdbqry_search, 0); rb_define_method(cls_tdbqry, "searchout", tdbqry_searchout, 0); rb_define_method(cls_tdbqry, "proc", tdbqry_proc, 0); rb_define_method(cls_tdbqry, "hint", tdbqry_hint, 0); rb_define_method(cls_tdbqry, "metasearch", tdbqry_metasearch, -1); rb_define_method(cls_tdbqry, "kwic", tdbqry_kwic, -1); } static int tdbqry_procrec(const void *pkbuf, int pksiz, TCMAP *cols, void *opq){ VALUE vpkey, vcols, vrv, vkeys, vkey, vval; int i, rv, num; vpkey = rb_str_new(pkbuf, pksiz); vcols = maptovhash(cols); vrv = rb_yield_values(2, vpkey, vcols); rv = (vrv == Qnil) ? 0 : NUM2INT(vrv); if(rv & TDBQPPUT){ tcmapclear(cols); vkeys = rb_funcall(vcols, rb_intern("keys"), 0); num = RARRAY_LEN(vkeys); for(i = 0; i < num; i++){ vkey = rb_ary_entry(vkeys, i); vval = rb_hash_aref(vcols, vkey); vkey = StringValueEx(vkey); vval = StringValueEx(vval); tcmapput(cols, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)); } } return rv; } static VALUE tdbqry_initialize(VALUE vself, VALUE vtdb){ VALUE vqry; TCTDB *tdb; TDBQRY *qry; Check_Type(vtdb, T_OBJECT); vtdb = rb_iv_get(vtdb, TDBVNDATA); Data_Get_Struct(vtdb, TCTDB, tdb); qry = tctdbqrynew(tdb); vqry = Data_Wrap_Struct(cls_tdbqry_data, 0, tctdbqrydel, qry); rb_iv_set(vself, TDBQRYVNDATA, vqry); rb_iv_set(vself, TDBVNDATA, vtdb); return Qnil; } static VALUE tdbqry_addcond(VALUE vself, VALUE vname, VALUE vop, VALUE vexpr){ VALUE vqry; TDBQRY *qry; vname = StringValueEx(vname); vexpr = StringValueEx(vexpr); vqry = rb_iv_get(vself, TDBQRYVNDATA); Data_Get_Struct(vqry, TDBQRY, qry); tctdbqryaddcond(qry, RSTRING_PTR(vname), NUM2INT(vop), RSTRING_PTR(vexpr)); return Qnil; } static VALUE tdbqry_setorder(int argc, VALUE *argv, VALUE vself){ VALUE vqry, vname, vtype; TDBQRY *qry; int type; rb_scan_args(argc, argv, "11", &vname, &vtype); vname = StringValueEx(vname); type = (vtype == Qnil) ? TDBQOSTRASC : NUM2INT(vtype); vqry = rb_iv_get(vself, TDBQRYVNDATA); Data_Get_Struct(vqry, TDBQRY, qry); tctdbqrysetorder(qry, RSTRING_PTR(vname), type); return Qnil; } static VALUE tdbqry_setlimit(int argc, VALUE *argv, VALUE vself){ VALUE vqry, vmax, vskip; TDBQRY *qry; int max, skip; rb_scan_args(argc, argv, "02", &vmax, &vskip); max = (vmax == Qnil) ? -1 : NUM2INT(vmax); skip = (vskip == Qnil) ? -1 : NUM2INT(vskip); vqry = rb_iv_get(vself, TDBQRYVNDATA); Data_Get_Struct(vqry, TDBQRY, qry); tctdbqrysetlimit(qry, max, skip); return Qnil; } static VALUE tdbqry_search(VALUE vself){ VALUE vqry, vary; TDBQRY *qry; TCLIST *res; vqry = rb_iv_get(vself, TDBQRYVNDATA); Data_Get_Struct(vqry, TDBQRY, qry); res = tctdbqrysearch(qry); vary = listtovary(res); tclistdel(res); return vary; } static VALUE tdbqry_searchout(VALUE vself){ VALUE vqry; TDBQRY *qry; vqry = rb_iv_get(vself, TDBQRYVNDATA); Data_Get_Struct(vqry, TDBQRY, qry); return tctdbqrysearchout(qry) ? Qtrue : Qfalse; } static VALUE tdbqry_proc(VALUE vself, VALUE vproc){ VALUE vqry; TDBQRY *qry; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vqry = rb_iv_get(vself, TDBQRYVNDATA); Data_Get_Struct(vqry, TDBQRY, qry); return tctdbqryproc(qry, (TDBQRYPROC)tdbqry_procrec, NULL) ? Qtrue : Qfalse; } static VALUE tdbqry_hint(VALUE vself){ VALUE vqry; TDBQRY *qry; vqry = rb_iv_get(vself, TDBQRYVNDATA); Data_Get_Struct(vqry, TDBQRY, qry); return rb_str_new2(tctdbqryhint(qry)); } static VALUE tdbqry_metasearch(int argc, VALUE *argv, VALUE vself){ VALUE vqry, vothers, vtype, voqry, vary; TDBQRY *qry, **qrys; TCLIST *res; int i, type, num, qnum; rb_scan_args(argc, argv, "11", &vothers, &vtype); Check_Type(vothers, T_ARRAY); type = (vtype == Qnil) ? TDBMSUNION : NUM2INT(vtype); vqry = rb_iv_get(vself, TDBQRYVNDATA); Data_Get_Struct(vqry, TDBQRY, qry); num = RARRAY_LEN(vothers); qrys = tcmalloc(sizeof(*qrys) * (num + 1)); qnum = 0; qrys[qnum++] = qry; for(i = 0; i < num; i++){ voqry = rb_ary_entry(vothers, i); if(rb_obj_is_instance_of(voqry, cls_tdbqry) == Qtrue){ voqry = rb_iv_get(voqry, TDBQRYVNDATA); Data_Get_Struct(voqry, TDBQRY, qrys[qnum++]); } } res = tctdbmetasearch(qrys, qnum, type); vary = listtovary(res); tcfree(qrys); tclistdel(res); return vary; } static VALUE tdbqry_kwic(int argc, VALUE *argv, VALUE vself){ VALUE vqry, vcols, vname, vwidth, vopts, vval, vary; TDBQRY *qry; TCMAP *cols; const char *name; int width, opts; rb_scan_args(argc, argv, "13", &vcols, &vname, &vwidth, &vopts); Check_Type(vcols, T_HASH); width = (vwidth == Qnil) ? -1 : NUM2INT(vwidth); opts = (vopts == Qnil) ? 0 : NUM2INT(vopts); if(vname == Qnil){ cols = vhashtomap(vcols); name = NULL; } else { vname = StringValueEx(vname); cols = tcmapnew2(1); vval = rb_hash_aref(vcols, vname); if(vval != Qnil) tcmapput(cols, RSTRING_PTR(vname), RSTRING_LEN(vname), RSTRING_PTR(vval), RSTRING_LEN(vval)); name = RSTRING_PTR(vname); } if(width < 0){ width = 1 << 30; opts |= TCKWNOOVER | TCKWPULEAD; } vqry = rb_iv_get(vself, TDBQRYVNDATA); Data_Get_Struct(vqry, TDBQRY, qry); TCLIST *texts = tctdbqrykwic(qry, cols, name, width, opts); vary = listtovary(texts); tclistdel(texts); tcmapdel(cols); return vary; } static void adb_init(void){ cls_adb = rb_define_class_under(mod_tokyocabinet, "ADB", rb_cObject); cls_adb_data = rb_define_class_under(mod_tokyocabinet, "ADB_data", rb_cObject); rb_define_private_method(cls_adb, "initialize", adb_initialize, 0); rb_define_method(cls_adb, "open", adb_open, 1); rb_define_method(cls_adb, "close", adb_close, 0); rb_define_method(cls_adb, "put", adb_put, 2); rb_define_method(cls_adb, "putkeep", adb_putkeep, 2); rb_define_method(cls_adb, "putcat", adb_putcat, 2); rb_define_method(cls_adb, "out", adb_out, 1); rb_define_method(cls_adb, "get", adb_get, 1); rb_define_method(cls_adb, "vsiz", adb_vsiz, 1); rb_define_method(cls_adb, "iterinit", adb_iterinit, 0); rb_define_method(cls_adb, "iternext", adb_iternext, 0); rb_define_method(cls_adb, "fwmkeys", adb_fwmkeys, -1); rb_define_method(cls_adb, "addint", adb_addint, 2); rb_define_method(cls_adb, "adddouble", adb_adddouble, 2); rb_define_method(cls_adb, "sync", adb_sync, 0); rb_define_method(cls_adb, "optimize", adb_optimize, -1); rb_define_method(cls_adb, "vanish", adb_vanish, 0); rb_define_method(cls_adb, "copy", adb_copy, 1); rb_define_method(cls_adb, "tranbegin", adb_tranbegin, 0); rb_define_method(cls_adb, "trancommit", adb_trancommit, 0); rb_define_method(cls_adb, "tranabort", adb_tranabort, 0); rb_define_method(cls_adb, "path", adb_path, 0); rb_define_method(cls_adb, "rnum", adb_rnum, 0); rb_define_method(cls_adb, "size", adb_size, 0); rb_define_method(cls_adb, "misc", adb_misc, -1); rb_define_method(cls_adb, "[]", adb_get, 1); rb_define_method(cls_adb, "[]=", adb_put, 2); rb_define_method(cls_adb, "store", adb_put, 2); rb_define_method(cls_adb, "delete", adb_out, 1); rb_define_method(cls_adb, "fetch", adb_fetch, -1); rb_define_method(cls_adb, "has_key?", adb_check, 1); rb_define_method(cls_adb, "key?", adb_check, 1); rb_define_method(cls_adb, "include?", adb_check, 1); rb_define_method(cls_adb, "member?", adb_check, 1); rb_define_method(cls_adb, "has_value?", adb_check_value, 1); rb_define_method(cls_adb, "value?", adb_check_value, 1); rb_define_method(cls_adb, "key", adb_get_reverse, 1); rb_define_method(cls_adb, "clear", adb_vanish, 0); rb_define_method(cls_adb, "length", adb_rnum, 0); rb_define_method(cls_adb, "empty?", adb_empty, 0); rb_define_method(cls_adb, "each", adb_each, 0); rb_define_method(cls_adb, "each_pair", adb_each, 0); rb_define_method(cls_adb, "each_key", adb_each_key, 0); rb_define_method(cls_adb, "each_value", adb_each_value, 0); rb_define_method(cls_adb, "keys", adb_keys, 0); rb_define_method(cls_adb, "values", adb_values, 0); } static VALUE adb_initialize(VALUE vself){ VALUE vadb; TCADB *adb; adb = tcadbnew(); vadb = Data_Wrap_Struct(cls_adb_data, 0, tcadbdel, adb); rb_iv_set(vself, ADBVNDATA, vadb); return Qnil; } static VALUE adb_open(VALUE vself, VALUE vname){ VALUE vadb; TCADB *adb; Check_Type(vname, T_STRING); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadbopen(adb, RSTRING_PTR(vname)) ? Qtrue : Qfalse; } static VALUE adb_close(VALUE vself){ VALUE vadb; TCADB *adb; vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadbclose(adb) ? Qtrue : Qfalse; } static VALUE adb_put(VALUE vself, VALUE vkey, VALUE vval){ VALUE vadb; TCADB *adb; vkey = StringValueEx(vkey); vval = StringValueEx(vval); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadbput(adb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)) ? Qtrue : Qfalse; } static VALUE adb_putkeep(VALUE vself, VALUE vkey, VALUE vval){ VALUE vadb; TCADB *adb; vkey = StringValueEx(vkey); vval = StringValueEx(vval); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadbputkeep(adb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)) ? Qtrue : Qfalse; } static VALUE adb_putcat(VALUE vself, VALUE vkey, VALUE vval){ VALUE vadb; TCADB *adb; vkey = StringValueEx(vkey); vval = StringValueEx(vval); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadbputcat(adb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), RSTRING_PTR(vval), RSTRING_LEN(vval)) ? Qtrue : Qfalse; } static VALUE adb_out(VALUE vself, VALUE vkey){ VALUE vadb; TCADB *adb; vkey = StringValueEx(vkey); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadbout(adb, RSTRING_PTR(vkey), RSTRING_LEN(vkey)) ? Qtrue : Qfalse; } static VALUE adb_get(VALUE vself, VALUE vkey){ VALUE vadb, vval; TCADB *adb; char *vbuf; int vsiz; vkey = StringValueEx(vkey); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); if(!(vbuf = tcadbget(adb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), &vsiz))) return Qnil; vval = rb_str_new(vbuf, vsiz); tcfree(vbuf); return vval; } static VALUE adb_vsiz(VALUE vself, VALUE vkey){ VALUE vadb; TCADB *adb; vkey = StringValueEx(vkey); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return INT2NUM(tcadbvsiz(adb, RSTRING_PTR(vkey), RSTRING_LEN(vkey))); } static VALUE adb_iterinit(VALUE vself){ VALUE vadb; TCADB *adb; vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadbiterinit(adb) ? Qtrue : Qfalse; } static VALUE adb_iternext(VALUE vself){ VALUE vadb, vval; TCADB *adb; char *vbuf; int vsiz; vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); if(!(vbuf = tcadbiternext(adb, &vsiz))) return Qnil; vval = rb_str_new(vbuf, vsiz); tcfree(vbuf); return vval; } static VALUE adb_fwmkeys(int argc, VALUE *argv, VALUE vself){ VALUE vadb, vprefix, vmax, vary; TCADB *adb; TCLIST *keys; int max; rb_scan_args(argc, argv, "11", &vprefix, &vmax); vprefix = StringValueEx(vprefix); max = (vmax == Qnil) ? -1 : NUM2INT(vmax); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); keys = tcadbfwmkeys(adb, RSTRING_PTR(vprefix), RSTRING_LEN(vprefix), max); vary = listtovary(keys); tclistdel(keys); return vary; } static VALUE adb_addint(VALUE vself, VALUE vkey, VALUE vnum){ VALUE vadb; TCADB *adb; int num; vkey = StringValueEx(vkey); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); num = tcadbaddint(adb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), NUM2INT(vnum)); return num == INT_MIN ? Qnil : INT2NUM(num); } static VALUE adb_adddouble(VALUE vself, VALUE vkey, VALUE vnum){ VALUE vadb; TCADB *adb; double num; vkey = StringValueEx(vkey); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); num = tcadbadddouble(adb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), NUM2DBL(vnum)); return isnan(num) ? Qnil : rb_float_new(num); } static VALUE adb_sync(VALUE vself){ VALUE vadb; TCADB *adb; vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadbsync(adb) ? Qtrue : Qfalse; } static VALUE adb_optimize(int argc, VALUE *argv, VALUE vself){ VALUE vadb, vparams; TCADB *adb; const char *params; rb_scan_args(argc, argv, "01", &vparams); if(vparams == Qnil){ params = NULL; } else { Check_Type(vparams, T_STRING); params = RSTRING_PTR(vparams); } vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadboptimize(adb, params) ? Qtrue : Qfalse; } static VALUE adb_vanish(VALUE vself){ VALUE vadb; TCADB *adb; vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadbvanish(adb) ? Qtrue : Qfalse; } static VALUE adb_copy(VALUE vself, VALUE vpath){ VALUE vadb; TCADB *adb; Check_Type(vpath, T_STRING); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadbcopy(adb, RSTRING_PTR(vpath)) ? Qtrue : Qfalse; } static VALUE adb_tranbegin(VALUE vself){ VALUE vadb; TCADB *adb; vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadbtranbegin(adb) ? Qtrue : Qfalse; } static VALUE adb_trancommit(VALUE vself){ VALUE vadb; TCADB *adb; vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadbtrancommit(adb) ? Qtrue : Qfalse; } static VALUE adb_tranabort(VALUE vself){ VALUE vadb; TCADB *adb; vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadbtranabort(adb) ? Qtrue : Qfalse; } static VALUE adb_path(VALUE vself){ VALUE vadb; TCADB *adb; const char *path; vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); if(!(path = tcadbpath(adb))) return Qnil; return rb_str_new2(path); } static VALUE adb_rnum(VALUE vself){ VALUE vadb; TCADB *adb; vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return LL2NUM(tcadbrnum(adb)); } static VALUE adb_size(VALUE vself){ VALUE vadb; TCADB *adb; vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return LL2NUM(tcadbsize(adb)); } static VALUE adb_misc(int argc, VALUE *argv, VALUE vself){ VALUE vadb, vname, vargs, vrv; TCADB *adb; TCLIST *targs, *res; rb_scan_args(argc, argv, "11", &vname, &vargs); vname = StringValueEx(vname); if(vargs == Qnil){ targs = tclistnew2(1); } else { Check_Type(vargs, T_ARRAY); targs = varytolist(vargs); } vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); res = tcadbmisc(adb, RSTRING_PTR(vname), targs); if(res){ vrv = listtovary(res); tclistdel(res); } else { vrv = Qnil; } tclistdel(targs); return vrv; } static VALUE adb_fetch(int argc, VALUE *argv, VALUE vself){ VALUE vadb, vkey, vdef, vval; TCADB *adb; char *vbuf; int vsiz; rb_scan_args(argc, argv, "11", &vkey, &vdef); vkey = StringValueEx(vkey); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); if((vbuf = tcadbget(adb, RSTRING_PTR(vkey), RSTRING_LEN(vkey), &vsiz)) != NULL){ vval = rb_str_new(vbuf, vsiz); tcfree(vbuf); } else { vval = vdef; } return vval; } static VALUE adb_check(VALUE vself, VALUE vkey){ VALUE vadb; TCADB *adb; vkey = StringValueEx(vkey); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadbvsiz(adb, RSTRING_PTR(vkey), RSTRING_LEN(vkey)) >= 0 ? Qtrue : Qfalse; } static VALUE adb_check_value(VALUE vself, VALUE vval){ VALUE vadb; TCADB *adb; char *tkbuf, *tvbuf; bool hit; int tksiz, tvsiz; vval = StringValueEx(vval); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); hit = false; tcadbiterinit(adb); while((tkbuf = tcadbiternext(adb, &tksiz)) != NULL){ tvbuf = tcadbget(adb, tkbuf, tksiz, &tvsiz); if(tvbuf && tvsiz == RSTRING_LEN(vval) && memcmp(tvbuf, RSTRING_PTR(vval), RSTRING_LEN(vval)) == 0){ tcfree(tvbuf); tcfree(tkbuf); hit = true; break; } tcfree(tvbuf); tcfree(tkbuf); } return hit ? Qtrue : Qfalse; } static VALUE adb_get_reverse(VALUE vself, VALUE vval){ VALUE vadb, vrv; TCADB *adb; char *tkbuf, *tvbuf; int tksiz, tvsiz; vval = StringValueEx(vval); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); vrv = Qnil; tcadbiterinit(adb); while((tkbuf = tcadbiternext(adb, &tksiz)) != NULL){ tvbuf = tcadbget(adb, tkbuf, tksiz, &tvsiz); if(tvbuf && tvsiz == RSTRING_LEN(vval) && memcmp(tvbuf, RSTRING_PTR(vval), RSTRING_LEN(vval)) == 0){ vrv = rb_str_new(tkbuf, tksiz); tcfree(tvbuf); tcfree(tkbuf); break; } tcfree(tvbuf); tcfree(tkbuf); } return vrv; } static VALUE adb_empty(VALUE vself){ VALUE vadb; TCADB *adb; vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); return tcadbrnum(adb) < 1 ? Qtrue : Qfalse; } static VALUE adb_each(VALUE vself){ VALUE vadb, vrv; TCADB *adb; char *tkbuf, *tvbuf; int tksiz, tvsiz; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); vrv = Qnil; tcadbiterinit(adb); while((tkbuf = tcadbiternext(adb, &tksiz)) != NULL){ tvbuf = tcadbget(adb, tkbuf, tksiz, &tvsiz); if(tvbuf){ vrv = rb_yield_values(2, rb_str_new(tkbuf, tksiz), rb_str_new(tvbuf, tvsiz)); tcfree(tvbuf); } tcfree(tkbuf); } return vrv; } static VALUE adb_each_key(VALUE vself){ VALUE vadb, vrv; TCADB *adb; char *tkbuf; int tksiz; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); vrv = Qnil; tcadbiterinit(adb); while((tkbuf = tcadbiternext(adb, &tksiz)) != NULL){ vrv = rb_yield(rb_str_new(tkbuf, tksiz)); tcfree(tkbuf); } return vrv; } static VALUE adb_each_value(VALUE vself){ VALUE vadb, vrv; TCADB *adb; char *tkbuf, *tvbuf; int tksiz, tvsiz; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); vrv = Qnil; tcadbiterinit(adb); while((tkbuf = tcadbiternext(adb, &tksiz)) != NULL){ tvbuf = tcadbget(adb, tkbuf, tksiz, &tvsiz); if(tvbuf){ vrv = rb_yield(rb_str_new(tvbuf, tvsiz)); tcfree(tvbuf); } tcfree(tkbuf); } return vrv; } static VALUE adb_keys(VALUE vself){ VALUE vadb, vary; TCADB *adb; char *tkbuf; int tksiz; vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); vary = rb_ary_new2(tcadbrnum(adb)); tcadbiterinit(adb); while((tkbuf = tcadbiternext(adb, &tksiz)) != NULL){ rb_ary_push(vary, rb_str_new(tkbuf, tksiz)); tcfree(tkbuf); } return vary; } static VALUE adb_values(VALUE vself){ VALUE vadb, vary; TCADB *adb; char *tkbuf, *tvbuf; int tksiz, tvsiz; vadb = rb_iv_get(vself, ADBVNDATA); Data_Get_Struct(vadb, TCADB, adb); vary = rb_ary_new2(tcadbrnum(adb)); tcadbiterinit(adb); while((tkbuf = tcadbiternext(adb, &tksiz)) != NULL){ tvbuf = tcadbget(adb, tkbuf, tksiz, &tvsiz); if(tvbuf){ rb_ary_push(vary, rb_str_new(tvbuf, tvsiz)); tcfree(tvbuf); } tcfree(tkbuf); } return vary; } /* END OF FILE */ tokyocabinet-ruby-1.31/memsize.rb0000644000175000017500000000122411547412351015264 0ustar spkspk#! /usr/bin/ruby require 'tokyocabinet' include TokyoCabinet def memoryusage() status = `cat /proc/#{$$}/status` lines = status.split("\n") lines.each do |line| if line =~ /^VmRSS:/ line.gsub!(/.*:\s*(\d+).*/, '\1') return line.to_i / 1024.0 end end return -1; end rnum = 1000000; if ARGV.length > 0 rnum = ARGV[0].to_i end if ARGV.length > 1 hash = ADB::new hash.open(ARGV[1]) || raise("open failed") else hash = Hash.new end stime = Time.now (0...rnum).each do |i| buf = sprintf("%08d", i) hash[buf] = buf end etime = Time.now printf("Time: %.3f sec.\n", etime - stime) printf("Usage: %.3f MB\n", memoryusage) tokyocabinet-ruby-1.31/extconf.rb0000644000175000017500000000164411547412351015267 0ustar spkspkrequire "mkmf" dir_config('tokyocabinet') File::unlink("Makefile") if (File::exist?("Makefile")) home = ENV["HOME"] ENV["PATH"] = ENV["PATH"] + ":/usr/local/bin:$home/bin:." tccflags = `tcucodec conf -i 2>/dev/null`.chomp tcldflags = `tcucodec conf -l 2>/dev/null`.chomp tcldflags = tcldflags.gsub(/-l[\S]+/, "").strip tclibs = `tcucodec conf -l 2>/dev/null`.chomp tclibs = tclibs.gsub(/-L[\S]+/, "").strip tccflags = "-I/usr/local/include" if(tccflags.length < 1) tcldflags = "-L/usr/local/lib" if(tcldflags.length < 1) tclibs = "-ltokyocabinet -lz -lbz2 -lpthread -lm -lc" if(tclibs.length < 1) $CFLAGS = "-I. #{tccflags} -Wall #{$CFLAGS} -O2" $LDFLAGS = "#{$LDFLAGS} -L. #{tcldflags}" $libs = "#{$libs} #{tclibs}" printf("setting variables ...\n") printf(" \$CFLAGS = %s\n", $CFLAGS) printf(" \$LDFLAGS = %s\n", $LDFLAGS) printf(" \$libs = %s\n", $libs) if have_header('tcutil.h') create_makefile('tokyocabinet') end tokyocabinet-ruby-1.31/overview.rd0000644000175000017500000002134111547412351015465 0ustar spkspk= Ruby Binding of Tokyo Cabinet Tokyo Cabinet: a modern implementation of DBM == INTRODUCTION Tokyo Cabinet is a library of routines for managing a database. The database is a simple data file containing records, each is a pair of a key and a value. Every key and value is serial bytes with variable length. Both binary data and character string can be used as a key and a value. There is neither concept of data tables nor data types. Records are organized in hash table, B+ tree, or fixed-length array. As for database of hash table, each key must be unique within a database, so it is impossible to store two or more records with a key overlaps. The following access methods are provided to the database: storing a record with a key and a value, deleting a record by a key, retrieving a record by a key. Moreover, traversal access to every key are provided, although the order is arbitrary. These access methods are similar to ones of DBM (or its followers: NDBM and GDBM) library defined in the UNIX standard. Tokyo Cabinet is an alternative for DBM because of its higher performance. As for database of B+ tree, records whose keys are duplicated can be stored. Access methods of storing, deleting, and retrieving are provided as with the database of hash table. Records are stored in order by a comparison function assigned by a user. It is possible to access each record with the cursor in ascending or descending order. According to this mechanism, forward matching search for strings and range search for integers are realized. As for database of fixed-length array, records are stored with unique natural numbers. It is impossible to store two or more records with a key overlaps. Moreover, the length of each record is limited by the specified length. Provided operations are the same as ones of hash database. Table database is also provided as a variant of hash database. Each record is identified by the primary key and has a set of named columns. Although there is no concept of data schema, it is possible to search for records with complex conditions efficiently by using indices of arbitrary columns. === Setting Install the latest version of Tokyo Cabinet beforehand and get the package of the Ruby binding of Tokyo Cabinet. Enter the directory of the extracted package then perform installation. ruby extconf.rb make su make install The package `tokyocabinet' should be loaded in each source file of application programs. require 'tokyocabinet' All symbols of Tokyo Cabinet are defined in the module `TokyoCabinet'. You can access them without any prefix by including the module. include TokyoCabinet = EXAMPLE The following code is an example to use a hash database. require 'tokyocabinet' include TokyoCabinet # create the object hdb = HDB::new # open the database if !hdb.open("casket.tch", HDB::OWRITER | HDB::OCREAT) ecode = hdb.ecode STDERR.printf("open error: %s\n", hdb.errmsg(ecode)) end # store records if !hdb.put("foo", "hop") || !hdb.put("bar", "step") || !hdb.put("baz", "jump") ecode = hdb.ecode STDERR.printf("put error: %s\n", hdb.errmsg(ecode)) end # retrieve records value = hdb.get("foo") if value printf("%s\n", value) else ecode = hdb.ecode STDERR.printf("get error: %s\n", hdb.errmsg(ecode)) end # traverse records hdb.iterinit while key = hdb.iternext value = hdb.get(key) if value printf("%s:%s\n", key, value) end end # hash-like usage hdb["quux"] = "touchdown" printf("%s\n", hdb["quux"]) hdb.each do |key, value| printf("%s:%s\n", key, value) end # close the database if !hdb.close ecode = hdb.ecode STDERR.printf("close error: %s\n", hdb.errmsg(ecode)) end The following code is an example to use a B+ tree database. require 'tokyocabinet' include TokyoCabinet # create the object bdb = BDB::new # open the database if !bdb.open("casket.tcb", BDB::OWRITER | BDB::OCREAT) ecode = bdb.ecode STDERR.printf("open error: %s\n", bdb.errmsg(ecode)) end # store records if !bdb.put("foo", "hop") || !bdb.put("bar", "step") || !bdb.put("baz", "jump") ecode = bdb.ecode STDERR.printf("put error: %s\n", bdb.errmsg(ecode)) end # retrieve records value = bdb.get("foo") if value printf("%s\n", value) else ecode = bdb.ecode STDERR.printf("get error: %s\n", bdb.errmsg(ecode)) end # traverse records cur = BDBCUR::new(bdb) cur.first while key = cur.key value = cur.val if value printf("%s:%s\n", key, value) end cur.next end # hash-like usage bdb["quux"] = "touchdown" printf("%s\n", bdb["quux"]) bdb.each do |key, value| printf("%s:%s\n", key, value) end # close the database if !bdb.close ecode = bdb.ecode STDERR.printf("close error: %s\n", bdb.errmsg(ecode)) end The following code is an example to use a fixed-length database. require 'tokyocabinet' include TokyoCabinet # create the object fdb = FDB::new # open the database if !fdb.open("casket.tcf", FDB::OWRITER | FDB::OCREAT) ecode = fdb.ecode STDERR.printf("open error: %s\n", fdb.errmsg(ecode)) end # store records if !fdb.put(1, "one") || !fdb.put(12, "twelve") || !fdb.put(144, "one forty four") ecode = fdb.ecode STDERR.printf("put error: %s\n", fdb.errmsg(ecode)) end # retrieve records value = fdb.get(1) if value printf("%s\n", value) else ecode = fdb.ecode STDERR.printf("get error: %s\n", fdb.errmsg(ecode)) end # traverse records fdb.iterinit while key = fdb.iternext value = fdb.get(key) if value printf("%s:%s\n", key, value) end end # hash-like usage fdb[1728] = "seventeen twenty eight" printf("%s\n", fdb[1728]) fdb.each do |key, value| printf("%s:%s\n", key, value) end # close the database if !fdb.close ecode = fdb.ecode STDERR.printf("close error: %s\n", fdb.errmsg(ecode)) end The following code is an example to use a table database. require 'tokyocabinet' include TokyoCabinet # create the object tdb = TDB::new # open the database if !tdb.open("casket.tct", TDB::OWRITER | TDB::OCREAT) ecode = tdb.ecode STDERR.printf("open error: %s\n", tdb.errmsg(ecode)) end # store a record pkey = tdb.genuid cols = { "name" => "mikio", "age" => "30", "lang" => "ja,en,c" } if !tdb.put(pkey, cols) ecode = tdb.ecode STDERR.printf("get error: %s\n", tdb.errmsg(ecode)) end # store another record cols = { "name" => "falcon", "age" => "31", "lang" => "ja", "skill" => "cook,blog" } if !tdb.put("x12345", cols) ecode = tdb.ecode STDERR.printf("get error: %s\n", tdb.errmsg(ecode)) end # search for records qry = TDBQRY::new(tdb) qry.addcond("age", TDBQRY::QCNUMGE, "20") qry.addcond("lang", TDBQRY::QCSTROR, "ja,en") qry.setorder("name", TDBQRY::QOSTRASC) qry.setlimit(10) res = qry.search res.each do |rkey| rcols = tdb.get(rkey) printf("name:%s\n", rcols["name"]) end # hash-like usage tdb["joker"] = { "name" => "ozma", "lang" => "en", "skill" => "song,dance" } printf("%s\n", tdb["joker"]["name"]) tdb.each do |key, value| printf("%s:%s\n", key, value["name"]) end # close the database if !tdb.close ecode = tdb.ecode STDERR.printf("close error: %s\n", tdb.errmsg(ecode)) end The following code is an example to use an abstract database. require 'tokyocabinet' include TokyoCabinet # create the object adb = ADB::new # open the database if !adb.open("casket.tch") STDERR.printf("open error\n") end # store records if !adb.put("foo", "hop") || !adb.put("bar", "step") || !adb.put("baz", "jump") STDERR.printf("put error\n") end # retrieve records value = adb.get("foo") if value printf("%s\n", value) else STDERR.printf("get error\n") end # traverse records adb.iterinit while key = adb.iternext value = adb.get(key) if value printf("%s:%s\n", key, value) end end # hash-like usage adb["quux"] = "touchdown" printf("%s\n", adb["quux"]) adb.each do |key, value| printf("%s:%s\n", key, value) end # close the database if !adb.close STDERR.printf("close error\n") end == LICENSE Copyright (C) 2006-2010 FAL Labs All rights reserved. Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Tokyo Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. tokyocabinet-ruby-1.31/example/0000755000175000017500000000000011547412351014722 5ustar spkspktokyocabinet-ruby-1.31/example/tcfdbex.rb0000644000175000017500000000171311547412351016670 0ustar spkspkrequire 'tokyocabinet' include TokyoCabinet # create the object fdb = FDB::new # open the database if !fdb.open("casket.tcf", FDB::OWRITER | FDB::OCREAT) ecode = fdb.ecode STDERR.printf("open error: %s\n", fdb.errmsg(ecode)) end # store records if !fdb.put(1, "one") || !fdb.put(12, "twelve") || !fdb.put(144, "one forty four") ecode = fdb.ecode STDERR.printf("put error: %s\n", fdb.errmsg(ecode)) end # retrieve records value = fdb.get(1) if value printf("%s\n", value) else ecode = fdb.ecode STDERR.printf("get error: %s\n", fdb.errmsg(ecode)) end # traverse records fdb.iterinit while key = fdb.iternext value = fdb.get(key) if value printf("%s:%s\n", key, value) end end # hash-like usage fdb[1728] = "seventeen twenty eight" printf("%s\n", fdb[1728]) fdb.each do |key, value| printf("%s:%s\n", key, value) end # close the database if !fdb.close ecode = fdb.ecode STDERR.printf("close error: %s\n", fdb.errmsg(ecode)) end tokyocabinet-ruby-1.31/example/tcbdbex.rb0000644000175000017500000000173011547412351016663 0ustar spkspkrequire 'tokyocabinet' include TokyoCabinet # create the object bdb = BDB::new # open the database if !bdb.open("casket.tcb", BDB::OWRITER | BDB::OCREAT) ecode = bdb.ecode STDERR.printf("open error: %s\n", bdb.errmsg(ecode)) end # store records if !bdb.put("foo", "hop") || !bdb.put("bar", "step") || !bdb.put("baz", "jump") ecode = bdb.ecode STDERR.printf("put error: %s\n", bdb.errmsg(ecode)) end # retrieve records value = bdb.get("foo") if value printf("%s\n", value) else ecode = bdb.ecode STDERR.printf("get error: %s\n", bdb.errmsg(ecode)) end # traverse records cur = BDBCUR::new(bdb) cur.first while key = cur.key value = cur.val if value printf("%s:%s\n", key, value) end cur.next end # hash-like usage bdb["quux"] = "touchdown" printf("%s\n", bdb["quux"]) bdb.each do |key, value| printf("%s:%s\n", key, value) end # close the database if !bdb.close ecode = bdb.ecode STDERR.printf("close error: %s\n", bdb.errmsg(ecode)) end tokyocabinet-ruby-1.31/example/tcadbex.rb0000644000175000017500000000137311547412351016665 0ustar spkspkrequire 'tokyocabinet' include TokyoCabinet # create the object adb = ADB::new # open the database if !adb.open("casket.tch") STDERR.printf("open error\n") end # store records if !adb.put("foo", "hop") || !adb.put("bar", "step") || !adb.put("baz", "jump") STDERR.printf("put error\n") end # retrieve records value = adb.get("foo") if value printf("%s\n", value) else STDERR.printf("get error\n") end # traverse records adb.iterinit while key = adb.iternext value = adb.get(key) if value printf("%s:%s\n", key, value) end end # hash-like usage adb["quux"] = "touchdown" printf("%s\n", adb["quux"]) adb.each do |key, value| printf("%s:%s\n", key, value) end # close the database if !adb.close STDERR.printf("close error\n") end tokyocabinet-ruby-1.31/example/tchdbex.rb0000644000175000017500000000170311547412351016671 0ustar spkspkrequire 'tokyocabinet' include TokyoCabinet # create the object hdb = HDB::new # open the database if !hdb.open("casket.tch", HDB::OWRITER | HDB::OCREAT) ecode = hdb.ecode STDERR.printf("open error: %s\n", hdb.errmsg(ecode)) end # store records if !hdb.put("foo", "hop") || !hdb.put("bar", "step") || !hdb.put("baz", "jump") ecode = hdb.ecode STDERR.printf("put error: %s\n", hdb.errmsg(ecode)) end # retrieve records value = hdb.get("foo") if value printf("%s\n", value) else ecode = hdb.ecode STDERR.printf("get error: %s\n", hdb.errmsg(ecode)) end # traverse records hdb.iterinit while key = hdb.iternext value = hdb.get(key) if value printf("%s:%s\n", key, value) end end # hash-like usage hdb["quux"] = "touchdown" printf("%s\n", hdb["quux"]) hdb.each do |key, value| printf("%s:%s\n", key, value) end # close the database if !hdb.close ecode = hdb.ecode STDERR.printf("close error: %s\n", hdb.errmsg(ecode)) end tokyocabinet-ruby-1.31/example/tctdbex.rb0000644000175000017500000000235511547412351016711 0ustar spkspkrequire 'tokyocabinet' include TokyoCabinet # create the object tdb = TDB::new # open the database if !tdb.open("casket.tct", TDB::OWRITER | TDB::OCREAT) ecode = tdb.ecode STDERR.printf("open error: %s\n", tdb.errmsg(ecode)) end # store a record pkey = tdb.genuid cols = { "name" => "mikio", "age" => "30", "lang" => "ja,en,c" } if !tdb.put(pkey, cols) ecode = tdb.ecode STDERR.printf("get error: %s\n", tdb.errmsg(ecode)) end # store another record cols = { "name" => "falcon", "age" => "31", "lang" => "ja", "skill" => "cook,blog" } if !tdb.put("x12345", cols) ecode = tdb.ecode STDERR.printf("get error: %s\n", tdb.errmsg(ecode)) end # search for records qry = TDBQRY::new(tdb) qry.addcond("age", TDBQRY::QCNUMGE, "20") qry.addcond("lang", TDBQRY::QCSTROR, "ja,en") qry.setorder("name", TDBQRY::QOSTRASC) qry.setlimit(10) res = qry.search res.each do |rkey| rcols = tdb.get(rkey) printf("name:%s\n", rcols["name"]) end # hash-like usage tdb["joker"] = { "name" => "ozma", "lang" => "en", "skill" => "song,dance" } printf("%s\n", tdb["joker"]["name"]) tdb.each do |key, value| printf("%s:%s\n", key, value["name"]) end # close the database if !tdb.close ecode = tdb.ecode STDERR.printf("close error: %s\n", tdb.errmsg(ecode)) end tokyocabinet-ruby-1.31/tcftest.rb0000644000175000017500000002776111547412351015305 0ustar spkspk#! /usr/bin/ruby -w #------------------------------------------------------------------------------------------------- # The test cases of the fixed-length database API # Copyright (C) 2006-2010 FAL Labs # This file is part of Tokyo Cabinet. # Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of # the GNU Lesser General Public License as published by the Free Software Foundation; either # version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope # that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. # You should have received a copy of the GNU Lesser General Public License along with Tokyo # Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA. #------------------------------------------------------------------------------------------------- require 'tokyocabinet' include TokyoCabinet # main routine def main ARGV.length >= 1 || usage if ARGV[0] == "write" rv = runwrite elsif ARGV[0] == "read" rv = runread elsif ARGV[0] == "remove" rv = runremove elsif ARGV[0] == "misc" rv = runmisc else usage end GC.start return rv end # print the usage and exit def usage STDERR.printf("%s: test cases of the fixed-length database API\n", $progname) STDERR.printf("\n") STDERR.printf("usage:\n") STDERR.printf(" %s write [-nl|-nb] path rnum [width [limsiz]]\n", $progname) STDERR.printf(" %s read [-nl|-nb] path\n", $progname) STDERR.printf(" %s remove [-nl|-nb] path\n", $progname) STDERR.printf(" %s misc [-nl|-nb] path rnum\n", $progname) STDERR.printf("\n") exit(1) end # print error message of fixed-length database def eprint(fdb, func) path = fdb.path STDERR.printf("%s: %s: %s: %s\n", $progname, path ? path : "-", func, fdb.errmsg) end # parse arguments of write command def runwrite path = nil rnum = nil width = nil limsiz = nil omode = 0 i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-nl" omode |= FDB::ONOLCK elsif ARGV[i] == "-nb" omode |= FDB::OLCKNB else usage end elsif !path path = ARGV[i] elsif !rnum rnum = ARGV[i].to_i elsif !width width = ARGV[i].to_i elsif !limsiz limsiz = ARGV[i].to_i else usage end i += 1 end usage if !path || !rnum || rnum < 1 width = width ? width : -1 limsiz = limsiz ? limsiz : -1 rv = procwrite(path, rnum, width, limsiz, omode) return rv end # parse arguments of read command def runread path = nil omode = 0 i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-nl" omode |= FDB::ONOLCK elsif ARGV[i] == "-nb" omode |= FDB::OLCKNB else usage end elsif !path path = ARGV[i] else usage end i += 1 end usage if !path rv = procread(path, omode) return rv end # parse arguments of remove command def runremove path = nil omode = 0 i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-nl" omode |= FDB::ONOLCK elsif ARGV[i] == "-nb" omode |= FDB::OLCKNB else usage end elsif !path path = ARGV[i] else usage end i += 1 end usage if !path rv = procremove(path, omode) return rv end # parse arguments of misc command def runmisc path = nil rnum = nil omode = 0 i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-nl" omode |= FDB::ONOLCK elsif ARGV[i] == "-nb" omode |= FDB::OLCKNB else usage end elsif !path path = ARGV[i] elsif !rnum rnum = ARGV[i].to_i else usage end i += 1 end usage if !path || !rnum || rnum < 1 rv = procmisc(path, rnum, omode) return rv end # perform write command def procwrite(path, rnum, width, limsiz, omode) printf("\n path=%s rnum=%d width=%d limsiz=%d omode=%d\n\n", path, rnum, width, limsiz, omode) err = false stime = Time.now fdb = FDB::new if !fdb.tune(width, limsiz) eprint(fdb, "tune") err = true end if !fdb.open(path, FDB::OWRITER | FDB::OCREAT | FDB::OTRUNC | omode) eprint(fdb, "open") err = true end for i in 1..rnum buf = sprintf("%08d", i) if !fdb.put(buf, buf) eprint(fdb, "put") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("record number: %d\n", fdb.rnum) printf("size: %d\n", fdb.fsiz) if !fdb.close eprint(fdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # perform read command def procread(path, omode) printf("\n path=%s omode=%d\n\n", path, omode) err = false stime = Time.now fdb = FDB::new if !fdb.open(path, FDB::OREADER | omode) eprint(fdb, "open") err = true end rnum = fdb.rnum for i in 1..rnum buf = sprintf("%08d", i) if !fdb.get(buf) eprint(fdb, "get") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("record number: %d\n", fdb.rnum) printf("size: %d\n", fdb.fsiz) if !fdb.close eprint(fdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # perform remove command def procremove(path, omode) printf("\n path=%s omode=%d\n\n", path, omode) err = false stime = Time.now fdb = FDB::new if !fdb.open(path, FDB::OWRITER | omode) eprint(fdb, "open") err = true end rnum = fdb.rnum for i in 1..rnum buf = sprintf("%08d", i) if !fdb.out(buf) eprint(fdb, "out") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("record number: %d\n", fdb.rnum) printf("size: %d\n", fdb.fsiz) if !fdb.close eprint(fdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # perform misc command def procmisc(path, rnum, omode) printf("\n path=%s rnum=%d omode=%d\n\n", path, rnum, omode) err = false stime = Time.now fdb = FDB::new if !fdb.tune(10, 1024 + 32 * rnum) eprint(fdb, "tune") err = true end if !fdb.open(path, FDB::OWRITER | FDB::OCREAT | FDB::OTRUNC | omode) eprint(fdb, "open") err = true end printf("writing:\n") for i in 1..rnum buf = sprintf("%08d", i) if !fdb.put(buf, buf) eprint(fdb, "put") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("reading:\n") for i in 1..rnum buf = sprintf("%08d", i) if !fdb.get(buf) eprint(fdb, "get") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("removing:\n") for i in 1..rnum buf = sprintf("%08d", i) if rand(2) == 0 && !fdb.out(buf) eprint(fdb, "out") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("checking iterator:\n") if !fdb.iterinit eprint(fdb, "iterinit") err = true end inum = 0 while key = fdb.iternext value = fdb.get(key) if !value eprint(fdb, "get") err = true end if inum > 0 && rnum > 250 && inum % (rnum / 250) == 0 print('.') if inum == rnum || inum % (rnum / 10) == 0 printf(" (%08d)\n", inum) end end inum += 1 end printf(" (%08d)\n", inum) if rnum > 250 if fdb.ecode != FDB::ENOREC || inum != fdb.rnum eprint(fdb, "(validation)") err = true end keys = fdb.range("[min,max]", 10) if fdb.rnum >= 10 && keys.size != 10 eprint(fdb, "range") err = true end printf("checking counting:\n") for i in 1..rnum buf = sprintf("[%d]", rand(rnum) + 1) if rand(2) == 0 if !fdb.addint(buf, 1) && fdb.ecode != FDB::EKEEP eprint(fdb, "addint") err = true break end else if !fdb.adddouble(buf, 1) && fdb.ecode != FDB::EKEEP eprint(fdb, "adddouble") err = true break end end if i > 0 && rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end if !fdb.sync eprint(fdb, "sync") err = true end if !fdb.optimize eprint(fdb, "optimize") err = true end npath = path + "-tmp" if !fdb.copy(npath) eprint(fdb, "copy") err = true end File::unlink(npath) if !fdb.vanish eprint(fdb, "vanish") err = true end printf("checking transaction commit:\n") if !fdb.tranbegin eprint(fdb, "tranbegin") err = true end for i in 1..rnum buf = sprintf("%d", rand(rnum) + 1) if rand(2) == 0 if !fdb.putcat(buf, buf) eprint(fdb, "putcat") err = true break end else if !fdb.out(buf) && fdb.ecode != FDB::ENOREC eprint(fdb, "out") err = true break end end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end if !fdb.trancommit eprint(fdb, "trancommit") err = true end printf("checking transaction abort:\n") ornum = fdb.rnum ofsiz = fdb.fsiz if !fdb.tranbegin eprint(fdb, "tranbegin") err = true end for i in 1..rnum buf = sprintf("%d", rand(rnum) + 1) if rand(2) == 0 if !fdb.putcat(buf, buf) eprint(fdb, "putcat") err = true break end else if !fdb.out(buf) && fdb.ecode != FDB::ENOREC eprint(fdb, "out") err = true break end end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end if !fdb.tranabort eprint(fdb, "trancommit") err = true end if fdb.rnum != ornum || fdb.fsiz != ofsiz eprint(fdb, "(validation)") err = true end printf("checking hash-like updating:\n") for i in 1..rnum buf = sprintf("[%d]", rand(rnum) + 1) rnd = rand(4) if rnd == 0 fdb[buf] = buf elsif rnd == 1 value = fdb[buf] elsif rnd == 2 res = fdb.key?(buf) elsif rnd == 3 fdb.delete(buf) end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("checking hash-like iterator:\n") inum = 0 fdb.each do |tkey, tvalue| if inum > 0 && rnum > 250 && inum % (rnum / 250) == 0 print('.') if inum == rnum || inum % (rnum / 10) == 0 printf(" (%08d)\n", inum) end end inum += 1 end printf(" (%08d)\n", inum) if rnum > 250 fdb.clear printf("record number: %d\n", fdb.rnum) printf("size: %d\n", fdb.fsiz) if !fdb.close eprint(fdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # execute main STDOUT.sync = true $progname = $0.dup $progname.gsub!(/.*\//, "") srand exit(main) # END OF FILE tokyocabinet-ruby-1.31/COPYING0000644000175000017500000006347611547412351014342 0ustar spkspk GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! tokyocabinet-ruby-1.31/test.rb0000644000175000017500000000364211547412351014600 0ustar spkspk#! /usr/bin/ruby require 'rbconfig' commands = [ "tchtest.rb write casket 10000", "tchtest.rb read casket", "tchtest.rb remove casket", "tchtest.rb misc casket 1000", "tchtest.rb write -tl -as -td casket 10000 10000 1 1", "tchtest.rb read -nl casket", "tchtest.rb remove -nb casket", "tchtest.rb misc -tl -tb casket 1000", "tcbtest.rb write casket 10000", "tcbtest.rb read casket", "tcbtest.rb remove casket", "tcbtest.rb misc casket 1000", "tcbtest.rb write -tl casket 10000 10 10 100 1 1", "tcbtest.rb read -nl casket", "tcbtest.rb remove -nb casket", "tcbtest.rb misc -tl -tb casket 1000", "tcftest.rb write casket 10000", "tcftest.rb read casket", "tcftest.rb remove casket", "tcftest.rb misc casket 1000", "tcttest.rb write -ip -is -in casket 1000", "tcttest.rb read casket", "tcttest.rb remove casket", "tcttest.rb misc casket 500", "tcttest.rb write -tl -is -td casket 1000 1000 1 1", "tcttest.rb read -nl casket", "tcttest.rb remove -nb casket", "tcttest.rb misc -tl -tb casket 500", "tcatest.rb write 'casket.tch#mode=wct' 10000", "tcatest.rb read 'casket.tch#mode=r'", "tcatest.rb remove 'casket.tch#mode=w'", "tcatest.rb misc 'casket.tch#mode=wct' 1000", ] rubycmd = Config::CONFIG["bindir"] + "/" + RbConfig::CONFIG['ruby_install_name'] num = 1 commands.each do |command| rv = system("#{rubycmd} #{command} >/dev/null") if rv printf("%03d/%03d: %s: ok\n", num, commands.size, command) else printf("%03d/%03d: %s: failed\n", num, commands.size, command) exit(1) end num += 1 end printf("all ok\n") system("rm -rf casket*") tokyocabinet-ruby-1.31/tokyocabinet-doc.rb0000644000175000017500000027276411547412351017074 0ustar spkspk#-- # Ruby binding of Tokyo Cabinet # Copyright (C) 2006-2010 FAL Labs # This file is part of Tokyo Cabinet. # Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of # the GNU Lesser General Public License as published by the Free Software Foundation; either # version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope # that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. # You should have received a copy of the GNU Lesser General Public License along with Tokyo # Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA. #++ #:include:overview.rd module TokyoCabinet # the version information VERSION = "x.y.z" # Hash database is a file containing a hash table and is handled with the hash database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the hash database object to it. To avoid data missing or corruption, it is important to close every database file when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.%% # Except for the interface below, methods compatible with the `Hash' class are also provided; `[]', `[]=', `store', `delete', `fetch', `has_key?', `has_value?', `key', `clear', `length', `empty?', `each', `each_key', `each_value', and `keys'.%% class HDB # error code: success ESUCCESS = 0 # error code: threading error ETHREAD = 1 # error code: invalid operation EINVALID = 2 # error code: file not found ENOFILE = 3 # error code: no permission ENOPERM = 4 # error code: invalid meta data EMETA = 5 # error code: invalid record header ERHEAD = 6 # error code: open error EOPEN = 7 # error code: close error ECLOSE = 8 # error code: trunc error ETRUNC = 9 # error code: sync error ESYNC = 10 # error code: stat error ESTAT = 11 # error code: seek error ESEEK = 12 # error code: read error EREAD = 13 # error code: write error EWRITE = 14 # error code: mmap error EMMAP = 15 # error code: lock error ELOCK = 16 # error code: unlink error EUNLINK = 17 # error code: rename error ERENAME = 18 # error code: mkdir error EMKDIR = 19 # error code: rmdir error ERMDIR = 20 # error code: existing record EKEEP = 21 # error code: no record found ENOREC = 22 # error code: miscellaneous error EMISC = 9999 # tuning option: use 64-bit bucket array TLARGE = 1 << 0 # tuning option: compress each record with Deflate TDEFLATE = 1 << 1 # tuning option: compress each record with BZIP2 TBZIP = 1 << 2 # tuning option: compress each record with TCBS TTCBS = 1 << 3 # open mode: open as a reader OREADER = 1 << 0 # open mode: open as a writer OWRITER = 1 << 1 # open mode: writer creating OCREAT = 1 << 2 # open mode: writer truncating OTRUNC = 1 << 3 # open mode: open without locking ONOLCK = 1 << 4 # open mode: lock without blocking OLCKNB = 1 << 5 # open mode: synchronize every transaction OTSYNC = 1 << 6 # Create a hash database object.%% # The return value is the new hash database object.%% def initialize() # (native code) end # Get the message string corresponding to an error code.%% # `ecode' specifies the error code. If it is not defined or negative, the last happened error code is specified.%% # The return value is the message string of the error code.%% def errmsg(ecode) # (native code) end # Get the last happened error code.%% # The return value is the last happened error code.%% # The following error codes are defined: `TokyoCabinet::HDB::ESUCCESS' for success, `TokyoCabinet::HDB::ETHREAD' for threading error, `TokyoCabinet::HDB::EINVALID' for invalid operation, `TokyoCabinet::HDB::ENOFILE' for file not found, `TokyoCabinet::HDB::ENOPERM' for no permission, `TokyoCabinet::HDB::EMETA' for invalid meta data, `TokyoCabinet::HDB::ERHEAD' for invalid record header, `TokyoCabinet::HDB::EOPEN' for open error, `TokyoCabinet::HDB::ECLOSE' for close error, `TokyoCabinet::HDB::ETRUNC' for trunc error, `TokyoCabinet::HDB::ESYNC' for sync error, `TokyoCabinet::HDB::ESTAT' for stat error, `TokyoCabinet::HDB::ESEEK' for seek error, `TokyoCabinet::HDB::EREAD' for read error, `TokyoCabinet::HDB::EWRITE' for write error, `TokyoCabinet::HDB::EMMAP' for mmap error, `TokyoCabinet::HDB::ELOCK' for lock error, `TokyoCabinet::HDB::EUNLINK' for unlink error, `TokyoCabinet::HDB::ERENAME' for rename error, `TokyoCabinet::HDB::EMKDIR' for mkdir error, `TokyoCabinet::HDB::ERMDIR' for rmdir error, `TokyoCabinet::HDB::EKEEP' for existing record, `TokyoCabinet::HDB::ENOREC' for no record found, and `TokyoCabinet::HDB::EMISC' for miscellaneous error.%% def ecode() # (native code) end # Set the tuning parameters.%% # `bnum' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 131071. Suggested size of the bucket array is about from 0.5 to 4 times of the number of all records to be stored.%% # `apow' specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^4=16.%% # `fpow' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.%% # `opts' specifies options by bitwise-or: `TokyoCabinet::HDB::TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::HDB::TDEFLATE' specifies that each record is compressed with Deflate encoding, `TokyoCabinet::HDB::TDBZIP' specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::HDB::TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.%% # If successful, the return value is true, else, it is false. Note that the tuning parameters of the database should be set before the database is opened.%% def tune(bnum, apow, fpow, opts) # (native code) end # Set the caching parameters.%% # `rcnum' specifies the maximum number of records to be cached. If it is not defined or not more than 0, the record cache is disabled. It is disabled by default.%% # If successful, the return value is true, else, it is false.%% # Note that the caching parameters of the database should be set before the database is opened.%% def setcache(rcnum) # (native code) end # Set the size of the extra mapped memory.%% # `xmsiz' specifies the size of the extra mapped memory. If it is not defined or not more than 0, the extra mapped memory is disabled. The default size is 67108864.%% # If successful, the return value is true, else, it is false.%% # Note that the mapping parameters should be set before the database is opened.%% def setxmsiz(xmsiz) # (native code) end # Set the unit step number of auto defragmentation.%% # `dfunit' specifie the unit step number. If it is not more than 0, the auto defragmentation is disabled. It is disabled by default.%% # If successful, the return value is true, else, it is false.%% # Note that the defragmentation parameters should be set before the database is opened.%% def setdfunit(dfunit) # (native code) end # Open a database file.%% # `path' specifies the path of the database file.%% # `omode' specifies the connection mode: `TokyoCabinet::HDB::OWRITER' as a writer, `TokyoCabinet::HDB::OREADER' as a reader. If the mode is `TokyoCabinet::HDB::OWRITER', the following may be added by bitwise-or: `TokyoCabinet::HDB::OCREAT', which means it creates a new database if not exist, `TokyoCabinet::HDB::OTRUNC', which means it creates a new database regardless if one exists, `TokyoCabinet::HDB::OTSYNC', which means every transaction synchronizes updated contents with the device. Both of `TokyoCabinet::HDB::OREADER' and `TokyoCabinet::HDB::OWRITER' can be added to by bitwise-or: `TokyoCabinet::HDB::ONOLCK', which means it opens the database file without file locking, or `TokyoCabinet::HDB::OLCKNB', which means locking is performed without blocking. If it is not defined, `TokyoCabinet::HDB::OREADER' is specified.%% # If successful, the return value is true, else, it is false.%% def open(path, omode) # (native code) end # Close the database file.%% # If successful, the return value is true, else, it is false.%% # Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.%% def close() # (native code) end # Store a record.%% # `key' specifies the key.%% # `value' specifies the value.%% # If successful, the return value is true, else, it is false.%% # If a record with the same key exists in the database, it is overwritten.%% def put(key, value) # (native code) end # Store a new record.%% # `key' specifies the key.%% # `value' specifies the value.%% # If successful, the return value is true, else, it is false.%% # If a record with the same key exists in the database, this method has no effect.%% def putkeep(key, value) # (native code) end # Concatenate a value at the end of the existing record.%% # `key' specifies the key.%% # `value' specifies the value.%% # If successful, the return value is true, else, it is false.%% # If there is no corresponding record, a new record is created.%% def putcat(key, value) # (native code) end # Store a record in asynchronous fashion.%% # `key' specifies the key.%% # `value' specifies the value.%% # If successful, the return value is true, else, it is false.%% # If a record with the same key exists in the database, it is overwritten. Records passed to this method are accumulated into the inner buffer and wrote into the file at a blast.%% def putasync(key, value) # (native code) end # Remove a record.%% # `key' specifies the key.%% # If successful, the return value is true, else, it is false.%% def out(key) # (native code) end # Retrieve a record.%% # `key' specifies the key.%% # If successful, the return value is the value of the corresponding record. `nil' is returned if no record corresponds.%% def get(key) # (native code) end # Get the size of the value of a record.%% # `key' specifies the key.%% # If successful, the return value is the size of the value of the corresponding record, else, it is -1.%% def vsiz(key) # (native code) end # Initialize the iterator.%% # If successful, the return value is true, else, it is false.%% # The iterator is used in order to access the key of every record stored in a database.%% def iterinit() # (native code) end # Get the next key of the iterator.%% # If successful, the return value is the next key, else, it is `nil'. `nil' is returned when no record is to be get out of the iterator.%% # It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.%% def iternext() # (native code) end # Get forward matching keys.%% # `prefix' specifies the prefix of the corresponding keys.%% # `max' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.%% # The return value is a list object of the keys of the corresponding records. This method does never fail. It returns an empty list even if no record corresponds.%% # Note that this method may be very slow because every key in the database is scanned.%% def fwmkeys(prefix, max) # (native code) end # Add an integer to a record.%% # `key' specifies the key.%% # `num' specifies the additional value.%% # If successful, the return value is the summation value, else, it is `nil'.%% # If the corresponding record exists, the value is treated as an integer and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `i' operator after retrieval.%% def addint(key, num) # (native code) end # Add a real number to a record.%% # `key' specifies the key.%% # `num' specifies the additional value.%% # If successful, the return value is the summation value, else, it is `nil'.%% # If the corresponding record exists, the value is treated as a real number and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `d' operator after retrieval.%% def adddouble(key, num) # (native code) end # Synchronize updated contents with the file and the device.%% # If successful, the return value is true, else, it is false.%% # This method is useful when another process connects the same database file.%% def sync() # (native code) end # Optimize the database file.%% # `bnum' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is two times of the number of records.%% # `apow' specifies the size of record alignment by power of 2. If it is not defined or negative, the current setting is not changed.%% # `fpow' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the current setting is not changed.%% # `opts' specifies options by bitwise-or: `TokyoCabinet::HDB::TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::HDB::TDEFLATE' specifies that each record is compressed with Deflate encoding, `TokyoCabinet::HDB::TBZIP' specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::HDB::TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined or 0xff, the current setting is not changed.%% # If successful, the return value is true, else, it is false.%% # This method is useful to reduce the size of the database file with data fragmentation by successive updating.%% def optimize(bnum, apow, fpow, opts) # (native code) end # Remove all records.%% # If successful, the return value is true, else, it is false.%% def vanish() # (native code) end # Copy the database file.%% # `path' specifies the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.%% # If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.%% # The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.%% def copy(path) # (native code) end # Begin the transaction.%% # If successful, the return value is true, else, it is false.%% # The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly.%% def tranbegin() # (native code) end # Commit the transaction.%% # If successful, the return value is true, else, it is false.%% # Update in the transaction is fixed when it is committed successfully.%% def trancommit() # (native code) end # Abort the transaction.%% # If successful, the return value is true, else, it is false.%% # Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.%% def tranabort() # (native code) end # Get the path of the database file.%% # The return value is the path of the database file or `nil' if the object does not connect to any database file.%% def path() # (native code) end # Get the number of records.%% # The return value is the number of records or 0 if the object does not connect to any database file.%% def rnum() # (native code) end # Get the size of the database file.%% # The return value is the size of the database file or 0 if the object does not connect to any database file.%% def fsiz() # (native code) end end # B+ tree database is a file containing a B+ tree and is handled with the B+ tree database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the B+ tree database object to it. To avoid data missing or corruption, it is important to close every database file when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.%% # Except for the interface below, methods compatible with the `Hash' class are also provided; `[]', `[]=', `store', `delete', `fetch', `has_key?', `has_value?', `key', `clear', `length', `empty?', `each', `each_key', `each_value', and `keys'.%% class BDB # error code: success ESUCCESS = 0 # error code: threading error ETHREAD = 1 # error code: invalid operation EINVALID = 2 # error code: file not found ENOFILE = 3 # error code: no permission ENOPERM = 4 # error code: invalid meta data EMETA = 5 # error code: invalid record header ERHEAD = 6 # error code: open error EOPEN = 7 # error code: close error ECLOSE = 8 # error code: trunc error ETRUNC = 9 # error code: sync error ESYNC = 10 # error code: stat error ESTAT = 11 # error code: seek error ESEEK = 12 # error code: read error EREAD = 13 # error code: write error EWRITE = 14 # error code: mmap error EMMAP = 15 # error code: lock error ELOCK = 16 # error code: unlink error EUNLINK = 17 # error code: rename error ERENAME = 18 # error code: mkdir error EMKDIR = 19 # error code: rmdir error ERMDIR = 20 # error code: existing record EKEEP = 21 # error code: no record found ENOREC = 22 # error code: miscellaneous error EMISC = 9999 # comparison function: by lexical order CMPLEXICAL = "CMPLEXICAL" # comparison function: as decimal strings of real numbers CMPDECIMAL = "CMPDECIMAL" # comparison function: as 32-bit integers in the native byte order CMPINT32 = "CMPINT32" # comparison function: as 64-bit integers in the native byte order CMPINT64 = "CMPINT64" # tuning option: use 64-bit bucket array TLARGE = 1 << 0 # tuning option: compress each record with Deflate TDEFLATE = 1 << 1 # tuning option: compress each record with BZIP2 TBZIP = 1 << 2 # tuning option: compress each record with TCBS TTCBS = 1 << 3 # open mode: open as a reader OREADER = 1 << 0 # open mode: open as a writer OWRITER = 1 << 1 # open mode: writer creating OCREAT = 1 << 2 # open mode: writer truncating OTRUNC = 1 << 3 # open mode: open without locking ONOLCK = 1 << 4 # open mode: lock without blocking OLCKNB = 1 << 5 # open mode: synchronize every transaction OTSYNC = 1 << 6 # Create a B+ tree database object.%% # The return value is the new B+ tree database object.%% def initialize() # (native code) end # Get the message string corresponding to an error code.%% # `ecode' specifies the error code. If it is not defined or negative, the last happened error code is specified.%% # The return value is the message string of the error code.%% def errmsg(ecode) # (native code) end # Get the last happened error code.%% # The return value is the last happened error code.%% # The following error codes are defined: `TokyoCabinet::BDB::ESUCCESS' for success, `TokyoCabinet::BDB::ETHREAD' for threading error, `TokyoCabinet::BDB::EINVALID' for invalid operation, `TokyoCabinet::BDB::ENOFILE' for file not found, `TokyoCabinet::BDB::ENOPERM' for no permission, `TokyoCabinet::BDB::EMETA' for invalid meta data, `TokyoCabinet::BDB::ERHEAD' for invalid record header, `TokyoCabinet::BDB::EOPEN' for open error, `TokyoCabinet::BDB::ECLOSE' for close error, `TokyoCabinet::BDB::ETRUNC' for trunc error, `TokyoCabinet::BDB::ESYNC' for sync error, `TokyoCabinet::BDB::ESTAT' for stat error, `TokyoCabinet::BDB::ESEEK' for seek error, `TokyoCabinet::BDB::EREAD' for read error, `TokyoCabinet::BDB::EWRITE' for write error, `TokyoCabinet::BDB::EMMAP' for mmap error, `TokyoCabinet::BDB::ELOCK' for lock error, `TokyoCabinet::BDB::EUNLINK' for unlink error, `TokyoCabinet::BDB::ERENAME' for rename error, `TokyoCabinet::BDB::EMKDIR' for mkdir error, `TokyoCabinet::BDB::ERMDIR' for rmdir error, `TokyoCabinet::BDB::EKEEP' for existing record, `TokyoCabinet::BDB::ENOREC' for no record found, and `TokyoCabinet::BDB::EMISC' for miscellaneous error.%% def ecode() # (native code) end # Set the custom comparison function.%% # `cmp' specifies the custom comparison function. It should be an instance of the class `Proc'.%% # If successful, the return value is true, else, it is false.%% # The default comparison function compares keys of two records by lexical order. The constants `TokyoCabinet::BDB::CMPLEXICAL' (dafault), `TokyoCabinet::BDB::CMPDECIMAL', `TokyoCabinet::BDB::CMPINT32', and `TokyoCabinet::BDB::CMPINT64' are built-in. Note that the comparison function should be set before the database is opened. Moreover, user-defined comparison functions should be set every time the database is being opened.%% def setcmpfunc(cmp) # (native code) end # Set the tuning parameters.%% # `lmemb' specifies the number of members in each leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 128.%% # `nmemb' specifies the number of members in each non-leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 256.%% # `bnum' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 32749. Suggested size of the bucket array is about from 1 to 4 times of the number of all pages to be stored.%% # `apow' specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^8=256.%% # `fpow' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.%% # `opts' specifies options by bitwise-or: `TokyoCabinet::BDB::TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::BDB::TDEFLATE' specifies that each record is compressed with Deflate encoding, `TokyoCabinet::BDB::TBZIP' specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::BDB::TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.%% # If successful, the return value is true, else, it is false. Note that the tuning parameters of the database should be set before the database is opened.%% def tune(lmemb, nmemb, bnum, apow, fpow, opts) # (native code) end # Set the caching parameters.%% # `lcnum' specifies the maximum number of leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 1024.%% # `ncnum' specifies the maximum number of non-leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 512.%% # If successful, the return value is true, else, it is false.%% # Note that the tuning parameters of the database should be set before the database is opened.%% def setcache(lcnum, ncnum) # (native code) end # Set the size of the extra mapped memory.%% # `xmsiz' specifies the size of the extra mapped memory. If it is not defined or not more than 0, the extra mapped memory is disabled. It is disabled by default.%% # If successful, the return value is true, else, it is false.%% # Note that the mapping parameters should be set before the database is opened.%% def setxmsiz(xmsiz) # (native code) end # Set the unit step number of auto defragmentation.%% # `dfunit' specifie the unit step number. If it is not more than 0, the auto defragmentation is disabled. It is disabled by default.%% # If successful, the return value is true, else, it is false.%% # Note that the defragmentation parameters should be set before the database is opened.%% def setdfunit(dfunit) # (native code) end # Open a database file.%% # `path' specifies the path of the database file.%% # `omode' specifies the connection mode: `TokyoCabinet::BDB::OWRITER' as a writer, `TokyoCabinet::BDB::OREADER' as a reader. If the mode is `TokyoCabinet::BDB::OWRITER', the following may be added by bitwise-or: `TokyoCabinet::BDB::OCREAT', which means it creates a new database if not exist, `TokyoCabinet::BDB::OTRUNC', which means it creates a new database regardless if one exists, `TokyoCabinet::BDB::OTSYNC', which means every transaction synchronizes updated contents with the device. Both of `TokyoCabinet::BDB::OREADER' and `TokyoCabinet::BDB::OWRITER' can be added to by bitwise-or: `TokyoCabinet::BDB::ONOLCK', which means it opens the database file without file locking, or `TokyoCabinet::BDB::OLCKNB', which means locking is performed without blocking. If it is not defined, `TokyoCabinet::BDB::OREADER' is specified.%% # If successful, the return value is true, else, it is false.%% def open(path, omode) # (native code) end # Close the database file.%% # If successful, the return value is true, else, it is false.%% # Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.%% def close() # (native code) end # Store a record.%% # `key' specifies the key.%% # `value' specifies the value.%% # If successful, the return value is true, else, it is false.%% # If a record with the same key exists in the database, it is overwritten.%% def put(key, value) # (native code) end # Store a new record.%% # `key' specifies the key.%% # `value' specifies the value.%% # If successful, the return value is true, else, it is false.%% # If a record with the same key exists in the database, this method has no effect.%% def putkeep(key, value) # (native code) end # Concatenate a value at the end of the existing record.%% # `key' specifies the key.%% # `value' specifies the value.%% # If successful, the return value is true, else, it is false.%% # If there is no corresponding record, a new record is created.%% def putcat(key, value) # (native code) end # Store a record with allowing duplication of keys.%% # `key' specifies the key.%% # `value' specifies the value.%% # If successful, the return value is true, else, it is false.%% # If a record with the same key exists in the database, the new record is placed after the existing one.%% def putdup(key, value) # (native code) end # Store records with allowing duplication of keys.%% # `key' specifies the key.%% # `values' specifies an array of the values.%% # If successful, the return value is true, else, it is false.%% # If a record with the same key exists in the database, the new records are placed after the existing one.%% def putlist(key, values) # (native code) end # Remove a record.%% # `key' specifies the key.%% # If successful, the return value is true, else, it is false.%% # If the key of duplicated records is specified, the value of the first one is selected.%% def out(key) # (native code) end # Remove records.%% # `key' specifies the key.%% # If successful, the return value is true, else, it is false.%% # If the key of duplicated records is specified, all of them are removed.%% def outlist(key) # (native code) end # Retrieve a record.%% # `key' specifies the key.%% # If successful, the return value is the value of the corresponding record. `nil' is returned if no record corresponds.%% # If the key of duplicated records is specified, the value of the first one is selected.%% def get(key) # (native code) end # Retrieve records.%% # `key' specifies the key.%% # If successful, the return value is a list object of the values of the corresponding records. `nil' is returned if no record corresponds.%% def getlist(key) # (native code) end # Get the number of records corresponding a key.%% # `key' specifies the key.%% # If successful, the return value is the number of the corresponding records, else, it is 0.%% def vnum(key) # (native code) end # Get the size of the value of a record.%% # `key' specifies the key.%% # If successful, the return value is the size of the value of the corresponding record, else, it is -1.%% # If the key of duplicated records is specified, the value of the first one is selected.%% def vsiz(key) # (native code) end # Get keys of ranged records.%% # `bkey' specifies the key of the beginning border. If it is not defined, the first record is specified.%% # `binc' specifies whether the beginning border is inclusive or not. If it is not defined, false is specified.%% # `ekey' specifies the key of the ending border. If it is not defined, the last record is specified.%% # `einc' specifies whether the ending border is inclusive or not. If it is not defined, false is specified.%% # `max' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.%% # The return value is a list object of the keys of the corresponding records. This method does never fail. It returns an empty list even if no record corresponds.%% def range(bkey, binc, ekey, einc, max) # (native code) end # Get forward matching keys.%% # `prefix' specifies the prefix of the corresponding keys.%% # `max' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.%% # The return value is a list object of the keys of the corresponding records. This method does never fail. It returns an empty list even if no record corresponds.%% def fwmkeys(prefix, max) # (native code) end # Add an integer to a record.%% # `key' specifies the key.%% # `num' specifies the additional value.%% # If successful, the return value is the summation value, else, it is `nil'.%% # If the corresponding record exists, the value is treated as an integer and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `i' operator after retrieval.%% def addint(key, num) # (native code) end # Add a real number to a record.%% # `key' specifies the key.%% # `num' specifies the additional value.%% # If successful, the return value is the summation value, else, it is `nil'.%% # If the corresponding record exists, the value is treated as a real number and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `d' operator after retrieval.%% def adddouble(key, num) # (native code) end # Synchronize updated contents with the file and the device.%% # If successful, the return value is true, else, it is false.%% # This method is useful when another process connects the same database file.%% def sync() # (native code) end # Optimize the database file.%% # `lmemb' specifies the number of members in each leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 128.%% # `nmemb' specifies the number of members in each non-leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 256.%% # `bnum' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is two times of the number of pages.%% # `apow' specifies the size of record alignment by power of 2. If it is not defined or negative, the current setting is not changed.%% # `fpow' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the current setting is not changed.%% # `opts' specifies options by bitwise-or: `TokyoCabinet::BDB::TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::BDB::TDEFLATE' specifies that each record is compressed with Deflate encoding, `TokyoCabinet::BDB::TBZIP' specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::BDB::TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined or 0xff, the current setting is not changed.%% # If successful, the return value is true, else, it is false.%% # This method is useful to reduce the size of the database file with data fragmentation by successive updating.%% def optimize(lmemb, nmemb, bnum, apow, fpow, opts) # (native code) end # Remove all records.%% # If successful, the return value is true, else, it is false.%% def vanish() # (native code) end # Copy the database file.%% # `path' specifies the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.%% # If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.%% # The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.%% def copy(path) # (native code) end # Begin the transaction.%% # If successful, the return value is true, else, it is false.%% # The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. Because all pages are cached on memory while the transaction, the amount of referred records is limited by the memory capacity. If the database is closed during transaction, the transaction is aborted implicitly.%% def tranbegin() # (native code) end # Commit the transaction.%% # If successful, the return value is true, else, it is false.%% # Update in the transaction is fixed when it is committed successfully.%% def trancommit() # (native code) end # Abort the transaction.%% # If successful, the return value is true, else, it is false.%% # Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.%% def tranabort() # (native code) end # Get the path of the database file.%% # The return value is the path of the database file or `nil' if the object does not connect to any database file.%% def path() # (native code) end # Get the number of records.%% # The return value is the number of records or 0 if the object does not connect to any database file.%% def rnum() # (native code) end # Get the size of the database file.%% # The return value is the size of the database file or 0 if the object does not connect to any database file.%% def fsiz() # (native code) end end # Cursor is a mechanism to access each record of B+ tree database in ascending or descending order.%% class BDBCUR # cursor put mode: current CPCURRENT = 0 # cursor put mode: before CPBEFORE = 1 # cursor put mode: after CPAFTER = 2 # Create a cursor object.%% # `bdb' specifies the B+ tree database object.%% # The return value is the new cursor object.%% # Note that the cursor is available only after initialization with the `first' or the `jump' methods and so on. Moreover, the position of the cursor will be indefinite when the database is updated after the initialization of the cursor.%% def initialize(bdb) # (native code) end # Move the cursor to the first record.%% # If successful, the return value is true, else, it is false. False is returned if there is no record in the database.%% def first() # (native code) end # Move the cursor to the last record.%% # If successful, the return value is true, else, it is false. False is returned if there is no record in the database.%% def last() # (native code) end # Move the cursor to the front of records corresponding a key.%% # `key' specifies the key.%% # If successful, the return value is true, else, it is false. False is returned if there is no record corresponding the condition.%% # The cursor is set to the first record corresponding the key or the next substitute if completely matching record does not exist.%% def jump(key) # (native code) end # Move the cursor to the previous record.%% # If successful, the return value is true, else, it is false. False is returned if there is no previous record.%% def prev() # (native code) end # Move the cursor to the next record.%% # If successful, the return value is true, else, it is false. False is returned if there is no next record.%% def next() # (native code) end # Insert a record around the cursor.%% # `value' specifies the value.%% # `cpmode' specifies detail adjustment: `TokyoCabinet::BDBCUR::CPCURRENT', which means that the value of the current record is overwritten, `TokyoCabinet::BDBCUR::CPBEFORE', which means that the new record is inserted before the current record, `TokyoCabinet::BDBCUR::CPAFTER', which means that the new record is inserted after the current record.%% # If successful, the return value is true, else, it is false. False is returned when the cursor is at invalid position.%% # After insertion, the cursor is moved to the inserted record.%% def put(value, cpmode) # (native code) end # Remove the record where the cursor is.%% # If successful, the return value is true, else, it is false. False is returned when the cursor is at invalid position.%% # After deletion, the cursor is moved to the next record if possible.%% def out() # (native code) end # Get the key of the record where the cursor is.%% # If successful, the return value is the key, else, it is `nil'. 'nil' is returned when the cursor is at invalid position.%% def key() # (native code) end # Get the value of the record where the cursor is.%% # If successful, the return value is the value, else, it is `nil'. 'nil' is returned when the cursor is at invalid position.%% def val() # (native code) end end # Fixed-Length database is a file containing a fixed-length table and is handled with the fixed-length database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the fixed-length database object to it. To avoid data missing or corruption, it is important to close every database file when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.%% # Except for the interface below, methods compatible with the `Hash' class are also provided; `[]', `[]=', `store', `delete', `fetch', `has_key?', `has_value?', `key', `clear', `length', `empty?', `each', `each_key', `each_value', and `keys'.%% class FDB # error code: success ESUCCESS = 0 # error code: threading error ETHREAD = 1 # error code: invalid operation EINVALID = 2 # error code: file not found ENOFILE = 3 # error code: no permission ENOPERM = 4 # error code: invalid meta data EMETA = 5 # error code: invalid record header ERHEAD = 6 # error code: open error EOPEN = 7 # error code: close error ECLOSE = 8 # error code: trunc error ETRUNC = 9 # error code: sync error ESYNC = 10 # error code: stat error ESTAT = 11 # error code: seek error ESEEK = 12 # error code: read error EREAD = 13 # error code: write error EWRITE = 14 # error code: mmap error EMMAP = 15 # error code: lock error ELOCK = 16 # error code: unlink error EUNLINK = 17 # error code: rename error ERENAME = 18 # error code: mkdir error EMKDIR = 19 # error code: rmdir error ERMDIR = 20 # error code: existing record EKEEP = 21 # error code: no record found ENOREC = 22 # error code: miscellaneous error EMISC = 9999 # open mode: open as a reader OREADER = 1 << 0 # open mode: open as a writer OWRITER = 1 << 1 # open mode: writer creating OCREAT = 1 << 2 # open mode: writer truncating OTRUNC = 1 << 3 # open mode: open without locking ONOLCK = 1 << 4 # open mode: lock without blocking OLCKNB = 1 << 5 # Create a fixed-length database object.%% # The return value is the new fixed-length database object.%% def initialize() # (native code) end # Get the message string corresponding to an error code.%% # `ecode' specifies the error code. If it is not defined or negative, the last happened error code is specified.%% # The return value is the message string of the error code.%% def errmsg(ecode) # (native code) end # Get the last happened error code.%% # The return value is the last happened error code.%% # The following error codes are defined: `TokyoCabinet::FDB::ESUCCESS' for success, `TokyoCabinet::FDB::ETHREAD' for threading error, `TokyoCabinet::FDB::EINVALID' for invalid operation, `TokyoCabinet::FDB::ENOFILE' for file not found, `TokyoCabinet::FDB::ENOPERM' for no permission, `TokyoCabinet::FDB::EMETA' for invalid meta data, `TokyoCabinet::FDB::ERHEAD' for invalid record header, `TokyoCabinet::FDB::EOPEN' for open error, `TokyoCabinet::FDB::ECLOSE' for close error, `TokyoCabinet::FDB::ETRUNC' for trunc error, `TokyoCabinet::FDB::ESYNC' for sync error, `TokyoCabinet::FDB::ESTAT' for stat error, `TokyoCabinet::FDB::ESEEK' for seek error, `TokyoCabinet::FDB::EREAD' for read error, `TokyoCabinet::FDB::EWRITE' for write error, `TokyoCabinet::FDB::EMMAP' for mmap error, `TokyoCabinet::FDB::ELOCK' for lock error, `TokyoCabinet::FDB::EUNLINK' for unlink error, `TokyoCabinet::FDB::ERENAME' for rename error, `TokyoCabinet::FDB::EMKDIR' for mkdir error, `TokyoCabinet::FDB::ERMDIR' for rmdir error, `TokyoCabinet::FDB::EKEEP' for existing record, `TokyoCabinet::FDB::ENOREC' for no record found, and `TokyoCabinet::FDB::EMISC' for miscellaneous error.%% def ecode() # (native code) end # Set the tuning parameters.%% # `width' specifies the width of the value of each record. If it is not defined or not more than 0, the default value is specified. The default value is 255.%% # `limsiz' specifies the limit size of the database file. If it is not defined or not more than 0, the default value is specified. The default value is 268435456.%% # If successful, the return value is true, else, it is false. Note that the tuning parameters of the database should be set before the database is opened.%% def tune(width, limsiz) # (native code) end # Open a database file.%% # `path' specifies the path of the database file.%% # `omode' specifies the connection mode: `TokyoCabinet::FDB::OWRITER' as a writer, `TokyoCabinet::FDB::OREADER' as a reader. If the mode is `TokyoCabinet::FDB::OWRITER', the following may be added by bitwise-or: `TokyoCabinet::FDB::OCREAT', which means it creates a new database if not exist, `TokyoCabinet::FDB::OTRUNC', which means it creates a new database regardless if one exists. Both of `TokyoCabinet::FDB::OREADER' and `TokyoCabinet::FDB::OWRITER' can be added to by bitwise-or: `TokyoCabinet::FDB::ONOLCK', which means it opens the database file without file locking, or `TokyoCabinet::FDB::OLCKNB', which means locking is performed without blocking. If it is not defined, `TokyoCabinet::FDB::OREADER' is specified.%% # If successful, the return value is true, else, it is false.%% def open(path, omode) # (native code) end # Close the database file.%% # If successful, the return value is true, else, it is false.%% # Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.%% def close() # (native code) end # Store a record.%% # `key' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.%% # `value' specifies the value.%% # If successful, the return value is true, else, it is false.%% # If a record with the same key exists in the database, it is overwritten.%% def put(key, value) # (native code) end # Store a new record.%% # `key' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.%% # `value' specifies the value.%% # If successful, the return value is true, else, it is false.%% # If a record with the same key exists in the database, this method has no effect.%% def putkeep(key, value) # (native code) end # Concatenate a value at the end of the existing record.%% # `key' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.%% # `value' specifies the value.%% # If successful, the return value is true, else, it is false.%% # If there is no corresponding record, a new record is created.%% def putcat(key, value) # (native code) end # Remove a record.%% # `key' specifies the key. It should be more than 0. If it is `FDBIDMIN', the minimum ID number of existing records is specified. If it is `FDBIDMAX', the maximum ID number of existing records is specified.%% # If successful, the return value is true, else, it is false.%% def out(key) # (native code) end # Retrieve a record.%% # `key' specifies the key. It should be more than 0. If it is `FDBIDMIN', the minimum ID number of existing records is specified. If it is `FDBIDMAX', the maximum ID number of existing records is specified.%% # If successful, the return value is the value of the corresponding record. `nil' is returned if no record corresponds.%% def get(key) # (native code) end # Get the size of the value of a record.%% # `key' specifies the key. It should be more than 0. If it is `FDBIDMIN', the minimum ID number of existing records is specified. If it is `FDBIDMAX', the maximum ID number of existing records is specified.%% # If successful, the return value is the size of the value of the corresponding record, else, it is -1.%% def vsiz(key) # (native code) end # Initialize the iterator.%% # If successful, the return value is true, else, it is false.%% # The iterator is used in order to access the key of every record stored in a database.%% def iterinit() # (native code) end # Get the next key of the iterator.%% # If successful, the return value is the next key, else, it is `nil'. `nil' is returned when no record is to be get out of the iterator.%% # It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. The order of this traversal access method is ascending of the ID number.%% def iternext() # (native code) end # Get keys with an interval notation.%% # `interval' specifies the interval notation.%% # `max' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.%% # The return value is a list object of the keys of the corresponding records. This method does never fail. It returns an empty list even if no record corresponds.%% def range(interval, max) # (native code) end # Add an integer to a record.%% # `key' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.%% # `num' specifies the additional value.%% # If successful, the return value is the summation value, else, it is `nil'.%% # If the corresponding record exists, the value is treated as an integer and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `i' operator after retrieval.%% def addint(key, num) # (native code) end # Add a real number to a record.%% # `key' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.%% # `num' specifies the additional value.%% # If successful, the return value is the summation value, else, it is `nil'.%% # If the corresponding record exists, the value is treated as a real number and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `d' operator after retrieval.%% def adddouble(key, num) # (native code) end # Synchronize updated contents with the file and the device.%% # If successful, the return value is true, else, it is false.%% # This method is useful when another process connects the same database file.%% def sync() # (native code) end # Optimize the database file.%% # `width' specifies the width of the value of each record. If it is not defined or not more than 0, the current setting is not changed.%% # `limsiz' specifies the limit size of the database file. If it is not defined or not more than 0, the current setting is not changed.%% # If successful, the return value is true, else, it is false.%% def optimize(bnum, width, limsiz) # (native code) end # Remove all records.%% # If successful, the return value is true, else, it is false.%% def vanish() # (native code) end # Copy the database file.%% # `path' specifies the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.%% # If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.%% # The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.%% def copy(path) # (native code) end # Begin the transaction.%% # If successful, the return value is true, else, it is false.%% # The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly.%% def tranbegin() # (native code) end # Commit the transaction.%% # If successful, the return value is true, else, it is false.%% # Update in the transaction is fixed when it is committed successfully.%% def trancommit() # (native code) end # Abort the transaction.%% # If successful, the return value is true, else, it is false.%% # Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.%% def tranabort() # (native code) end # Get the path of the database file.%% # The return value is the path of the database file or `nil' if the object does not connect to any database file.%% def path() # (native code) end # Get the number of records.%% # The return value is the number of records or 0 if the object does not connect to any database file.%% def rnum() # (native code) end # Get the size of the database file.%% # The return value is the size of the database file or 0 if the object does not connect to any database file.%% def fsiz() # (native code) end end # Table database is a file containing records composed of the primary keys and arbitrary columns and is handled with the table database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the table database object to it. To avoid data missing or corruption, it is important to close every database file when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.%% # Except for the interface below, methods compatible with the `Hash' class are also provided; `[]', `[]=', `store', `delete', `fetch', `has_key?', `clear', `length', `empty?', `each', `each_key', `each_value', and `keys'.%% class TDB # error code: success ESUCCESS = 0 # error code: threading error ETHREAD = 1 # error code: invalid operation EINVALID = 2 # error code: file not found ENOFILE = 3 # error code: no permission ENOPERM = 4 # error code: invalid meta data EMETA = 5 # error code: invalid record header ERHEAD = 6 # error code: open error EOPEN = 7 # error code: close error ECLOSE = 8 # error code: trunc error ETRUNC = 9 # error code: sync error ESYNC = 10 # error code: stat error ESTAT = 11 # error code: seek error ESEEK = 12 # error code: read error EREAD = 13 # error code: write error EWRITE = 14 # error code: mmap error EMMAP = 15 # error code: lock error ELOCK = 16 # error code: unlink error EUNLINK = 17 # error code: rename error ERENAME = 18 # error code: mkdir error EMKDIR = 19 # error code: rmdir error ERMDIR = 20 # error code: existing record EKEEP = 21 # error code: no record found ENOREC = 22 # error code: miscellaneous error EMISC = 9999 # tuning option: use 64-bit bucket array TLARGE = 1 << 0 # tuning option: compress each record with Deflate TDEFLATE = 1 << 1 # tuning option: compress each record with BZIP2 TBZIP = 1 << 2 # tuning option: compress each record with TCBS TTCBS = 1 << 3 # open mode: open as a reader OREADER = 1 << 0 # open mode: open as a writer OWRITER = 1 << 1 # open mode: writer creating OCREAT = 1 << 2 # open mode: writer truncating OTRUNC = 1 << 3 # open mode: open without locking ONOLCK = 1 << 4 # open mode: lock without blocking OLCKNB = 1 << 5 # open mode: synchronize every transaction OTSYNC = 1 << 6 # index type: lexical string ITLEXICAL = 0 # index type: decimal string ITDECIMAL = 1 # index type: token inverted index ITTOKEN = 2 # index type: q-gram inverted index ITQGRAM = 3 # index type: optimize ITOPT = 9998 # index type: void ITVOID = 9999 # index type: keep existing index ITKEEP = 1 << 24 # Create a table database object.%% # The return value is the new table database object.%% def initialize() # (native code) end # Get the message string corresponding to an error code.%% # `ecode' specifies the error code. If it is not defined or negative, the last happened error code is specified.%% # The return value is the message string of the error code.%% def errmsg(ecode) # (native code) end # Get the last happened error code.%% # The return value is the last happened error code.%% # The following error codes are defined: `TokyoCabinet::TDB::ESUCCESS' for success, `TokyoCabinet::TDB::ETHREAD' for threading error, `TokyoCabinet::TDB::EINVALID' for invalid operation, `TokyoCabinet::TDB::ENOFILE' for file not found, `TokyoCabinet::TDB::ENOPERM' for no permission, `TokyoCabinet::TDB::EMETA' for invalid meta data, `TokyoCabinet::TDB::ERHEAD' for invalid record header, `TokyoCabinet::TDB::EOPEN' for open error, `TokyoCabinet::TDB::ECLOSE' for close error, `TokyoCabinet::TDB::ETRUNC' for trunc error, `TokyoCabinet::TDB::ESYNC' for sync error, `TokyoCabinet::TDB::ESTAT' for stat error, `TokyoCabinet::TDB::ESEEK' for seek error, `TokyoCabinet::TDB::EREAD' for read error, `TokyoCabinet::TDB::EWRITE' for write error, `TokyoCabinet::TDB::EMMAP' for mmap error, `TokyoCabinet::TDB::ELOCK' for lock error, `TokyoCabinet::TDB::EUNLINK' for unlink error, `TokyoCabinet::TDB::ERENAME' for rename error, `TokyoCabinet::TDB::EMKDIR' for mkdir error, `TokyoCabinet::TDB::ERMDIR' for rmdir error, `TokyoCabinet::TDB::EKEEP' for existing record, `TokyoCabinet::TDB::ENOREC' for no record found, and `TokyoCabinet::TDB::EMISC' for miscellaneous error.%% def ecode() # (native code) end # Set the tuning parameters.%% # `bnum' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 131071. Suggested size of the bucket array is about from 0.5 to 4 times of the number of all records to be stored.%% # `apow' specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^4=16.%% # `fpow' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.%% # `opts' specifies options by bitwise-or: `TokyoCabinet::TDB::TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::TDB::TDEFLATE' specifies that each record is compressed with Deflate encoding, `TokyoCabinet::TDB::TDBZIP' specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::TDB::TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.%% # If successful, the return value is true, else, it is false. Note that the tuning parameters of the database should be set before the database is opened.%% def tune(bnum, apow, fpow, opts) # (native code) end # Set the caching parameters.%% # `rcnum' specifies the maximum number of records to be cached. If it is not defined or not more than 0, the record cache is disabled. It is disabled by default.%% # `lcnum' specifies the maximum number of leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 4096.%% # `ncnum' specifies the maximum number of non-leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 512.%% # If successful, the return value is true, else, it is false.%% # Note that the caching parameters of the database should be set before the database is opened.%% def setcache(rcnum, lcnum, ncnum) # (native code) end # Set the size of the extra mapped memory.%% # `xmsiz' specifies the size of the extra mapped memory. If it is not defined or not more than 0, the extra mapped memory is disabled. The default size is 67108864.%% # If successful, the return value is true, else, it is false.%% # Note that the mapping parameters should be set before the database is opened.%% def setxmsiz(xmsiz) # (native code) end # Set the unit step number of auto defragmentation.%% # `dfunit' specifie the unit step number. If it is not more than 0, the auto defragmentation is disabled. It is disabled by default.%% # If successful, the return value is true, else, it is false.%% # Note that the defragmentation parameters should be set before the database is opened.%% def setdfunit(dfunit) # (native code) end # Open a database file.%% # `path' specifies the path of the database file.%% # `omode' specifies the connection mode: `TokyoCabinet::TDB::OWRITER' as a writer, `TokyoCabinet::TDB::OREADER' as a reader. If the mode is `TokyoCabinet::TDB::OWRITER', the following may be added by bitwise-or: `TokyoCabinet::TDB::OCREAT', which means it creates a new database if not exist, `TokyoCabinet::TDB::OTRUNC', which means it creates a new database regardless if one exists, `TokyoCabinet::TDB::OTSYNC', which means every transaction synchronizes updated contents with the device. Both of `TokyoCabinet::TDB::OREADER' and `TokyoCabinet::TDB::OWRITER' can be added to by bitwise-or: `TokyoCabinet::TDB::ONOLCK', which means it opens the database file without file locking, or `TokyoCabinet::TDB::OLCKNB', which means locking is performed without blocking. If it is not defined, `TokyoCabinet::TDB::OREADER' is specified.%% # If successful, the return value is true, else, it is false.%% def open(path, omode) # (native code) end # Close the database file.%% # If successful, the return value is true, else, it is false.%% # Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.%% def close() # (native code) end # Store a record.%% # `pkey' specifies the primary key.%% # `cols' specifies a hash containing columns.%% # If successful, the return value is true, else, it is false.%% # If a record with the same key exists in the database, it is overwritten.%% def put(pkey, cols) # (native code) end # Store a new record.%% # `pkey' specifies the primary key.%% # `cols' specifies a hash containing columns.%% # If successful, the return value is true, else, it is false.%% # If a record with the same key exists in the database, this method has no effect.%% def putkeep(pkey, cols) # (native code) end # Concatenate columns of the existing record.%% # `pkey' specifies the primary key.%% # `cols' specifies a hash containing columns.%% # If successful, the return value is true, else, it is false.%% # If there is no corresponding record, a new record is created.%% def putcat(pkey, value) # (native code) end # Remove a record.%% # `pkey' specifies the primary key.%% # If successful, the return value is true, else, it is false.%% def out(pkey) # (native code) end # Retrieve a record.%% # `pkey' specifies the primary key.%% # If successful, the return value is a hash of the columns of the corresponding record. `nil' is returned if no record corresponds.%% def get(pkey) # (native code) end # Get the size of the value of a record.%% # `pkey' specifies the primary key.%% # If successful, the return value is the size of the value of the corresponding record, else, it is -1.%% def vsiz(pkey) # (native code) end # Initialize the iterator.%% # If successful, the return value is true, else, it is false.%% # The iterator is used in order to access the primary key of every record stored in a database.%% def iterinit() # (native code) end # Get the next primary key of the iterator.%% # If successful, the return value is the next primary key, else, it is `nil'. `nil' is returned when no record is to be get out of the iterator.%% # It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.%% def iternext() # (native code) end # Get forward matching primary keys.%% # `prefix' specifies the prefix of the corresponding keys.%% # `max' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.%% # The return value is a list object of the keys of the corresponding records. This method does never fail. It returns an empty list even if no record corresponds.%% # Note that this method may be very slow because every key in the database is scanned.%% def fwmkeys(prefix, max) # (native code) end # Add an integer to a record.%% # `pkey' specifies the primary key.%% # `num' specifies the additional value.%% # If successful, the return value is the summation value, else, it is `nil'.%% # The additional value is stored as a decimal string value of a column whose name is "_num". If no record corresponds, a new record with the additional value is stored.%% def addint(pkey, num) # (native code) end # Add a real number to a record.%% # `key' specifies the primary key.%% # `num' specifies the additional value.%% # If successful, the return value is the summation value, else, it is `nil'.%% # The additional value is stored as a decimal string value of a column whose name is "_num". If no record corresponds, a new record with the additional value is stored.%% def adddouble(pkey, num) # (native code) end # Synchronize updated contents with the file and the device.%% # If successful, the return value is true, else, it is false.%% # This method is useful when another process connects the same database file.%% def sync() # (native code) end # Optimize the database file.%% # `bnum' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is two times of the number of records.%% # `apow' specifies the size of record alignment by power of 2. If it is not defined or negative, the current setting is not changed.%% # `fpow' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the current setting is not changed.%% # `opts' specifies options by bitwise-or: `TokyoCabinet::TDB::TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::TDB::TDEFLATE' specifies that each record is compressed with Deflate encoding, `TokyoCabinet::TDB::TBZIP' specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::TDB::TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined or 0xff, the current setting is not changed.%% # If successful, the return value is true, else, it is false.%% # This method is useful to reduce the size of the database file with data fragmentation by successive updating.%% def optimize(bnum, apow, fpow, opts) # (native code) end # Remove all records.%% # If successful, the return value is true, else, it is false.%% def vanish() # (native code) end # Copy the database file.%% # `path' specifies the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.%% # If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.%% # The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.%% def copy(path) # (native code) end # Begin the transaction.%% # If successful, the return value is true, else, it is false.%% # The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly.%% def tranbegin() # (native code) end # Commit the transaction.%% # If successful, the return value is true, else, it is false.%% # Update in the transaction is fixed when it is committed successfully.%% def trancommit() # (native code) end # Abort the transaction.%% # If successful, the return value is true, else, it is false.%% # Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.%% def tranabort() # (native code) end # Get the path of the database file.%% # The return value is the path of the database file or `nil' if the object does not connect to any database file.%% def path() # (native code) end # Get the number of records.%% # The return value is the number of records or 0 if the object does not connect to any database file.%% def rnum() # (native code) end # Get the size of the database file.%% # The return value is the size of the database file or 0 if the object does not connect to any database file.%% def fsiz() # (native code) end # Set a column index.%% # `name' specifies the name of a column. If the name of an existing index is specified, the index is rebuilt. An empty string means the primary key.%% # `type' specifies the index type: `TokyoCabinet::TDB::ITLEXICAL' for lexical string, `TokyoCabinet::TDB::ITDECIMAL' for decimal string, `TokyoCabinet::TDB::ITTOKEN' for token inverted index, `TokyoCabinet::TDB::ITQGRAM' for q-gram inverted index. If it is `TokyoCabinet::TDB::ITOPT', the index is optimized. If it is `TokyoCabinet::TDB::ITVOID', the index is removed. If `TokyoCabinet::TDB::ITKEEP' is added by bitwise-or and the index exists, this method merely returns failure.%% # If successful, the return value is true, else, it is false.%% def setindex(name, type) # (native code) end # Generate a unique ID number.%% # The return value is the new unique ID number or -1 on failure.%% def genuid() # (native code) end end # Query is a mechanism to search for and retrieve records corresponding conditions from table database.%% class TDBQRY # query condition: string is equal to QCSTREQ = 0 # query condition: string is included in QCSTRINC = 1 # query condition: string begins with QCSTRBW = 2 # query condition: string ends with QCSTREW = 3 # query condition: string includes all tokens in QCSTRAND = 4 # query condition: string includes at least one token in QCSTROR = 5 # query condition: string is equal to at least one token in QCSTROREQ = 6 # query condition: string matches regular expressions of QCSTRRX = 7 # query condition: number is equal to QCNUMEQ = 8 # query condition: number is greater than QCNUMGT = 9 # query condition: number is greater than or equal to QCNUMGE = 10 # query condition: number is less than QCNUMLT = 11 # query condition: number is less than or equal to QCNUMLE = 12 # query condition: number is between two tokens of QCNUMBT = 13 # query condition: number is equal to at least one token in QCNUMOREQ = 14 # query condition: full-text search with the phrase of QCFTSPH = 15 # query condition: full-text search with all tokens in QCFTSAND = 16 # query condition: full-text search with at least one token in QCFTSOR = 17 # query condition: full-text search with the compound expression of QCFTSEX = 18 # query condition: negation flag QCNEGATE = 1 << 24 # query condition: no index flag QCNOIDX = 1 << 25 # order type: string ascending QOSTRASC = 1 # order type: string descending QOSTRDESC = 2 # order type: number ascending QONUMASC = 3 # order type: number descending QONUMDESC = 4 # post treatment: modify the record QPPUT = 1 << 0 # post treatment: remove the record QPOUT = 1 << 1 # post treatment: stop the iteration QPSTOP = 1 << 24 # set operation type: union MSUNION = 0 # set operation type: intersection MSISECT = 1 # set operation type: difference MSDIFF = 2 # KWIC option: mark up by tabs KWMUTAB = 1 << 0 # KWIC option: mark up by control characters KWMUCTRL = 1 << 1 # KWIC option: mark up by square brackets KWMUBRCT = 1 << 2 # KWIC option: do not overlap KWNOOVER = 1 << 24 # KWIC option: pick up the lead string KWPULEAD = 1 << 25 # Create a query object.%% # `tdb' specifies the table database object.%% # The return value is the new query object.%% def initialize(tdb) # (native code) end # Add a narrowing condition.%% # `name' specifies the name of a column. An empty string means the primary key.%% # `op' specifies an operation type: `TokyoCabinet::TDBQRY::QCSTREQ' for string which is equal to the expression, `TokyoCabinet::TDBQRY::QCSTRINC' for string which is included in the expression, `TokyoCabinet::TDBQRY::QCSTRBW' for string which begins with the expression, `TokyoCabinet::TDBQRY::QCSTREW' for string which ends with the expression, `TokyoCabinet::TDBQRY::QCSTRAND' for string which includes all tokens in the expression, `TokyoCabinet::TDBQRY::QCSTROR' for string which includes at least one token in the expression, `TokyoCabinet::TDBQRY::QCSTROREQ' for string which is equal to at least one token in the expression, `TokyoCabinet::TDBQRY::QCSTRRX' for string which matches regular expressions of the expression, `TokyoCabinet::TDBQRY::QCNUMEQ' for number which is equal to the expression, `TokyoCabinet::TDBQRY::QCNUMGT' for number which is greater than the expression, `TokyoCabinet::TDBQRY::QCNUMGE' for number which is greater than or equal to the expression, `TokyoCabinet::TDBQRY::QCNUMLT' for number which is less than the expression, `TokyoCabinet::TDBQRY::QCNUMLE' for number which is less than or equal to the expression, `TokyoCabinet::TDBQRY::QCNUMBT' for number which is between two tokens of the expression, `TokyoCabinet::TDBQRY::QCNUMOREQ' for number which is equal to at least one token in the expression, `TokyoCabinet::TDBQRY::QCFTSPH' for full-text search with the phrase of the expression, `TokyoCabinet::TDBQRY::QCFTSAND' for full-text search with all tokens in the expression, `TokyoCabinet::TDBQRY::QCFTSOR' for full-text search with at least one token in the expression, `TokyoCabinet::TDBQRY::QCFTSEX' for full-text search with the compound expression. All operations can be flagged by bitwise-or: `TokyoCabinet::TDBQRY::QCNEGATE' for negation, `TokyoCabinet::TDBQRY::QCNOIDX' for using no index.%% # `expr' specifies an operand exression.%% # The return value is always `nil'.%% def addcond(name, op, expr) # (native code) end # Set the order of the result.%% # `name' specifies the name of a column. An empty string means the primary key.%% # `type' specifies the order type: `TokyoCabinet::TDBQRY::QOSTRASC' for string ascending, `TokyoCabinet::TDBQRY::QOSTRDESC' for string descending, `TokyoCabinet::TDBQRY::QONUMASC' for number ascending, `TokyoCabinet::TDBQRY::QONUMDESC' for number descending. If it is not defined, `TokyoCabinet::TDBQRY::QOSTRASC' is specified.%% # The return value is always `nil'.%% def setorder(name, type) # (native code) end # Set the maximum number of records of the result.%% # `max' specifies the maximum number of records of the result. If it is not defined or negative, no limit is specified.%% # `skip' specifies the maximum number of records of the result. If it is not defined or not more than 0, no record is skipped.%% # The return value is always `nil'.%% def setlimit(max, skip) # (native code) end # Execute the search.%% # The return value is an array of the primary keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.%% def search() # (native code) end # Remove each corresponding record.%% # If successful, the return value is true, else, it is false.%% def searchout() # (native code) end # Process each corresponding record.%% # This method needs a block parameter of the iterator called for each record. The block receives two parameters. The first parameter is the primary key. The second parameter is a hash containing columns. It returns flags of the post treatment by bitwise-or: `TokyoCabinet::TDBQRY::QPPUT' to modify the record, `TokyoCabinet::TDBQRY::QPOUT' to remove the record, `TokyoCabinet::TDBQRY::QPSTOP' to stop the iteration.%% # If successful, the return value is true, else, it is false.%% def proc() # (native code) end # Get the hint string.%% # The return value is the hint string.%% def hint() # (native code) end # Retrieve records with multiple query objects and get the set of the result.%% # `others' specifies an array of the query objects except for the self object.%% # `type' specifies a set operation type: `TokyoCabinet::TDBQRY::MSUNION' for the union set, `TokyoCabinet::TDBQRY::MSISECT' for the intersection set, `TokyoCabinet::TDBQRY::MSDIFF' for the difference set. If it is not defined, `TokyoCabinet::TDBQRY::MSUNION' is specified.%% # The return value is an array of the primary keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.%% # If the first query object has the order setting, the result array is sorted by the order.%% def metasearch(others, type) # (native code) end # Generate keyword-in-context strings.%% # `cols' specifies a hash containing columns.%% # `name' specifies the name of a column. If it is not defined, the first column of the query is specified.%% # `width' specifies the width of strings picked up around each keyword. If it is not defined or negative, the whole text is picked up.%% # `opts' specifies options by bitwise-or: `TokyoCabinet::TDBQRY::KWMUTAB' specifies that each keyword is marked up between two tab characters, `TokyoCabinet::TDBQRY::KWMUCTRL' specifies that each keyword is marked up by the STX (0x02) code and the ETX (0x03) code, `TokyoCabinet::TDBQRY::KWMUBRCT' specifies that each keyword is marked up by the two square brackets, `TokyoCabinet::TDBQRY::KWNOOVER' specifies that each context does not overlap, `TokyoCabinet::TDBQRY::KWPULEAD' specifies that the lead string is picked up forcibly. If it is not defined, no option is specified.%% # The return value is an array of strings around keywords.%% def kwic(cols, name, width, opts) # (native code) end end # Abstract database is a set of interfaces to use on-memory hash database, on-memory tree database, hash database, B+ tree database, fixed-length database, and table database with the same API. Before operations to store or retrieve records, it is necessary to connect the abstract database object to the concrete one. The method `open' is used to open a concrete database and the method `close' is used to close the database. To avoid data missing or corruption, it is important to close every database instance when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.%% # Except for the interface below, methods compatible with the `Hash' class are also provided; `[]', `[]=', `store', `delete', `fetch', `has_key?', `has_value?', `key', `clear', `length', `empty?', `each', `each_key', `each_value', and `keys'.%% class ADB # Create an abstract database object.%% # The return value is the new abstract database object.%% def initialize() # (native code) end # Open a database.%% # `name' specifies the name of the database. If it is "*", the database will be an on-memory hash database. If it is "+", the database will be an on-memory tree database. If its suffix is ".tch", the database will be a hash database. If its suffix is ".tcb", the database will be a B+ tree database. If its suffix is ".tcf", the database will be a fixed-length database. If its suffix is ".tct", the database will be a table database. Otherwise, this method fails. Tuning parameters can trail the name, separated by "#". Each parameter is composed of the name and the value, separated by "=". On-memory hash database supports "bnum", "capnum", and "capsiz". On-memory tree database supports "capnum" and "capsiz". Hash database supports "mode", "bnum", "apow", "fpow", "opts", "rcnum", and "xmsiz". B+ tree database supports "mode", "lmemb", "nmemb", "bnum", "apow", "fpow", "opts", "lcnum", "ncnum", and "xmsiz". Fixed-length database supports "mode", "width", and "limsiz". Table database supports "mode", "bnum", "apow", "fpow", "opts", "rcnum", "lcnum", "ncnum", "xmsiz", and "idx".%% # If successful, the return value is true, else, it is false.%% # The tuning parameter "capnum" specifies the capacity number of records. "capsiz" specifies the capacity size of using memory. Records spilled the capacity are removed by the storing order. "mode" can contain "w" of writer, "r" of reader, "c" of creating, "t" of truncating, "e" of no locking, and "f" of non-blocking lock. The default mode is relevant to "wc". "opts" can contains "l" of large option, "d" of Deflate option, "b" of BZIP2 option, and "t" of TCBS option. "idx" specifies the column name of an index and its type separated by ":". For example, "casket.tch#bnum=1000000#opts=ld" means that the name of the database file is "casket.tch", and the bucket number is 1000000, and the options are large and Deflate.%% def open(name) # (native code) end # Close the database.%% # If successful, the return value is true, else, it is false.%% # Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.%% def close() # (native code) end # Store a record.%% # `key' specifies the key.%% # `value' specifies the value.%% # If successful, the return value is true, else, it is false.%% # If a record with the same key exists in the database, it is overwritten.%% def put(key, value) # (native code) end # Store a new record.%% # `key' specifies the key.%% # `value' specifies the value.%% # If successful, the return value is true, else, it is false.%% # If a record with the same key exists in the database, this method has no effect.%% def putkeep(key, value) # (native code) end # Concatenate a value at the end of the existing record.%% # `key' specifies the key.%% # `value' specifies the value.%% # If successful, the return value is true, else, it is false.%% # If there is no corresponding record, a new record is created.%% def putcat(key, value) # (native code) end # Remove a record.%% # `key' specifies the key.%% # If successful, the return value is true, else, it is false.%% def out(key) # (native code) end # Retrieve a record.%% # `key' specifies the key.%% # If successful, the return value is the value of the corresponding record. `nil' is returned if no record corresponds.%% def get(key) # (native code) end # Get the size of the value of a record.%% # `key' specifies the key.%% # If successful, the return value is the size of the value of the corresponding record, else, it is -1.%% def vsiz(key) # (native code) end # Initialize the iterator.%% # If successful, the return value is true, else, it is false.%% # The iterator is used in order to access the key of every record stored in a database.%% def iterinit() # (native code) end # Get the next key of the iterator.%% # If successful, the return value is the next key, else, it is `nil'. `nil' is returned when no record is to be get out of the iterator.%% # It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.%% def iternext() # (native code) end # Get forward matching keys.%% # `prefix' specifies the prefix of the corresponding keys.%% # `max' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.%% # The return value is a list object of the keys of the corresponding records. This method does never fail. It returns an empty list even if no record corresponds.%% # Note that this method may be very slow because every key in the database is scanned.%% def fwmkeys(prefix, max) # (native code) end # Add an integer to a record.%% # `key' specifies the key.%% # `num' specifies the additional value.%% # If successful, the return value is the summation value, else, it is `nil'.%% # If the corresponding record exists, the value is treated as an integer and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `i' operator after retrieval.%% def addint(key, num) # (native code) end # Add a real number to a record.%% # `key' specifies the key.%% # `num' specifies the additional value.%% # If successful, the return value is the summation value, else, it is `nil'.%% # If the corresponding record exists, the value is treated as a real number and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `d' operator after retrieval.%% def adddouble(key, num) # (native code) end # Synchronize updated contents with the file and the device.%% # If successful, the return value is true, else, it is false.%% # This method is useful when another process connects the same database file.%% def sync() # (native code) end # Optimize the storage.%% # `params' specifies the string of the tuning parameters, which works as with the tuning of parameters the method `open'. If it is not defined, it is not used.%% # If successful, the return value is true, else, it is false.%% def optimize(params) # (native code) end # Remove all records.%% # If successful, the return value is true, else, it is false.%% def vanish() # (native code) end # Copy the database file.%% # `path' specifies the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.%% # If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.%% # The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.%% def copy(path) # (native code) end # Begin the transaction.%% # If successful, the return value is true, else, it is false.%% # The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly.%% def tranbegin() # (native code) end # Commit the transaction.%% # If successful, the return value is true, else, it is false.%% # Update in the transaction is fixed when it is committed successfully.%% def trancommit() # (native code) end # Abort the transaction.%% # If successful, the return value is true, else, it is false.%% # Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.%% def tranabort() # (native code) end # Get the path of the database file.%% # The return value is the path of the database file or `nil' if the object does not connect to any database instance. "*" stands for on-memory hash database. "+" stands for on-memory tree database.%% def path() # (native code) end # Get the number of records.%% # The return value is the number of records or 0 if the object does not connect to any database instance.%% def rnum() # (native code) end # Get the size of the database.%% # The return value is the size of the database or 0 if the object does not connect to any database instance.%% def size() # (native code) end # Call a versatile function for miscellaneous operations.%% # `name' specifies the name of the function.%% # `args' specifies an array of arguments. If it is not defined, no argument is specified.%% # If successful, the return value is an array of the result. `nil' is returned on failure.%% def misc(name, args) # (native code) end end end tokyocabinet-ruby-1.31/tokyocabinet.gemspec0000644000175000017500000000156711547412351017340 0ustar spkspkrequire 'rubygems' spec = Gem::Specification.new do |s| s.name = "tokyocabinet" s.version = "1.31" s.author "FAL Labs" s.email = "info@fallabs.com" s.homepage = "http://fallabs.com/tokyocabinet/" s.summary = "Tokyo Cabinet: a modern implementation of DBM." s.description = "Tokyo Cabinet is a library of routines for managing a database. The database is a simple data file containing records, each is a pair of a key and a value. Every key and value is serial bytes with variable length. Both binary data and character string can be used as a key and a value. There is neither concept of data tables nor data types. Records are organized in hash table, B+ tree, or fixed-length array." s.files = [ "tokyocabinet.c", "extconf.rb" ] s.require_path = "." s.extensions = [ "extconf.rb" ] end if $0 == __FILE__ Gem::manage_gems Gem::Builder.new(spec).build end tokyocabinet-ruby-1.31/tchtest.rb0000644000175000017500000003211511547412351015274 0ustar spkspk#! /usr/bin/ruby -w #------------------------------------------------------------------------------------------------- # The test cases of the hash database API # Copyright (C) 2006-2010 FAL Labs # This file is part of Tokyo Cabinet. # Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of # the GNU Lesser General Public License as published by the Free Software Foundation; either # version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope # that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. # You should have received a copy of the GNU Lesser General Public License along with Tokyo # Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA. #------------------------------------------------------------------------------------------------- require 'tokyocabinet' include TokyoCabinet # main routine def main ARGV.length >= 1 || usage if ARGV[0] == "write" rv = runwrite elsif ARGV[0] == "read" rv = runread elsif ARGV[0] == "remove" rv = runremove elsif ARGV[0] == "misc" rv = runmisc else usage end GC.start return rv end # print the usage and exit def usage STDERR.printf("%s: test cases of the hash database API\n", $progname) STDERR.printf("\n") STDERR.printf("usage:\n") STDERR.printf(" %s write [-tl] [-td|-tb|-tt] [-nl|-nb] [-as] path rnum" + " [bnum [apow [fpow]]]\n", $progname) STDERR.printf(" %s read [-nl|-nb] path\n", $progname) STDERR.printf(" %s remove [-nl|-nb] path\n", $progname) STDERR.printf(" %s misc [-tl] [-td|-tb|-tt] [-nl|-nb] path rnum\n", $progname) STDERR.printf("\n") exit(1) end # print error message of hash database def eprint(hdb, func) path = hdb.path STDERR.printf("%s: %s: %s: %s\n", $progname, path ? path : "-", func, hdb.errmsg) end # parse arguments of write command def runwrite path = nil rnum = nil bnum = nil apow = nil fpow = nil opts = 0 omode = 0 as = false i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-tl" opts |= HDB::TLARGE elsif ARGV[i] == "-td" opts |= HDB::TDEFLATE elsif ARGV[i] == "-tb" opts |= HDB::TBZIP elsif ARGV[i] == "-tt" opts |= HDB::TTCBS elsif ARGV[i] == "-nl" omode |= HDB::ONOLCK elsif ARGV[i] == "-nb" omode |= HDB::OLCKNB elsif ARGV[i] == "-as" as = true else usage end elsif !path path = ARGV[i] elsif !rnum rnum = ARGV[i].to_i elsif !bnum bnum = ARGV[i].to_i elsif !apow apow = ARGV[i].to_i elsif !fpow fpow = ARGV[i].to_i else usage end i += 1 end usage if !path || !rnum || rnum < 1 bnum = bnum ? bnum : -1 apow = apow ? apow : -1 fpow = fpow ? fpow : -1 rv = procwrite(path, rnum, bnum, apow, fpow, opts, omode, as) return rv end # parse arguments of read command def runread path = nil omode = 0 i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-nl" omode |= HDB::ONOLCK elsif ARGV[i] == "-nb" omode |= HDB::OLCKNB else usage end elsif !path path = ARGV[i] else usage end i += 1 end usage if !path rv = procread(path, omode) return rv end # parse arguments of remove command def runremove path = nil omode = 0 i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-nl" omode |= HDB::ONOLCK elsif ARGV[i] == "-nb" omode |= HDB::OLCKNB else usage end elsif !path path = ARGV[i] else usage end i += 1 end usage if !path rv = procremove(path, omode) return rv end # parse arguments of misc command def runmisc path = nil rnum = nil opts = 0 omode = 0 i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-tl" opts |= HDB::TLARGE elsif ARGV[i] == "-td" opts |= HDB::TDEFLATE elsif ARGV[i] == "-tb" opts |= HDB::TBZIP elsif ARGV[i] == "-tt" opts |= HDB::TTCBS elsif ARGV[i] == "-nl" omode |= HDB::ONOLCK elsif ARGV[i] == "-nb" omode |= HDB::OLCKNB else usage end elsif !path path = ARGV[i] elsif !rnum rnum = ARGV[i].to_i else usage end i += 1 end usage if !path || !rnum || rnum < 1 rv = procmisc(path, rnum, opts, omode) return rv end # perform write command def procwrite(path, rnum, bnum, apow, fpow, opts, omode, as) printf("\n path=%s rnum=%d bnum=%d apow=%d fpow=%d opts=%d" + " omode=%d as=%s\n\n", path, rnum, bnum, apow, fpow, opts, omode, as) err = false stime = Time.now hdb = HDB::new if !hdb.tune(bnum, apow, fpow, opts) eprint(hdb, "tune") err = true end if !hdb.open(path, HDB::OWRITER | HDB::OCREAT | HDB::OTRUNC | omode) eprint(hdb, "open") err = true end for i in 1..rnum buf = sprintf("%08d", i) if as if !hdb.putasync(buf, buf) eprint(hdb, "putasync") err = true break end else if !hdb.put(buf, buf) eprint(hdb, "put") err = true break end end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("record number: %d\n", hdb.rnum) printf("size: %d\n", hdb.fsiz) if !hdb.close eprint(hdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # perform read command def procread(path, omode) printf("\n path=%s omode=%d\n\n", path, omode) err = false stime = Time.now hdb = HDB::new if !hdb.open(path, HDB::OREADER | omode) eprint(hdb, "open") err = true end rnum = hdb.rnum for i in 1..rnum buf = sprintf("%08d", i) if !hdb.get(buf) eprint(hdb, "get") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("record number: %d\n", hdb.rnum) printf("size: %d\n", hdb.fsiz) if !hdb.close eprint(hdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # perform remove command def procremove(path, omode) printf("\n path=%s omode=%d\n\n", path, omode) err = false stime = Time.now hdb = HDB::new if !hdb.open(path, HDB::OWRITER | omode) eprint(hdb, "open") err = true end rnum = hdb.rnum for i in 1..rnum buf = sprintf("%08d", i) if !hdb.out(buf) eprint(hdb, "out") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("record number: %d\n", hdb.rnum) printf("size: %d\n", hdb.fsiz) if !hdb.close eprint(hdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # perform misc command def procmisc(path, rnum, opts, omode) printf("\n path=%s rnum=%d opts=%d omode=%d\n\n", path, rnum, opts, omode) err = false stime = Time.now hdb = HDB::new if !hdb.tune(rnum / 50, 2, -1, opts) eprint(hdb, "tune") err = true end if !hdb.setcache(rnum / 10) eprint(hdb, "setcache") err = true end if !hdb.setxmsiz(rnum * 4) eprint(hdb, "setxmsiz") err = true end if !hdb.setdfunit(8) eprint(hdb, "setdfunit") err = true end if !hdb.open(path, HDB::OWRITER | HDB::OCREAT | HDB::OTRUNC | omode) eprint(hdb, "open") err = true end printf("writing:\n") for i in 1..rnum buf = sprintf("%08d", i) if !hdb.put(buf, buf) eprint(hdb, "put") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("reading:\n") for i in 1..rnum buf = sprintf("%08d", i) if !hdb.get(buf) eprint(hdb, "get") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("removing:\n") for i in 1..rnum buf = sprintf("%08d", i) if rand(2) == 0 && !hdb.out(buf) eprint(hdb, "out") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("checking iterator:\n") if !hdb.iterinit eprint(hdb, "iterinit") err = true end inum = 0 while key = hdb.iternext value = hdb.get(key) if !value eprint(hdb, "get") err = true end if inum > 0 && rnum > 250 && inum % (rnum / 250) == 0 print('.') if inum == rnum || inum % (rnum / 10) == 0 printf(" (%08d)\n", inum) end end inum += 1 end printf(" (%08d)\n", inum) if rnum > 250 if hdb.ecode != HDB::ENOREC || inum != hdb.rnum eprint(hdb, "(validation)") err = true end keys = hdb.fwmkeys("0", 10) if hdb.rnum >= 10 && keys.size != 10 eprint(hdb, "fwmkeys") err = true end printf("checking counting:\n") for i in 1..rnum buf = sprintf("[%d]", rand(rnum)) if rand(2) == 0 if !hdb.addint(buf, 1) && hdb.ecode != HDB::EKEEP eprint(hdb, "addint") err = true break end else if !hdb.adddouble(buf, 1) && hdb.ecode != HDB::EKEEP eprint(hdb, "adddouble") err = true break end end if i > 0 && rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end if !hdb.sync eprint(hdb, "sync") err = true end if !hdb.optimize eprint(hdb, "optimize") err = true end npath = path + "-tmp" if !hdb.copy(npath) eprint(hdb, "copy") err = true end File::unlink(npath) if !hdb.vanish eprint(hdb, "vanish") err = true end printf("checking transaction commit:\n") if !hdb.tranbegin eprint(hdb, "tranbegin") err = true end for i in 1..rnum buf = sprintf("%d", rand(rnum)) if rand(2) == 0 if !hdb.putcat(buf, buf) eprint(hdb, "putcat") err = true break end else if !hdb.out(buf) && hdb.ecode != HDB::ENOREC eprint(hdb, "out") err = true break end end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end if !hdb.trancommit eprint(hdb, "trancommit") err = true end printf("checking transaction abort:\n") ornum = hdb.rnum ofsiz = hdb.fsiz if !hdb.tranbegin eprint(hdb, "tranbegin") err = true end for i in 1..rnum buf = sprintf("%d", rand(rnum)) if rand(2) == 0 if !hdb.putcat(buf, buf) eprint(hdb, "putcat") err = true break end else if !hdb.out(buf) && hdb.ecode != HDB::ENOREC eprint(hdb, "out") err = true break end end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end if !hdb.tranabort eprint(hdb, "trancommit") err = true end if hdb.rnum != ornum || hdb.fsiz != ofsiz eprint(hdb, "(validation)") err = true end printf("checking hash-like updating:\n") for i in 1..rnum buf = sprintf("[%d]", rand(rnum)) rnd = rand(4) if rnd == 0 hdb[buf] = buf elsif rnd == 1 value = hdb[buf] elsif rnd == 2 res = hdb.key?(buf) elsif rnd == 3 hdb.delete(buf) end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("checking hash-like iterator:\n") inum = 0 hdb.each do |tkey, tvalue| if inum > 0 && rnum > 250 && inum % (rnum / 250) == 0 print('.') if inum == rnum || inum % (rnum / 10) == 0 printf(" (%08d)\n", inum) end end inum += 1 end printf(" (%08d)\n", inum) if rnum > 250 hdb.clear printf("record number: %d\n", hdb.rnum) printf("size: %d\n", hdb.fsiz) if !hdb.close eprint(hdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # execute main STDOUT.sync = true $progname = $0.dup $progname.gsub!(/.*\//, "") srand exit(main) # END OF FILE tokyocabinet-ruby-1.31/doc/0000755000175000017500000000000011547412351014034 5ustar spkspktokyocabinet-ruby-1.31/doc/files/0000755000175000017500000000000011547412351015136 5ustar spkspktokyocabinet-ruby-1.31/doc/files/tokyocabinet-doc_rb.html0000644000175000017500000002755711547412351021765 0ustar spkspk File: tokyocabinet-doc.rb [Tokyo Cabinet]

tokyocabinet-doc.rb

Path: tokyocabinet-doc.rb
Last Update: 2010-07-19 15:13:07 +0900

Ruby Binding of Tokyo Cabinet

Tokyo Cabinet: a modern implementation of DBM

INTRODUCTION

Tokyo Cabinet is a library of routines for managing a database. The database is a simple data file containing records, each is a pair of a key and a value. Every key and value is serial bytes with variable length. Both binary data and character string can be used as a key and a value. There is neither concept of data tables nor data types. Records are organized in hash table, B+ tree, or fixed-length array.

As for database of hash table, each key must be unique within a database, so it is impossible to store two or more records with a key overlaps. The following access methods are provided to the database: storing a record with a key and a value, deleting a record by a key, retrieving a record by a key. Moreover, traversal access to every key are provided, although the order is arbitrary. These access methods are similar to ones of DBM (or its followers: NDBM and GDBM) library defined in the UNIX standard. Tokyo Cabinet is an alternative for DBM because of its higher performance.

As for database of B+ tree, records whose keys are duplicated can be stored. Access methods of storing, deleting, and retrieving are provided as with the database of hash table. Records are stored in order by a comparison function assigned by a user. It is possible to access each record with the cursor in ascending or descending order. According to this mechanism, forward matching search for strings and range search for integers are realized.

As for database of fixed-length array, records are stored with unique natural numbers. It is impossible to store two or more records with a key overlaps. Moreover, the length of each record is limited by the specified length. Provided operations are the same as ones of hash database.

Table database is also provided as a variant of hash database. Each record is identified by the primary key and has a set of named columns. Although there is no concept of data schema, it is possible to search for records with complex conditions efficiently by using indices of arbitrary columns.

Setting

Install the latest version of Tokyo Cabinet beforehand and get the package of the Ruby binding of Tokyo Cabinet.

Enter the directory of the extracted package then perform installation.

 ruby extconf.rb
 make
 su
 make install

The package `tokyocabinet' should be loaded in each source file of application programs.

 require 'tokyocabinet'

All symbols of Tokyo Cabinet are defined in the module `TokyoCabinet'. You can access them without any prefix by including the module.

 include TokyoCabinet

EXAMPLE

The following code is an example to use a hash database.

 require 'tokyocabinet'
 include TokyoCabinet

 # create the object
 hdb = HDB::new

 # open the database
 if !hdb.open("casket.tch", HDB::OWRITER | HDB::OCREAT)
   ecode = hdb.ecode
   STDERR.printf("open error: %s\n", hdb.errmsg(ecode))
 end

 # store records
 if !hdb.put("foo", "hop") ||
     !hdb.put("bar", "step") ||
     !hdb.put("baz", "jump")
   ecode = hdb.ecode
   STDERR.printf("put error: %s\n", hdb.errmsg(ecode))
 end

 # retrieve records
 value = hdb.get("foo")
 if value
   printf("%s\n", value)
 else
   ecode = hdb.ecode
   STDERR.printf("get error: %s\n", hdb.errmsg(ecode))
 end

 # traverse records
 hdb.iterinit
 while key = hdb.iternext
   value = hdb.get(key)
   if value
     printf("%s:%s\n", key, value)
   end
 end

 # hash-like usage
 hdb["quux"] = "touchdown"
 printf("%s\n", hdb["quux"])
 hdb.each do |key, value|
   printf("%s:%s\n", key, value)
 end

 # close the database
 if !hdb.close
   ecode = hdb.ecode
   STDERR.printf("close error: %s\n", hdb.errmsg(ecode))
 end

The following code is an example to use a B+ tree database.

 require 'tokyocabinet'
 include TokyoCabinet

 # create the object
 bdb = BDB::new

 # open the database
 if !bdb.open("casket.tcb", BDB::OWRITER | BDB::OCREAT)
   ecode = bdb.ecode
   STDERR.printf("open error: %s\n", bdb.errmsg(ecode))
 end

 # store records
 if !bdb.put("foo", "hop") ||
     !bdb.put("bar", "step") ||
     !bdb.put("baz", "jump")
   ecode = bdb.ecode
   STDERR.printf("put error: %s\n", bdb.errmsg(ecode))
 end

 # retrieve records
 value = bdb.get("foo")
 if value
   printf("%s\n", value)
 else
   ecode = bdb.ecode
   STDERR.printf("get error: %s\n", bdb.errmsg(ecode))
 end

 # traverse records
 cur = BDBCUR::new(bdb)
 cur.first
 while key = cur.key
   value = cur.val
   if value
     printf("%s:%s\n", key, value)
   end
   cur.next
 end

 # hash-like usage
 bdb["quux"] = "touchdown"
 printf("%s\n", bdb["quux"])
 bdb.each do |key, value|
   printf("%s:%s\n", key, value)
 end

 # close the database
 if !bdb.close
   ecode = bdb.ecode
   STDERR.printf("close error: %s\n", bdb.errmsg(ecode))
 end

The following code is an example to use a fixed-length database.

 require 'tokyocabinet'
 include TokyoCabinet

 # create the object
 fdb = FDB::new

 # open the database
 if !fdb.open("casket.tcf", FDB::OWRITER | FDB::OCREAT)
   ecode = fdb.ecode
   STDERR.printf("open error: %s\n", fdb.errmsg(ecode))
 end

 # store records
 if !fdb.put(1, "one") ||
     !fdb.put(12, "twelve") ||
     !fdb.put(144, "one forty four")
   ecode = fdb.ecode
   STDERR.printf("put error: %s\n", fdb.errmsg(ecode))
 end

 # retrieve records
 value = fdb.get(1)
 if value
   printf("%s\n", value)
 else
   ecode = fdb.ecode
   STDERR.printf("get error: %s\n", fdb.errmsg(ecode))
 end

 # traverse records
 fdb.iterinit
 while key = fdb.iternext
   value = fdb.get(key)
   if value
     printf("%s:%s\n", key, value)
   end
 end

 # hash-like usage
 fdb[1728] = "seventeen twenty eight"
 printf("%s\n", fdb[1728])
 fdb.each do |key, value|
   printf("%s:%s\n", key, value)
 end

 # close the database
 if !fdb.close
   ecode = fdb.ecode
   STDERR.printf("close error: %s\n", fdb.errmsg(ecode))
 end

The following code is an example to use a table database.

 require 'tokyocabinet'
 include TokyoCabinet

 # create the object
 tdb = TDB::new

 # open the database
 if !tdb.open("casket.tct", TDB::OWRITER | TDB::OCREAT)
   ecode = tdb.ecode
   STDERR.printf("open error: %s\n", tdb.errmsg(ecode))
 end

 # store a record
 pkey = tdb.genuid
 cols = { "name" => "mikio", "age" => "30", "lang" => "ja,en,c" }
 if !tdb.put(pkey, cols)
   ecode = tdb.ecode
   STDERR.printf("get error: %s\n", tdb.errmsg(ecode))
 end

 # store another record
 cols = { "name" => "falcon", "age" => "31", "lang" => "ja", "skill" => "cook,blog" }
 if !tdb.put("x12345", cols)
   ecode = tdb.ecode
   STDERR.printf("get error: %s\n", tdb.errmsg(ecode))
 end

 # search for records
 qry = TDBQRY::new(tdb)
 qry.addcond("age", TDBQRY::QCNUMGE, "20")
 qry.addcond("lang", TDBQRY::QCSTROR, "ja,en")
 qry.setorder("name", TDBQRY::QOSTRASC)
 qry.setlimit(10)
 res = qry.search
 res.each do |rkey|
   rcols = tdb.get(rkey)
   printf("name:%s\n", rcols["name"])
 end

 # hash-like usage
 tdb["joker"] = { "name" => "ozma", "lang" => "en", "skill" => "song,dance" }
 printf("%s\n", tdb["joker"]["name"])
 tdb.each do |key, value|
   printf("%s:%s\n", key, value["name"])
 end

 # close the database
 if !tdb.close
   ecode = tdb.ecode
   STDERR.printf("close error: %s\n", tdb.errmsg(ecode))
 end

The following code is an example to use an abstract database.

 require 'tokyocabinet'
 include TokyoCabinet

 # create the object
 adb = ADB::new

 # open the database
 if !adb.open("casket.tch")
   STDERR.printf("open error\n")
 end

 # store records
 if !adb.put("foo", "hop") ||
     !adb.put("bar", "step") ||
     !adb.put("baz", "jump")
   STDERR.printf("put error\n")
 end

 # retrieve records
 value = adb.get("foo")
 if value
   printf("%s\n", value)
 else
   STDERR.printf("get error\n")
 end

 # traverse records
 adb.iterinit
 while key = adb.iternext
   value = adb.get(key)
   if value
     printf("%s:%s\n", key, value)
   end
 end

 # hash-like usage
 adb["quux"] = "touchdown"
 printf("%s\n", adb["quux"])
 adb.each do |key, value|
   printf("%s:%s\n", key, value)
 end

 # close the database
 if !adb.close
   STDERR.printf("close error\n")
 end

LICENSE

 Copyright (C) 2006-2010 FAL Labs
 All rights reserved.

Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Tokyo Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

tokyocabinet-ruby-1.31/doc/classes/0000755000175000017500000000000011547412351015471 5ustar spkspktokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/0000755000175000017500000000000011547412351020064 5ustar spkspktokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/0000755000175000017500000000000011547412351021263 5ustar spkspktokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000128.html0000644000175000017500000000134311547412351023021 0ustar spkspk tranbegin (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1191
    def tranbegin()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000133.html0000644000175000017500000000133111547412351023012 0ustar spkspk fsiz (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1218
    def fsiz()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000109.html0000644000175000017500000000141311547412351023016 0ustar spkspk setxmsiz (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1059
    def setxmsiz(xmsiz)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000106.html0000644000175000017500000000133311547412351023014 0ustar spkspk ecode (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1034
    def ecode()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000132.html0000644000175000017500000000133111547412351023011 0ustar spkspk rnum (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1213
    def rnum()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000123.html0000644000175000017500000000146611547412351023022 0ustar spkspk adddouble (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1157
    def adddouble(pkey, num)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000108.html0000644000175000017500000000154311547412351023021 0ustar spkspk setcache (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1052
    def setcache(rcnum, lcnum, ncnum)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000115.html0000644000175000017500000000146211547412351023017 0ustar spkspk putcat (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1103
    def putcat(pkey, value)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000134.html0000644000175000017500000000146511547412351023023 0ustar spkspk setindex (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1225
    def setindex(name, type)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000116.html0000644000175000017500000000140011547412351023010 0ustar spkspk out (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1109
    def out(pkey)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000107.html0000644000175000017500000000160311547412351023015 0ustar spkspk tune (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1043
    def tune(bnum, apow, fpow, opts)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000127.html0000644000175000017500000000140211547412351023014 0ustar spkspk copy (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1185
    def copy(path)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000104.html0000644000175000017500000000133611547412351023015 0ustar spkspk new (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1022
    def initialize()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000111.html0000644000175000017500000000145611547412351023016 0ustar spkspk open (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1073
    def open(path, omode)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000110.html0000644000175000017500000000141611547412351023011 0ustar spkspk setdfunit (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1066
    def setdfunit(dfunit)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000135.html0000644000175000017500000000133511547412351023020 0ustar spkspk genuid (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1230
    def genuid()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000122.html0000644000175000017500000000146011547412351023013 0ustar spkspk addint (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1149
    def addint(pkey, num)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000120.html0000644000175000017500000000134111547412351023007 0ustar spkspk iternext (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1133
    def iternext()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000117.html0000644000175000017500000000140011547412351023011 0ustar spkspk get (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1115
    def get(pkey)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000131.html0000644000175000017500000000133111547412351023010 0ustar spkspk path (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1208
    def path()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000125.html0000644000175000017500000000161311547412351023016 0ustar spkspk optimize (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1173
    def optimize(bnum, apow, fpow, opts)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000130.html0000644000175000017500000000134311547412351023012 0ustar spkspk tranabort (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1203
    def tranabort()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000126.html0000644000175000017500000000133511547412351023020 0ustar spkspk vanish (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1178
    def vanish()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000114.html0000644000175000017500000000146311547412351023017 0ustar spkspk putkeep (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1095
    def putkeep(pkey, cols)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000113.html0000644000175000017500000000145311547412351023015 0ustar spkspk put (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1087
    def put(pkey, cols)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000129.html0000644000175000017500000000134511547412351023024 0ustar spkspk trancommit (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1197
    def trancommit()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000118.html0000644000175000017500000000140211547412351023014 0ustar spkspk vsiz (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1121
    def vsiz(pkey)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000105.html0000644000175000017500000000140711547412351023015 0ustar spkspk errmsg (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1028
    def errmsg(ecode)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000119.html0000644000175000017500000000134111547412351023017 0ustar spkspk iterinit (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1127
    def iterinit()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000121.html0000644000175000017500000000146411547412351023016 0ustar spkspk fwmkeys (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1141
    def fwmkeys(prefix, max)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000112.html0000644000175000017500000000133311547412351023011 0ustar spkspk close (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1079
    def close()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.src/M000124.html0000644000175000017500000000133111547412351023012 0ustar spkspk sync (TokyoCabinet::TDB)
# File tokyocabinet-doc.rb, line 1163
    def sync()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/0000755000175000017500000000000011547412351021247 5ustar spkspktokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000015.html0000644000175000017500000000137611547412351023006 0ustar spkspk get (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 195
    def get(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000006.html0000644000175000017500000000141211547412351022775 0ustar spkspk setxmsiz (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 131
    def setxmsiz(xmsiz)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000007.html0000644000175000017500000000141511547412351023001 0ustar spkspk setdfunit (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 138
    def setdfunit(dfunit)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000029.html0000644000175000017500000000133011547412351023001 0ustar spkspk path (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 288
    def path()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000009.html0000644000175000017500000000133211547412351023001 0ustar spkspk close (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 151
    def close()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000026.html0000644000175000017500000000134211547412351023001 0ustar spkspk tranbegin (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 271
    def tranbegin()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000010.html0000644000175000017500000000145211547412351022774 0ustar spkspk put (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 159
    def put(key, value)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000027.html0000644000175000017500000000134411547412351023004 0ustar spkspk trancommit (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 277
    def trancommit()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000008.html0000644000175000017500000000145511547412351023006 0ustar spkspk open (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 145
    def open(path, omode)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000004.html0000644000175000017500000000160211547412351022774 0ustar spkspk tune (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 117
    def tune(bnum, apow, fpow, opts)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000018.html0000644000175000017500000000134011547412351023000 0ustar spkspk iternext (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 213
    def iternext()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000020.html0000644000175000017500000000145611547412351023001 0ustar spkspk addint (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 229
    def addint(key, num)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000024.html0000644000175000017500000000133411547412351023000 0ustar spkspk vanish (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 258
    def vanish()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000017.html0000644000175000017500000000134011547412351022777 0ustar spkspk iterinit (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 207
    def iterinit()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000028.html0000644000175000017500000000134211547412351023003 0ustar spkspk tranabort (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 283
    def tranabort()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000025.html0000644000175000017500000000140111547412351022774 0ustar spkspk copy (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 265
    def copy(path)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000005.html0000644000175000017500000000141211547412351022774 0ustar spkspk setcache (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 124
    def setcache(rcnum)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000002.html0000644000175000017500000000140611547412351022774 0ustar spkspk errmsg (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 102
    def errmsg(ecode)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000022.html0000644000175000017500000000133011547412351022772 0ustar spkspk sync (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 243
    def sync()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000003.html0000644000175000017500000000133211547412351022773 0ustar spkspk ecode (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 108
    def ecode()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000011.html0000644000175000017500000000146211547412351022776 0ustar spkspk putkeep (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 167
    def putkeep(key, value)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000019.html0000644000175000017500000000146311547412351023007 0ustar spkspk fwmkeys (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 221
    def fwmkeys(prefix, max)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000012.html0000644000175000017500000000146011547412351022775 0ustar spkspk putcat (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 175
    def putcat(key, value)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000014.html0000644000175000017500000000137611547412351023005 0ustar spkspk out (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 189
    def out(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000021.html0000644000175000017500000000146411547412351023001 0ustar spkspk adddouble (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 237
    def adddouble(key, num)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000001.html0000644000175000017500000000133411547412351022773 0ustar spkspk new (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 96
    def initialize()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000023.html0000644000175000017500000000161211547412351022776 0ustar spkspk optimize (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 253
    def optimize(bnum, apow, fpow, opts)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000030.html0000644000175000017500000000133011547412351022771 0ustar spkspk rnum (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 293
    def rnum()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000013.html0000644000175000017500000000146411547412351023002 0ustar spkspk putasync (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 183
    def putasync(key, value)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000016.html0000644000175000017500000000140011547412351022773 0ustar spkspk vsiz (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 201
    def vsiz(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.src/M000031.html0000644000175000017500000000133011547412351022772 0ustar spkspk fsiz (TokyoCabinet::HDB)
# File tokyocabinet-doc.rb, line 298
    def fsiz()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDBCUR.src/0000755000175000017500000000000011547412351021613 5ustar spkspktokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDBCUR.src/M000070.html0000644000175000017500000000140311547412351023342 0ustar spkspk jump (TokyoCabinet::BDBCUR)
# File tokyocabinet-doc.rb, line 659
    def jump(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDBCUR.src/M000072.html0000644000175000017500000000133311547412351023346 0ustar spkspk next (TokyoCabinet::BDBCUR)
# File tokyocabinet-doc.rb, line 669
    def next()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDBCUR.src/M000069.html0000644000175000017500000000133311547412351023354 0ustar spkspk last (TokyoCabinet::BDBCUR)
# File tokyocabinet-doc.rb, line 652
    def last()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDBCUR.src/M000076.html0000644000175000017500000000133111547412351023350 0ustar spkspk val (TokyoCabinet::BDBCUR)
# File tokyocabinet-doc.rb, line 693
    def val()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDBCUR.src/M000067.html0000644000175000017500000000141011547412351023346 0ustar spkspk new (TokyoCabinet::BDBCUR)
# File tokyocabinet-doc.rb, line 642
    def initialize(bdb)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDBCUR.src/M000071.html0000644000175000017500000000133311547412351023345 0ustar spkspk prev (TokyoCabinet::BDBCUR)
# File tokyocabinet-doc.rb, line 664
    def prev()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDBCUR.src/M000073.html0000644000175000017500000000146011547412351023350 0ustar spkspk put (TokyoCabinet::BDBCUR)
# File tokyocabinet-doc.rb, line 677
    def put(value, cpmode)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDBCUR.src/M000074.html0000644000175000017500000000133111547412351023346 0ustar spkspk out (TokyoCabinet::BDBCUR)
# File tokyocabinet-doc.rb, line 683
    def out()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDBCUR.src/M000075.html0000644000175000017500000000133111547412351023347 0ustar spkspk key (TokyoCabinet::BDBCUR)
# File tokyocabinet-doc.rb, line 688
    def key()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDBCUR.src/M000068.html0000644000175000017500000000133511547412351023355 0ustar spkspk first (TokyoCabinet::BDBCUR)
# File tokyocabinet-doc.rb, line 647
    def first()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDBQRY.html0000644000175000017500000006071511547412351021770 0ustar spkspk Class: TokyoCabinet::TDBQRY [Tokyo Cabinet]
Class TokyoCabinet::TDBQRY
In: tokyocabinet-doc.rb
Parent: Object

Query is a mechanism to search for and retrieve records corresponding conditions from table database.

Methods

addcond   hint   kwic   metasearch   new   proc   search   searchout   setlimit   setorder  

Constants

QCSTREQ = 0   query condition: string is equal to
QCSTRINC = 1   query condition: string is included in
QCSTRBW = 2   query condition: string begins with
QCSTREW = 3   query condition: string ends with
QCSTRAND = 4   query condition: string includes all tokens in
QCSTROR = 5   query condition: string includes at least one token in
QCSTROREQ = 6   query condition: string is equal to at least one token in
QCSTRRX = 7   query condition: string matches regular expressions of
QCNUMEQ = 8   query condition: number is equal to
QCNUMGT = 9   query condition: number is greater than
QCNUMGE = 10   query condition: number is greater than or equal to
QCNUMLT = 11   query condition: number is less than
QCNUMLE = 12   query condition: number is less than or equal to
QCNUMBT = 13   query condition: number is between two tokens of
QCNUMOREQ = 14   query condition: number is equal to at least one token in
QCFTSPH = 15   query condition: full-text search with the phrase of
QCFTSAND = 16   query condition: full-text search with all tokens in
QCFTSOR = 17   query condition: full-text search with at least one token in
QCFTSEX = 18   query condition: full-text search with the compound expression of
QCNEGATE = 1 << 24   query condition: negation flag
QCNOIDX = 1 << 25   query condition: no index flag
QOSTRASC = 1   order type: string ascending
QOSTRDESC = 2   order type: string descending
QONUMASC = 3   order type: number ascending
QONUMDESC = 4   order type: number descending
QPPUT = 1 << 0   post treatment: modify the record
QPOUT = 1 << 1   post treatment: remove the record
QPSTOP = 1 << 24   post treatment: stop the iteration
MSUNION = 0   set operation type: union
MSISECT = 1   set operation type: intersection
MSDIFF = 2   set operation type: difference
KWMUTAB = 1 << 0   KWIC option: mark up by tabs
KWMUCTRL = 1 << 1   KWIC option: mark up by control characters
KWMUBRCT = 1 << 2   KWIC option: mark up by square brackets
KWNOOVER = 1 << 24   KWIC option: do not overlap
KWPULEAD = 1 << 25   KWIC option: pick up the lead string

Public Class methods

Create a query object.
`tdb' specifies the table database object.
The return value is the new query object.

Public Instance methods

Add a narrowing condition.
`name' specifies the name of a column. An empty string means the primary key.
`op' specifies an operation type: `TokyoCabinet::TDBQRY::QCSTREQ' for string which is equal to the expression, `TokyoCabinet::TDBQRY::QCSTRINC' for string which is included in the expression, `TokyoCabinet::TDBQRY::QCSTRBW' for string which begins with the expression, `TokyoCabinet::TDBQRY::QCSTREW' for string which ends with the expression, `TokyoCabinet::TDBQRY::QCSTRAND' for string which includes all tokens in the expression, `TokyoCabinet::TDBQRY::QCSTROR' for string which includes at least one token in the expression, `TokyoCabinet::TDBQRY::QCSTROREQ' for string which is equal to at least one token in the expression, `TokyoCabinet::TDBQRY::QCSTRRX' for string which matches regular expressions of the expression, `TokyoCabinet::TDBQRY::QCNUMEQ' for number which is equal to the expression, `TokyoCabinet::TDBQRY::QCNUMGT' for number which is greater than the expression, `TokyoCabinet::TDBQRY::QCNUMGE' for number which is greater than or equal to the expression, `TokyoCabinet::TDBQRY::QCNUMLT' for number which is less than the expression, `TokyoCabinet::TDBQRY::QCNUMLE' for number which is less than or equal to the expression, `TokyoCabinet::TDBQRY::QCNUMBT' for number which is between two tokens of the expression, `TokyoCabinet::TDBQRY::QCNUMOREQ' for number which is equal to at least one token in the expression, `TokyoCabinet::TDBQRY::QCFTSPH' for full-text search with the phrase of the expression, `TokyoCabinet::TDBQRY::QCFTSAND' for full-text search with all tokens in the expression, `TokyoCabinet::TDBQRY::QCFTSOR' for full-text search with at least one token in the expression, `TokyoCabinet::TDBQRY::QCFTSEX' for full-text search with the compound expression. All operations can be flagged by bitwise-or: `TokyoCabinet::TDBQRY::QCNEGATE' for negation, `TokyoCabinet::TDBQRY::QCNOIDX' for using no index.
`expr' specifies an operand exression.
The return value is always `nil'.

Get the hint string.
The return value is the hint string.

Generate keyword-in-context strings.
`cols' specifies a hash containing columns.
`name' specifies the name of a column. If it is not defined, the first column of the query is specified.
`width' specifies the width of strings picked up around each keyword. If it is not defined or negative, the whole text is picked up.
`opts' specifies options by bitwise-or: `TokyoCabinet::TDBQRY::KWMUTAB' specifies that each keyword is marked up between two tab characters, `TokyoCabinet::TDBQRY::KWMUCTRL' specifies that each keyword is marked up by the STX (0x02) code and the ETX (0x03) code, `TokyoCabinet::TDBQRY::KWMUBRCT' specifies that each keyword is marked up by the two square brackets, `TokyoCabinet::TDBQRY::KWNOOVER' specifies that each context does not overlap, `TokyoCabinet::TDBQRY::KWPULEAD' specifies that the lead string is picked up forcibly. If it is not defined, no option is specified.
The return value is an array of strings around keywords.

Retrieve records with multiple query objects and get the set of the result.
`others' specifies an array of the query objects except for the self object.
`type' specifies a set operation type: `TokyoCabinet::TDBQRY::MSUNION' for the union set, `TokyoCabinet::TDBQRY::MSISECT' for the intersection set, `TokyoCabinet::TDBQRY::MSDIFF' for the difference set. If it is not defined, `TokyoCabinet::TDBQRY::MSUNION' is specified.
The return value is an array of the primary keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.
If the first query object has the order setting, the result array is sorted by the order.

Process each corresponding record.
This method needs a block parameter of the iterator called for each record. The block receives two parameters. The first parameter is the primary key. The second parameter is a hash containing columns. It returns flags of the post treatment by bitwise-or: `TokyoCabinet::TDBQRY::QPPUT' to modify the record, `TokyoCabinet::TDBQRY::QPOUT' to remove the record, `TokyoCabinet::TDBQRY::QPSTOP' to stop the iteration.
If successful, the return value is true, else, it is false.

Execute the search.
The return value is an array of the primary keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.

Remove each corresponding record.
If successful, the return value is true, else, it is false.

Set the maximum number of records of the result.
`max' specifies the maximum number of records of the result. If it is not defined or negative, no limit is specified.
`skip' specifies the maximum number of records of the result. If it is not defined or not more than 0, no record is skipped.
The return value is always `nil'.

Set the order of the result.
`name' specifies the name of a column. An empty string means the primary key.
`type' specifies the order type: `TokyoCabinet::TDBQRY::QOSTRASC' for string ascending, `TokyoCabinet::TDBQRY::QOSTRDESC' for string descending, `TokyoCabinet::TDBQRY::QONUMASC' for number ascending, `TokyoCabinet::TDBQRY::QONUMDESC' for number descending. If it is not defined, `TokyoCabinet::TDBQRY::QOSTRASC' is specified.
The return value is always `nil'.

tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.html0000644000175000017500000011315211547412351021350 0ustar spkspk Class: TokyoCabinet::FDB [Tokyo Cabinet]
Class TokyoCabinet::FDB
In: tokyocabinet-doc.rb
Parent: Object

Fixed-Length database is a file containing a fixed-length table and is handled with the fixed-length database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the fixed-length database object to it. To avoid data missing or corruption, it is important to close every database file when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.
Except for the interface below, methods compatible with the `Hash' class are also provided; `[]', `[]=', `store', `delete', `fetch', `has_key?', `has_value?', `key', `clear', `length', `empty?', `each', `each_key', `each_value', and `keys'.

Methods

adddouble   addint   close   copy   ecode   errmsg   fsiz   get   iterinit   iternext   new   open   optimize   out   path   put   putcat   putkeep   range   rnum   sync   tranabort   tranbegin   trancommit   tune   vanish   vsiz  

Constants

ESUCCESS = 0   error code: success
ETHREAD = 1   error code: threading error
EINVALID = 2   error code: invalid operation
ENOFILE = 3   error code: file not found
ENOPERM = 4   error code: no permission
EMETA = 5   error code: invalid meta data
ERHEAD = 6   error code: invalid record header
EOPEN = 7   error code: open error
ECLOSE = 8   error code: close error
ETRUNC = 9   error code: trunc error
ESYNC = 10   error code: sync error
ESTAT = 11   error code: stat error
ESEEK = 12   error code: seek error
EREAD = 13   error code: read error
EWRITE = 14   error code: write error
EMMAP = 15   error code: mmap error
ELOCK = 16   error code: lock error
EUNLINK = 17   error code: unlink error
ERENAME = 18   error code: rename error
EMKDIR = 19   error code: mkdir error
ERMDIR = 20   error code: rmdir error
EKEEP = 21   error code: existing record
ENOREC = 22   error code: no record found
EMISC = 9999   error code: miscellaneous error
OREADER = 1 << 0   open mode: open as a reader
OWRITER = 1 << 1   open mode: open as a writer
OCREAT = 1 << 2   open mode: writer creating
OTRUNC = 1 << 3   open mode: writer truncating
ONOLCK = 1 << 4   open mode: open without locking
OLCKNB = 1 << 5   open mode: lock without blocking

Public Class methods

Create a fixed-length database object.
The return value is the new fixed-length database object.

Public Instance methods

Add a real number to a record.
`key' specifies the key. It should be more than 0. If it is “min”, the minimum ID number of existing records is specified. If it is “prev”, the number less by one than the minimum ID number of existing records is specified. If it is “max”, the maximum ID number of existing records is specified. If it is “next”, the number greater by one than the maximum ID number of existing records is specified.
`num' specifies the additional value.
If successful, the return value is the summation value, else, it is `nil'.
If the corresponding record exists, the value is treated as a real number and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `d' operator after retrieval.

Add an integer to a record.
`key' specifies the key. It should be more than 0. If it is “min”, the minimum ID number of existing records is specified. If it is “prev”, the number less by one than the minimum ID number of existing records is specified. If it is “max”, the maximum ID number of existing records is specified. If it is “next”, the number greater by one than the maximum ID number of existing records is specified.
`num' specifies the additional value.
If successful, the return value is the summation value, else, it is `nil'.
If the corresponding record exists, the value is treated as an integer and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `i' operator after retrieval.

Close the database file.
If successful, the return value is true, else, it is false.
Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.

Copy the database file.
`path' specifies the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.
If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.
The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.

Get the last happened error code.
The return value is the last happened error code.
The following error codes are defined: `TokyoCabinet::FDB::ESUCCESS' for success, `TokyoCabinet::FDB::ETHREAD' for threading error, `TokyoCabinet::FDB::EINVALID' for invalid operation, `TokyoCabinet::FDB::ENOFILE' for file not found, `TokyoCabinet::FDB::ENOPERM' for no permission, `TokyoCabinet::FDB::EMETA' for invalid meta data, `TokyoCabinet::FDB::ERHEAD' for invalid record header, `TokyoCabinet::FDB::EOPEN' for open error, `TokyoCabinet::FDB::ECLOSE' for close error, `TokyoCabinet::FDB::ETRUNC' for trunc error, `TokyoCabinet::FDB::ESYNC' for sync error, `TokyoCabinet::FDB::ESTAT' for stat error, `TokyoCabinet::FDB::ESEEK' for seek error, `TokyoCabinet::FDB::EREAD' for read error, `TokyoCabinet::FDB::EWRITE' for write error, `TokyoCabinet::FDB::EMMAP' for mmap error, `TokyoCabinet::FDB::ELOCK' for lock error, `TokyoCabinet::FDB::EUNLINK' for unlink error, `TokyoCabinet::FDB::ERENAME' for rename error, `TokyoCabinet::FDB::EMKDIR' for mkdir error, `TokyoCabinet::FDB::ERMDIR' for rmdir error, `TokyoCabinet::FDB::EKEEP' for existing record, `TokyoCabinet::FDB::ENOREC' for no record found, and `TokyoCabinet::FDB::EMISC' for miscellaneous error.

Get the message string corresponding to an error code.
`ecode' specifies the error code. If it is not defined or negative, the last happened error code is specified.
The return value is the message string of the error code.

Get the size of the database file.
The return value is the size of the database file or 0 if the object does not connect to any database file.

Retrieve a record.
`key' specifies the key. It should be more than 0. If it is `FDBIDMIN', the minimum ID number of existing records is specified. If it is `FDBIDMAX', the maximum ID number of existing records is specified.
If successful, the return value is the value of the corresponding record. `nil' is returned if no record corresponds.

Initialize the iterator.
If successful, the return value is true, else, it is false.
The iterator is used in order to access the key of every record stored in a database.

Get the next key of the iterator.
If successful, the return value is the next key, else, it is `nil'. `nil' is returned when no record is to be get out of the iterator.
It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. The order of this traversal access method is ascending of the ID number.

Open a database file.
`path' specifies the path of the database file.
`omode' specifies the connection mode: `TokyoCabinet::FDB::OWRITER' as a writer, `TokyoCabinet::FDB::OREADER' as a reader. If the mode is `TokyoCabinet::FDB::OWRITER', the following may be added by bitwise-or: `TokyoCabinet::FDB::OCREAT', which means it creates a new database if not exist, `TokyoCabinet::FDB::OTRUNC', which means it creates a new database regardless if one exists. Both of `TokyoCabinet::FDB::OREADER' and `TokyoCabinet::FDB::OWRITER' can be added to by bitwise-or: `TokyoCabinet::FDB::ONOLCK', which means it opens the database file without file locking, or `TokyoCabinet::FDB::OLCKNB', which means locking is performed without blocking. If it is not defined, `TokyoCabinet::FDB::OREADER' is specified.
If successful, the return value is true, else, it is false.

Optimize the database file.
`width' specifies the width of the value of each record. If it is not defined or not more than 0, the current setting is not changed.
`limsiz' specifies the limit size of the database file. If it is not defined or not more than 0, the current setting is not changed.
If successful, the return value is true, else, it is false.

Remove a record.
`key' specifies the key. It should be more than 0. If it is `FDBIDMIN', the minimum ID number of existing records is specified. If it is `FDBIDMAX', the maximum ID number of existing records is specified.
If successful, the return value is true, else, it is false.

Get the path of the database file.
The return value is the path of the database file or `nil' if the object does not connect to any database file.

Store a record.
`key' specifies the key. It should be more than 0. If it is “min”, the minimum ID number of existing records is specified. If it is “prev”, the number less by one than the minimum ID number of existing records is specified. If it is “max”, the maximum ID number of existing records is specified. If it is “next”, the number greater by one than the maximum ID number of existing records is specified.
`value' specifies the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, it is overwritten.

Concatenate a value at the end of the existing record.
`key' specifies the key. It should be more than 0. If it is “min”, the minimum ID number of existing records is specified. If it is “prev”, the number less by one than the minimum ID number of existing records is specified. If it is “max”, the maximum ID number of existing records is specified. If it is “next”, the number greater by one than the maximum ID number of existing records is specified.
`value' specifies the value.
If successful, the return value is true, else, it is false.
If there is no corresponding record, a new record is created.

Store a new record.
`key' specifies the key. It should be more than 0. If it is “min”, the minimum ID number of existing records is specified. If it is “prev”, the number less by one than the minimum ID number of existing records is specified. If it is “max”, the maximum ID number of existing records is specified. If it is “next”, the number greater by one than the maximum ID number of existing records is specified.
`value' specifies the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, this method has no effect.

Get keys with an interval notation.
`interval' specifies the interval notation.
`max' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.
The return value is a list object of the keys of the corresponding records. This method does never fail. It returns an empty list even if no record corresponds.

Get the number of records.
The return value is the number of records or 0 if the object does not connect to any database file.

Synchronize updated contents with the file and the device.
If successful, the return value is true, else, it is false.
This method is useful when another process connects the same database file.

Abort the transaction.
If successful, the return value is true, else, it is false.
Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.

Begin the transaction.
If successful, the return value is true, else, it is false.
The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly.

Commit the transaction.
If successful, the return value is true, else, it is false.
Update in the transaction is fixed when it is committed successfully.

Set the tuning parameters.
`width' specifies the width of the value of each record. If it is not defined or not more than 0, the default value is specified. The default value is 255.
`limsiz' specifies the limit size of the database file. If it is not defined or not more than 0, the default value is specified. The default value is 268435456.
If successful, the return value is true, else, it is false. Note that the tuning parameters of the database should be set before the database is opened.

Remove all records.
If successful, the return value is true, else, it is false.

Get the size of the value of a record.
`key' specifies the key. It should be more than 0. If it is `FDBIDMIN', the minimum ID number of existing records is specified. If it is `FDBIDMAX', the maximum ID number of existing records is specified.
If successful, the return value is the size of the value of the corresponding record, else, it is -1.

tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/0000755000175000017500000000000011547412351021240 5ustar spkspktokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000149.html0000644000175000017500000000145311547412351023003 0ustar spkspk put (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1401
    def put(key, value)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000150.html0000644000175000017500000000146311547412351022774 0ustar spkspk putkeep (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1409
    def putkeep(key, value)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000169.html0000644000175000017500000000133111547412351023000 0ustar spkspk size (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1528
    def size()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000153.html0000644000175000017500000000137711547412351023003 0ustar spkspk get (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1429
    def get(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000160.html0000644000175000017500000000133111547412351022767 0ustar spkspk sync (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1477
    def sync()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000147.html0000644000175000017500000000140211547412351022773 0ustar spkspk open (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1387
    def open(name)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000156.html0000644000175000017500000000134111547412351022775 0ustar spkspk iternext (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1447
    def iternext()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000151.html0000644000175000017500000000146111547412351022773 0ustar spkspk putcat (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1417
    def putcat(key, value)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000165.html0000644000175000017500000000134511547412351023001 0ustar spkspk trancommit (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1507
    def trancommit()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000157.html0000644000175000017500000000146411547412351023004 0ustar spkspk fwmkeys (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1455
    def fwmkeys(prefix, max)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000155.html0000644000175000017500000000134111547412351022774 0ustar spkspk iterinit (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1441
    def iterinit()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000162.html0000644000175000017500000000133511547412351022775 0ustar spkspk vanish (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1488
    def vanish()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000158.html0000644000175000017500000000145711547412351023007 0ustar spkspk addint (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1463
    def addint(key, num)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000167.html0000644000175000017500000000133111547412351022776 0ustar spkspk path (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1518
    def path()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000152.html0000644000175000017500000000137711547412351023002 0ustar spkspk out (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1423
    def out(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000148.html0000644000175000017500000000133311547412351022777 0ustar spkspk close (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1393
    def close()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000146.html0000644000175000017500000000133611547412351023000 0ustar spkspk new (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1380
    def initialize()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000166.html0000644000175000017500000000134311547412351023000 0ustar spkspk tranabort (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1513
    def tranabort()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000161.html0000644000175000017500000000141411547412351022772 0ustar spkspk optimize (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1483
    def optimize(params)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000163.html0000644000175000017500000000140211547412351022771 0ustar spkspk copy (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1495
    def copy(path)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000164.html0000644000175000017500000000134311547412351022776 0ustar spkspk tranbegin (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1501
    def tranbegin()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000159.html0000644000175000017500000000146511547412351023007 0ustar spkspk adddouble (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1471
    def adddouble(key, num)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000168.html0000644000175000017500000000133111547412351022777 0ustar spkspk rnum (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1523
    def rnum()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000170.html0000644000175000017500000000145511547412351022777 0ustar spkspk misc (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1535
    def misc(name, args)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.src/M000154.html0000644000175000017500000000140111547412351022770 0ustar spkspk vsiz (TokyoCabinet::ADB)
# File tokyocabinet-doc.rb, line 1435
    def vsiz(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/0000755000175000017500000000000011547412351021245 5ustar spkspktokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000099.html0000644000175000017500000000134411547412351023013 0ustar spkspk trancommit (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 908
    def trancommit()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000083.html0000644000175000017500000000145211547412351023004 0ustar spkspk put (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 802
    def put(key, value)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000080.html0000644000175000017500000000145711547412351023006 0ustar spkspk tune (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 781
    def tune(width, limsiz)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000091.html0000644000175000017500000000146111547412351023003 0ustar spkspk range (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 855
    def range(interval, max)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000103.html0000644000175000017500000000133011547412351022770 0ustar spkspk fsiz (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 929
    def fsiz()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000093.html0000644000175000017500000000146411547412351023010 0ustar spkspk adddouble (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 871
    def adddouble(key, num)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000095.html0000644000175000017500000000154211547412351023007 0ustar spkspk optimize (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 884
    def optimize(bnum, width, limsiz)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000081.html0000644000175000017500000000145511547412351023005 0ustar spkspk open (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 788
    def open(path, omode)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000097.html0000644000175000017500000000140111547412351023003 0ustar spkspk copy (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 896
    def copy(path)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000101.html0000644000175000017500000000133011547412351022766 0ustar spkspk path (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 919
    def path()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000079.html0000644000175000017500000000133211547412351023006 0ustar spkspk ecode (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 774
    def ecode()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000088.html0000644000175000017500000000140011547412351023002 0ustar spkspk vsiz (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 836
    def vsiz(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000087.html0000644000175000017500000000137611547412351023015 0ustar spkspk get (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 830
    def get(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000094.html0000644000175000017500000000133011547412351023001 0ustar spkspk sync (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 877
    def sync()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000084.html0000644000175000017500000000146211547412351023006 0ustar spkspk putkeep (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 810
    def putkeep(key, value)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000077.html0000644000175000017500000000133511547412351023007 0ustar spkspk new (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 762
    def initialize()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000098.html0000644000175000017500000000134211547412351023010 0ustar spkspk tranbegin (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 902
    def tranbegin()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000092.html0000644000175000017500000000145611547412351023010 0ustar spkspk addint (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 863
    def addint(key, num)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000100.html0000644000175000017500000000134211547412351022770 0ustar spkspk tranabort (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 914
    def tranabort()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000102.html0000644000175000017500000000133011547412351022767 0ustar spkspk rnum (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 924
    def rnum()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000089.html0000644000175000017500000000134011547412351023006 0ustar spkspk iterinit (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 842
    def iterinit()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000096.html0000644000175000017500000000133411547412351023007 0ustar spkspk vanish (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 889
    def vanish()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000090.html0000644000175000017500000000134011547412351022776 0ustar spkspk iternext (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 848
    def iternext()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000085.html0000644000175000017500000000146011547412351023005 0ustar spkspk putcat (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 818
    def putcat(key, value)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000078.html0000644000175000017500000000140611547412351023007 0ustar spkspk errmsg (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 768
    def errmsg(ecode)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000086.html0000644000175000017500000000137611547412351023014 0ustar spkspk out (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 824
    def out(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/FDB.src/M000082.html0000644000175000017500000000133211547412351023000 0ustar spkspk close (TokyoCabinet::FDB)
# File tokyocabinet-doc.rb, line 794
    def close()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/ADB.html0000644000175000017500000006331611547412351021351 0ustar spkspk Class: TokyoCabinet::ADB [Tokyo Cabinet]
Class TokyoCabinet::ADB
In: tokyocabinet-doc.rb
Parent: Object

Abstract database is a set of interfaces to use on-memory hash database, on-memory tree database, hash database, B+ tree database, fixed-length database, and table database with the same API. Before operations to store or retrieve records, it is necessary to connect the abstract database object to the concrete one. The method `open' is used to open a concrete database and the method `close' is used to close the database. To avoid data missing or corruption, it is important to close every database instance when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.
Except for the interface below, methods compatible with the `Hash' class are also provided; `[]', `[]=', `store', `delete', `fetch', `has_key?', `has_value?', `key', `clear', `length', `empty?', `each', `each_key', `each_value', and `keys'.

Methods

adddouble   addint   close   copy   fwmkeys   get   iterinit   iternext   misc   new   open   optimize   out   path   put   putcat   putkeep   rnum   size   sync   tranabort   tranbegin   trancommit   vanish   vsiz  

Public Class methods

Create an abstract database object.
The return value is the new abstract database object.

Public Instance methods

Add a real number to a record.
`key' specifies the key.
`num' specifies the additional value.
If successful, the return value is the summation value, else, it is `nil'.
If the corresponding record exists, the value is treated as a real number and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `d' operator after retrieval.

Add an integer to a record.
`key' specifies the key.
`num' specifies the additional value.
If successful, the return value is the summation value, else, it is `nil'.
If the corresponding record exists, the value is treated as an integer and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `i' operator after retrieval.

Close the database.
If successful, the return value is true, else, it is false.
Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.

Copy the database file.
`path' specifies the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.
If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.
The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.

Get forward matching keys.
`prefix' specifies the prefix of the corresponding keys.
`max' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.
The return value is a list object of the keys of the corresponding records. This method does never fail. It returns an empty list even if no record corresponds.
Note that this method may be very slow because every key in the database is scanned.

Retrieve a record.
`key' specifies the key.
If successful, the return value is the value of the corresponding record. `nil' is returned if no record corresponds.

Initialize the iterator.
If successful, the return value is true, else, it is false.
The iterator is used in order to access the key of every record stored in a database.

Get the next key of the iterator.
If successful, the return value is the next key, else, it is `nil'. `nil' is returned when no record is to be get out of the iterator.
It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.

Call a versatile function for miscellaneous operations.
`name' specifies the name of the function.
`args' specifies an array of arguments. If it is not defined, no argument is specified.
If successful, the return value is an array of the result. `nil' is returned on failure.

Open a database.
`name' specifies the name of the database. If it is “*”, the database will be an on-memory hash database. If it is “+”, the database will be an on-memory tree database. If its suffix is “.tch”, the database will be a hash database. If its suffix is “.tcb”, the database will be a B+ tree database. If its suffix is “.tcf”, the database will be a fixed-length database. If its suffix is “.tct”, the database will be a table database. Otherwise, this method fails. Tuning parameters can trail the name, separated by “#”. Each parameter is composed of the name and the value, separated by “=”. On-memory hash database supports “bnum”, “capnum”, and “capsiz”. On-memory tree database supports “capnum” and “capsiz”. Hash database supports “mode”, “bnum”, “apow”, “fpow”, “opts”, “rcnum”, and “xmsiz”. B+ tree database supports “mode”, “lmemb”, “nmemb”, “bnum”, “apow”, “fpow”, “opts”, “lcnum”, “ncnum”, and “xmsiz”. Fixed-length database supports “mode”, “width”, and “limsiz”. Table database supports “mode”, “bnum”, “apow”, “fpow”, “opts”, “rcnum”, “lcnum”, “ncnum”, “xmsiz”, and “idx”.
If successful, the return value is true, else, it is false.
The tuning parameter “capnum” specifies the capacity number of records. “capsiz” specifies the capacity size of using memory. Records spilled the capacity are removed by the storing order. “mode” can contain “w” of writer, “r” of reader, “c” of creating, “t” of truncating, “e” of no locking, and “f” of non-blocking lock. The default mode is relevant to “wc”. “opts” can contains “l” of large option, “d” of Deflate option, “b” of BZIP2 option, and “t” of TCBS option. “idx” specifies the column name of an index and its type separated by “:”. For example, “casket.tch#bnum=1000000opts=ld” means that the name of the database file is “casket.tch“, and the bucket number is 1000000, and the options are large and Deflate.

Optimize the storage.
`params' specifies the string of the tuning parameters, which works as with the tuning of parameters the method `open'. If it is not defined, it is not used.
If successful, the return value is true, else, it is false.

Remove a record.
`key' specifies the key.
If successful, the return value is true, else, it is false.

Get the path of the database file.
The return value is the path of the database file or `nil' if the object does not connect to any database instance. “*” stands for on-memory hash database. “+” stands for on-memory tree database.

Store a record.
`key' specifies the key.
`value' specifies the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, it is overwritten.

Concatenate a value at the end of the existing record.
`key' specifies the key.
`value' specifies the value.
If successful, the return value is true, else, it is false.
If there is no corresponding record, a new record is created.

Store a new record.
`key' specifies the key.
`value' specifies the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, this method has no effect.

Get the number of records.
The return value is the number of records or 0 if the object does not connect to any database instance.

Get the size of the database.
The return value is the size of the database or 0 if the object does not connect to any database instance.

Synchronize updated contents with the file and the device.
If successful, the return value is true, else, it is false.
This method is useful when another process connects the same database file.

Abort the transaction.
If successful, the return value is true, else, it is false.
Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.

Begin the transaction.
If successful, the return value is true, else, it is false.
The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly.

Commit the transaction.
If successful, the return value is true, else, it is false.
Update in the transaction is fixed when it is committed successfully.

Remove all records.
If successful, the return value is true, else, it is false.

Get the size of the value of a record.
`key' specifies the key.
If successful, the return value is the size of the value of the corresponding record, else, it is -1.

tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/HDB.html0000644000175000017500000012417111547412351021355 0ustar spkspk Class: TokyoCabinet::HDB [Tokyo Cabinet]
Class TokyoCabinet::HDB
In: tokyocabinet-doc.rb
Parent: Object

Hash database is a file containing a hash table and is handled with the hash database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the hash database object to it. To avoid data missing or corruption, it is important to close every database file when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.
Except for the interface below, methods compatible with the `Hash' class are also provided; `[]', `[]=', `store', `delete', `fetch', `has_key?', `has_value?', `key', `clear', `length', `empty?', `each', `each_key', `each_value', and `keys'.

Methods

adddouble   addint   close   copy   ecode   errmsg   fsiz   fwmkeys   get   iterinit   iternext   new   open   optimize   out   path   put   putasync   putcat   putkeep   rnum   setcache   setdfunit   setxmsiz   sync   tranabort   tranbegin   trancommit   tune   vanish   vsiz  

Constants

ESUCCESS = 0   error code: success
ETHREAD = 1   error code: threading error
EINVALID = 2   error code: invalid operation
ENOFILE = 3   error code: file not found
ENOPERM = 4   error code: no permission
EMETA = 5   error code: invalid meta data
ERHEAD = 6   error code: invalid record header
EOPEN = 7   error code: open error
ECLOSE = 8   error code: close error
ETRUNC = 9   error code: trunc error
ESYNC = 10   error code: sync error
ESTAT = 11   error code: stat error
ESEEK = 12   error code: seek error
EREAD = 13   error code: read error
EWRITE = 14   error code: write error
EMMAP = 15   error code: mmap error
ELOCK = 16   error code: lock error
EUNLINK = 17   error code: unlink error
ERENAME = 18   error code: rename error
EMKDIR = 19   error code: mkdir error
ERMDIR = 20   error code: rmdir error
EKEEP = 21   error code: existing record
ENOREC = 22   error code: no record found
EMISC = 9999   error code: miscellaneous error
TLARGE = 1 << 0   tuning option: use 64-bit bucket array
TDEFLATE = 1 << 1   tuning option: compress each record with Deflate
TBZIP = 1 << 2   tuning option: compress each record with BZIP2
TTCBS = 1 << 3   tuning option: compress each record with TCBS
OREADER = 1 << 0   open mode: open as a reader
OWRITER = 1 << 1   open mode: open as a writer
OCREAT = 1 << 2   open mode: writer creating
OTRUNC = 1 << 3   open mode: writer truncating
ONOLCK = 1 << 4   open mode: open without locking
OLCKNB = 1 << 5   open mode: lock without blocking
OTSYNC = 1 << 6   open mode: synchronize every transaction

Public Class methods

Create a hash database object.
The return value is the new hash database object.

Public Instance methods

Add a real number to a record.
`key' specifies the key.
`num' specifies the additional value.
If successful, the return value is the summation value, else, it is `nil'.
If the corresponding record exists, the value is treated as a real number and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `d' operator after retrieval.

Add an integer to a record.
`key' specifies the key.
`num' specifies the additional value.
If successful, the return value is the summation value, else, it is `nil'.
If the corresponding record exists, the value is treated as an integer and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `i' operator after retrieval.

Close the database file.
If successful, the return value is true, else, it is false.
Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.

Copy the database file.
`path' specifies the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.
If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.
The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.

Get the last happened error code.
The return value is the last happened error code.
The following error codes are defined: `TokyoCabinet::HDB::ESUCCESS' for success, `TokyoCabinet::HDB::ETHREAD' for threading error, `TokyoCabinet::HDB::EINVALID' for invalid operation, `TokyoCabinet::HDB::ENOFILE' for file not found, `TokyoCabinet::HDB::ENOPERM' for no permission, `TokyoCabinet::HDB::EMETA' for invalid meta data, `TokyoCabinet::HDB::ERHEAD' for invalid record header, `TokyoCabinet::HDB::EOPEN' for open error, `TokyoCabinet::HDB::ECLOSE' for close error, `TokyoCabinet::HDB::ETRUNC' for trunc error, `TokyoCabinet::HDB::ESYNC' for sync error, `TokyoCabinet::HDB::ESTAT' for stat error, `TokyoCabinet::HDB::ESEEK' for seek error, `TokyoCabinet::HDB::EREAD' for read error, `TokyoCabinet::HDB::EWRITE' for write error, `TokyoCabinet::HDB::EMMAP' for mmap error, `TokyoCabinet::HDB::ELOCK' for lock error, `TokyoCabinet::HDB::EUNLINK' for unlink error, `TokyoCabinet::HDB::ERENAME' for rename error, `TokyoCabinet::HDB::EMKDIR' for mkdir error, `TokyoCabinet::HDB::ERMDIR' for rmdir error, `TokyoCabinet::HDB::EKEEP' for existing record, `TokyoCabinet::HDB::ENOREC' for no record found, and `TokyoCabinet::HDB::EMISC' for miscellaneous error.

Get the message string corresponding to an error code.
`ecode' specifies the error code. If it is not defined or negative, the last happened error code is specified.
The return value is the message string of the error code.

Get the size of the database file.
The return value is the size of the database file or 0 if the object does not connect to any database file.

Get forward matching keys.
`prefix' specifies the prefix of the corresponding keys.
`max' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.
The return value is a list object of the keys of the corresponding records. This method does never fail. It returns an empty list even if no record corresponds.
Note that this method may be very slow because every key in the database is scanned.

Retrieve a record.
`key' specifies the key.
If successful, the return value is the value of the corresponding record. `nil' is returned if no record corresponds.

Initialize the iterator.
If successful, the return value is true, else, it is false.
The iterator is used in order to access the key of every record stored in a database.

Get the next key of the iterator.
If successful, the return value is the next key, else, it is `nil'. `nil' is returned when no record is to be get out of the iterator.
It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.

Open a database file.
`path' specifies the path of the database file.
`omode' specifies the connection mode: `TokyoCabinet::HDB::OWRITER' as a writer, `TokyoCabinet::HDB::OREADER' as a reader. If the mode is `TokyoCabinet::HDB::OWRITER', the following may be added by bitwise-or: `TokyoCabinet::HDB::OCREAT', which means it creates a new database if not exist, `TokyoCabinet::HDB::OTRUNC', which means it creates a new database regardless if one exists, `TokyoCabinet::HDB::OTSYNC', which means every transaction synchronizes updated contents with the device. Both of `TokyoCabinet::HDB::OREADER' and `TokyoCabinet::HDB::OWRITER' can be added to by bitwise-or: `TokyoCabinet::HDB::ONOLCK', which means it opens the database file without file locking, or `TokyoCabinet::HDB::OLCKNB', which means locking is performed without blocking. If it is not defined, `TokyoCabinet::HDB::OREADER' is specified.
If successful, the return value is true, else, it is false.

Optimize the database file.
`bnum' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is two times of the number of records.
`apow' specifies the size of record alignment by power of 2. If it is not defined or negative, the current setting is not changed.
`fpow' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the current setting is not changed.
`opts' specifies options by bitwise-or: `TokyoCabinet::HDB::TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::HDB::TDEFLATE' specifies that each record is compressed with Deflate encoding, `TokyoCabinet::HDB::TBZIP' specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::HDB::TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined or 0xff, the current setting is not changed.
If successful, the return value is true, else, it is false.
This method is useful to reduce the size of the database file with data fragmentation by successive updating.

Remove a record.
`key' specifies the key.
If successful, the return value is true, else, it is false.

Get the path of the database file.
The return value is the path of the database file or `nil' if the object does not connect to any database file.

Store a record.
`key' specifies the key.
`value' specifies the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, it is overwritten.

Store a record in asynchronous fashion.
`key' specifies the key.
`value' specifies the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, it is overwritten. Records passed to this method are accumulated into the inner buffer and wrote into the file at a blast.

Concatenate a value at the end of the existing record.
`key' specifies the key.
`value' specifies the value.
If successful, the return value is true, else, it is false.
If there is no corresponding record, a new record is created.

Store a new record.
`key' specifies the key.
`value' specifies the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, this method has no effect.

Get the number of records.
The return value is the number of records or 0 if the object does not connect to any database file.

Set the caching parameters.
`rcnum' specifies the maximum number of records to be cached. If it is not defined or not more than 0, the record cache is disabled. It is disabled by default.
If successful, the return value is true, else, it is false.
Note that the caching parameters of the database should be set before the database is opened.

Set the unit step number of auto defragmentation.
`dfunit' specifie the unit step number. If it is not more than 0, the auto defragmentation is disabled. It is disabled by default.
If successful, the return value is true, else, it is false.
Note that the defragmentation parameters should be set before the database is opened.

Set the size of the extra mapped memory.
`xmsiz' specifies the size of the extra mapped memory. If it is not defined or not more than 0, the extra mapped memory is disabled. The default size is 67108864.
If successful, the return value is true, else, it is false.
Note that the mapping parameters should be set before the database is opened.

Synchronize updated contents with the file and the device.
If successful, the return value is true, else, it is false.
This method is useful when another process connects the same database file.

Abort the transaction.
If successful, the return value is true, else, it is false.
Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.

Begin the transaction.
If successful, the return value is true, else, it is false.
The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly.

Commit the transaction.
If successful, the return value is true, else, it is false.
Update in the transaction is fixed when it is committed successfully.

Set the tuning parameters.
`bnum' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 131071. Suggested size of the bucket array is about from 0.5 to 4 times of the number of all records to be stored.
`apow' specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^4=16.
`fpow' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.
`opts' specifies options by bitwise-or: `TokyoCabinet::HDB::TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::HDB::TDEFLATE' specifies that each record is compressed with Deflate encoding, `TokyoCabinet::HDB::TDBZIP' specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::HDB::TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.
If successful, the return value is true, else, it is false. Note that the tuning parameters of the database should be set before the database is opened.

Remove all records.
If successful, the return value is true, else, it is false.

Get the size of the value of a record.
`key' specifies the key.
If successful, the return value is the size of the value of the corresponding record, else, it is -1.

tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDB.html0000644000175000017500000013265011547412351021372 0ustar spkspk Class: TokyoCabinet::TDB [Tokyo Cabinet]
Class TokyoCabinet::TDB
In: tokyocabinet-doc.rb
Parent: Object

Table database is a file containing records composed of the primary keys and arbitrary columns and is handled with the table database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the table database object to it. To avoid data missing or corruption, it is important to close every database file when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.
Except for the interface below, methods compatible with the `Hash' class are also provided; `[]', `[]=', `store', `delete', `fetch', `has_key?', `clear', `length', `empty?', `each', `each_key', `each_value', and `keys'.

Methods

adddouble   addint   close   copy   ecode   errmsg   fsiz   fwmkeys   genuid   get   iterinit   iternext   new   open   optimize   out   path   put   putcat   putkeep   rnum   setcache   setdfunit   setindex   setxmsiz   sync   tranabort   tranbegin   trancommit   tune   vanish   vsiz  

Constants

ESUCCESS = 0   error code: success
ETHREAD = 1   error code: threading error
EINVALID = 2   error code: invalid operation
ENOFILE = 3   error code: file not found
ENOPERM = 4   error code: no permission
EMETA = 5   error code: invalid meta data
ERHEAD = 6   error code: invalid record header
EOPEN = 7   error code: open error
ECLOSE = 8   error code: close error
ETRUNC = 9   error code: trunc error
ESYNC = 10   error code: sync error
ESTAT = 11   error code: stat error
ESEEK = 12   error code: seek error
EREAD = 13   error code: read error
EWRITE = 14   error code: write error
EMMAP = 15   error code: mmap error
ELOCK = 16   error code: lock error
EUNLINK = 17   error code: unlink error
ERENAME = 18   error code: rename error
EMKDIR = 19   error code: mkdir error
ERMDIR = 20   error code: rmdir error
EKEEP = 21   error code: existing record
ENOREC = 22   error code: no record found
EMISC = 9999   error code: miscellaneous error
TLARGE = 1 << 0   tuning option: use 64-bit bucket array
TDEFLATE = 1 << 1   tuning option: compress each record with Deflate
TBZIP = 1 << 2   tuning option: compress each record with BZIP2
TTCBS = 1 << 3   tuning option: compress each record with TCBS
OREADER = 1 << 0   open mode: open as a reader
OWRITER = 1 << 1   open mode: open as a writer
OCREAT = 1 << 2   open mode: writer creating
OTRUNC = 1 << 3   open mode: writer truncating
ONOLCK = 1 << 4   open mode: open without locking
OLCKNB = 1 << 5   open mode: lock without blocking
OTSYNC = 1 << 6   open mode: synchronize every transaction
ITLEXICAL = 0   index type: lexical string
ITDECIMAL = 1   index type: decimal string
ITTOKEN = 2   index type: token inverted index
ITQGRAM = 3   index type: q-gram inverted index
ITOPT = 9998   index type: optimize
ITVOID = 9999   index type: void
ITKEEP = 1 << 24   index type: keep existing index

Public Class methods

Create a table database object.
The return value is the new table database object.

Public Instance methods

Add a real number to a record.
`key' specifies the primary key.
`num' specifies the additional value.
If successful, the return value is the summation value, else, it is `nil'.
The additional value is stored as a decimal string value of a column whose name is “_num”. If no record corresponds, a new record with the additional value is stored.

Add an integer to a record.
`pkey' specifies the primary key.
`num' specifies the additional value.
If successful, the return value is the summation value, else, it is `nil'.
The additional value is stored as a decimal string value of a column whose name is “_num”. If no record corresponds, a new record with the additional value is stored.

Close the database file.
If successful, the return value is true, else, it is false.
Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.

Copy the database file.
`path' specifies the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.
If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.
The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.

Get the last happened error code.
The return value is the last happened error code.
The following error codes are defined: `TokyoCabinet::TDB::ESUCCESS' for success, `TokyoCabinet::TDB::ETHREAD' for threading error, `TokyoCabinet::TDB::EINVALID' for invalid operation, `TokyoCabinet::TDB::ENOFILE' for file not found, `TokyoCabinet::TDB::ENOPERM' for no permission, `TokyoCabinet::TDB::EMETA' for invalid meta data, `TokyoCabinet::TDB::ERHEAD' for invalid record header, `TokyoCabinet::TDB::EOPEN' for open error, `TokyoCabinet::TDB::ECLOSE' for close error, `TokyoCabinet::TDB::ETRUNC' for trunc error, `TokyoCabinet::TDB::ESYNC' for sync error, `TokyoCabinet::TDB::ESTAT' for stat error, `TokyoCabinet::TDB::ESEEK' for seek error, `TokyoCabinet::TDB::EREAD' for read error, `TokyoCabinet::TDB::EWRITE' for write error, `TokyoCabinet::TDB::EMMAP' for mmap error, `TokyoCabinet::TDB::ELOCK' for lock error, `TokyoCabinet::TDB::EUNLINK' for unlink error, `TokyoCabinet::TDB::ERENAME' for rename error, `TokyoCabinet::TDB::EMKDIR' for mkdir error, `TokyoCabinet::TDB::ERMDIR' for rmdir error, `TokyoCabinet::TDB::EKEEP' for existing record, `TokyoCabinet::TDB::ENOREC' for no record found, and `TokyoCabinet::TDB::EMISC' for miscellaneous error.

Get the message string corresponding to an error code.
`ecode' specifies the error code. If it is not defined or negative, the last happened error code is specified.
The return value is the message string of the error code.

Get the size of the database file.
The return value is the size of the database file or 0 if the object does not connect to any database file.

Get forward matching primary keys.
`prefix' specifies the prefix of the corresponding keys.
`max' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.
The return value is a list object of the keys of the corresponding records. This method does never fail. It returns an empty list even if no record corresponds.
Note that this method may be very slow because every key in the database is scanned.

Generate a unique ID number.
The return value is the new unique ID number or -1 on failure.

Retrieve a record.
`pkey' specifies the primary key.
If successful, the return value is a hash of the columns of the corresponding record. `nil' is returned if no record corresponds.

Initialize the iterator.
If successful, the return value is true, else, it is false.
The iterator is used in order to access the primary key of every record stored in a database.

Get the next primary key of the iterator.
If successful, the return value is the next primary key, else, it is `nil'. `nil' is returned when no record is to be get out of the iterator.
It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.

Open a database file.
`path' specifies the path of the database file.
`omode' specifies the connection mode: `TokyoCabinet::TDB::OWRITER' as a writer, `TokyoCabinet::TDB::OREADER' as a reader. If the mode is `TokyoCabinet::TDB::OWRITER', the following may be added by bitwise-or: `TokyoCabinet::TDB::OCREAT', which means it creates a new database if not exist, `TokyoCabinet::TDB::OTRUNC', which means it creates a new database regardless if one exists, `TokyoCabinet::TDB::OTSYNC', which means every transaction synchronizes updated contents with the device. Both of `TokyoCabinet::TDB::OREADER' and `TokyoCabinet::TDB::OWRITER' can be added to by bitwise-or: `TokyoCabinet::TDB::ONOLCK', which means it opens the database file without file locking, or `TokyoCabinet::TDB::OLCKNB', which means locking is performed without blocking. If it is not defined, `TokyoCabinet::TDB::OREADER' is specified.
If successful, the return value is true, else, it is false.

Optimize the database file.
`bnum' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is two times of the number of records.
`apow' specifies the size of record alignment by power of 2. If it is not defined or negative, the current setting is not changed.
`fpow' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the current setting is not changed.
`opts' specifies options by bitwise-or: `TokyoCabinet::TDB::TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::TDB::TDEFLATE' specifies that each record is compressed with Deflate encoding, `TokyoCabinet::TDB::TBZIP' specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::TDB::TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined or 0xff, the current setting is not changed.
If successful, the return value is true, else, it is false.
This method is useful to reduce the size of the database file with data fragmentation by successive updating.

Remove a record.
`pkey' specifies the primary key.
If successful, the return value is true, else, it is false.

Get the path of the database file.
The return value is the path of the database file or `nil' if the object does not connect to any database file.

Store a record.
`pkey' specifies the primary key.
`cols' specifies a hash containing columns.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, it is overwritten.

Concatenate columns of the existing record.
`pkey' specifies the primary key.
`cols' specifies a hash containing columns.
If successful, the return value is true, else, it is false.
If there is no corresponding record, a new record is created.

Store a new record.
`pkey' specifies the primary key.
`cols' specifies a hash containing columns.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, this method has no effect.

Get the number of records.
The return value is the number of records or 0 if the object does not connect to any database file.

Set the caching parameters.
`rcnum' specifies the maximum number of records to be cached. If it is not defined or not more than 0, the record cache is disabled. It is disabled by default.
`lcnum' specifies the maximum number of leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 4096.
`ncnum' specifies the maximum number of non-leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 512.
If successful, the return value is true, else, it is false.
Note that the caching parameters of the database should be set before the database is opened.

Set the unit step number of auto defragmentation.
`dfunit' specifie the unit step number. If it is not more than 0, the auto defragmentation is disabled. It is disabled by default.
If successful, the return value is true, else, it is false.
Note that the defragmentation parameters should be set before the database is opened.

Set a column index.
`name' specifies the name of a column. If the name of an existing index is specified, the index is rebuilt. An empty string means the primary key.
`type' specifies the index type: `TokyoCabinet::TDB::ITLEXICAL' for lexical string, `TokyoCabinet::TDB::ITDECIMAL' for decimal string, `TokyoCabinet::TDB::ITTOKEN' for token inverted index, `TokyoCabinet::TDB::ITQGRAM' for q-gram inverted index. If it is `TokyoCabinet::TDB::ITOPT', the index is optimized. If it is `TokyoCabinet::TDB::ITVOID', the index is removed. If `TokyoCabinet::TDB::ITKEEP' is added by bitwise-or and the index exists, this method merely returns failure.
If successful, the return value is true, else, it is false.

Set the size of the extra mapped memory.
`xmsiz' specifies the size of the extra mapped memory. If it is not defined or not more than 0, the extra mapped memory is disabled. The default size is 67108864.
If successful, the return value is true, else, it is false.
Note that the mapping parameters should be set before the database is opened.

Synchronize updated contents with the file and the device.
If successful, the return value is true, else, it is false.
This method is useful when another process connects the same database file.

Abort the transaction.
If successful, the return value is true, else, it is false.
Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.

Begin the transaction.
If successful, the return value is true, else, it is false.
The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly.

Commit the transaction.
If successful, the return value is true, else, it is false.
Update in the transaction is fixed when it is committed successfully.

Set the tuning parameters.
`bnum' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 131071. Suggested size of the bucket array is about from 0.5 to 4 times of the number of all records to be stored.
`apow' specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^4=16.
`fpow' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.
`opts' specifies options by bitwise-or: `TokyoCabinet::TDB::TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::TDB::TDEFLATE' specifies that each record is compressed with Deflate encoding, `TokyoCabinet::TDB::TDBZIP' specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::TDB::TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.
If successful, the return value is true, else, it is false. Note that the tuning parameters of the database should be set before the database is opened.

Remove all records.
If successful, the return value is true, else, it is false.

Get the size of the value of a record.
`pkey' specifies the primary key.
If successful, the return value is the size of the value of the corresponding record, else, it is -1.

tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDBCUR.html0000644000175000017500000002665111547412351021725 0ustar spkspk Class: TokyoCabinet::BDBCUR [Tokyo Cabinet]
Class TokyoCabinet::BDBCUR
In: tokyocabinet-doc.rb
Parent: Object

Cursor is a mechanism to access each record of B+ tree database in ascending or descending order.

Methods

first   jump   key   last   new   next   out   prev   put   val  

Constants

CPCURRENT = 0   cursor put mode: current
CPBEFORE = 1   cursor put mode: before
CPAFTER = 2   cursor put mode: after

Public Class methods

Create a cursor object.
`bdb' specifies the B+ tree database object.
The return value is the new cursor object.
Note that the cursor is available only after initialization with the `first' or the `jump' methods and so on. Moreover, the position of the cursor will be indefinite when the database is updated after the initialization of the cursor.

Public Instance methods

Move the cursor to the first record.
If successful, the return value is true, else, it is false. False is returned if there is no record in the database.

Move the cursor to the front of records corresponding a key.
`key' specifies the key.
If successful, the return value is true, else, it is false. False is returned if there is no record corresponding the condition.
The cursor is set to the first record corresponding the key or the next substitute if completely matching record does not exist.

Get the key of the record where the cursor is.
If successful, the return value is the key, else, it is `nil'. ‘nil' is returned when the cursor is at invalid position.

Move the cursor to the last record.
If successful, the return value is true, else, it is false. False is returned if there is no record in the database.

Move the cursor to the next record.
If successful, the return value is true, else, it is false. False is returned if there is no next record.

Remove the record where the cursor is.
If successful, the return value is true, else, it is false. False is returned when the cursor is at invalid position.
After deletion, the cursor is moved to the next record if possible.

Move the cursor to the previous record.
If successful, the return value is true, else, it is false. False is returned if there is no previous record.

Insert a record around the cursor.
`value' specifies the value.
`cpmode' specifies detail adjustment: `TokyoCabinet::BDBCUR::CPCURRENT', which means that the value of the current record is overwritten, `TokyoCabinet::BDBCUR::CPBEFORE', which means that the new record is inserted before the current record, `TokyoCabinet::BDBCUR::CPAFTER', which means that the new record is inserted after the current record.
If successful, the return value is true, else, it is false. False is returned when the cursor is at invalid position.
After insertion, the cursor is moved to the inserted record.

Get the value of the record where the cursor is.
If successful, the return value is the value, else, it is `nil'. ‘nil' is returned when the cursor is at invalid position.

tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDBQRY.src/0000755000175000017500000000000011547412351021657 5ustar spkspktokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDBQRY.src/M000137.html0000644000175000017500000000153711547412351023422 0ustar spkspk addcond (TokyoCabinet::TDBQRY)
# File tokyocabinet-doc.rb, line 1319
    def addcond(name, op, expr)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDBQRY.src/M000142.html0000644000175000017500000000133411547412351023411 0ustar spkspk proc (TokyoCabinet::TDBQRY)
# File tokyocabinet-doc.rb, line 1349
    def proc()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDBQRY.src/M000143.html0000644000175000017500000000133411547412351023412 0ustar spkspk hint (TokyoCabinet::TDBQRY)
# File tokyocabinet-doc.rb, line 1354
    def hint()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDBQRY.src/M000139.html0000644000175000017500000000146711547412351023426 0ustar spkspk setlimit (TokyoCabinet::TDBQRY)
# File tokyocabinet-doc.rb, line 1333
    def setlimit(max, skip)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDBQRY.src/M000138.html0000644000175000017500000000147011547412351023417 0ustar spkspk setorder (TokyoCabinet::TDBQRY)
# File tokyocabinet-doc.rb, line 1326
    def setorder(name, type)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDBQRY.src/M000141.html0000644000175000017500000000134611547412351023413 0ustar spkspk searchout (TokyoCabinet::TDBQRY)
# File tokyocabinet-doc.rb, line 1343
    def searchout()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDBQRY.src/M000140.html0000644000175000017500000000134011547412351023404 0ustar spkspk search (TokyoCabinet::TDBQRY)
# File tokyocabinet-doc.rb, line 1338
    def search()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDBQRY.src/M000144.html0000644000175000017500000000147611547412351023422 0ustar spkspk metasearch (TokyoCabinet::TDBQRY)
# File tokyocabinet-doc.rb, line 1362
    def metasearch(others, type)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDBQRY.src/M000145.html0000644000175000017500000000160711547412351023417 0ustar spkspk kwic (TokyoCabinet::TDBQRY)
# File tokyocabinet-doc.rb, line 1371
    def kwic(cols, name, width, opts)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/TDBQRY.src/M000136.html0000644000175000017500000000141111547412351023410 0ustar spkspk new (TokyoCabinet::TDBQRY)
# File tokyocabinet-doc.rb, line 1311
    def initialize(tdb)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.html0000644000175000017500000014032311547412351021344 0ustar spkspk Class: TokyoCabinet::BDB [Tokyo Cabinet]
Class TokyoCabinet::BDB
In: tokyocabinet-doc.rb
Parent: Object

B+ tree database is a file containing a B+ tree and is handled with the B+ tree database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the B+ tree database object to it. To avoid data missing or corruption, it is important to close every database file when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.
Except for the interface below, methods compatible with the `Hash' class are also provided; `[]', `[]=', `store', `delete', `fetch', `has_key?', `has_value?', `key', `clear', `length', `empty?', `each', `each_key', `each_value', and `keys'.

Methods

adddouble   addint   close   copy   ecode   errmsg   fsiz   fwmkeys   get   getlist   new   open   optimize   out   outlist   path   put   putcat   putdup   putkeep   putlist   range   rnum   setcache   setcmpfunc   setdfunit   setxmsiz   sync   tranabort   tranbegin   trancommit   tune   vanish   vnum   vsiz  

Constants

ESUCCESS = 0   error code: success
ETHREAD = 1   error code: threading error
EINVALID = 2   error code: invalid operation
ENOFILE = 3   error code: file not found
ENOPERM = 4   error code: no permission
EMETA = 5   error code: invalid meta data
ERHEAD = 6   error code: invalid record header
EOPEN = 7   error code: open error
ECLOSE = 8   error code: close error
ETRUNC = 9   error code: trunc error
ESYNC = 10   error code: sync error
ESTAT = 11   error code: stat error
ESEEK = 12   error code: seek error
EREAD = 13   error code: read error
EWRITE = 14   error code: write error
EMMAP = 15   error code: mmap error
ELOCK = 16   error code: lock error
EUNLINK = 17   error code: unlink error
ERENAME = 18   error code: rename error
EMKDIR = 19   error code: mkdir error
ERMDIR = 20   error code: rmdir error
EKEEP = 21   error code: existing record
ENOREC = 22   error code: no record found
EMISC = 9999   error code: miscellaneous error
CMPLEXICAL = "CMPLEXICAL"   comparison function: by lexical order
CMPDECIMAL = "CMPDECIMAL"   comparison function: as decimal strings of real numbers
CMPINT32 = "CMPINT32"   comparison function: as 32-bit integers in the native byte order
CMPINT64 = "CMPINT64"   comparison function: as 64-bit integers in the native byte order
TLARGE = 1 << 0   tuning option: use 64-bit bucket array
TDEFLATE = 1 << 1   tuning option: compress each record with Deflate
TBZIP = 1 << 2   tuning option: compress each record with BZIP2
TTCBS = 1 << 3   tuning option: compress each record with TCBS
OREADER = 1 << 0   open mode: open as a reader
OWRITER = 1 << 1   open mode: open as a writer
OCREAT = 1 << 2   open mode: writer creating
OTRUNC = 1 << 3   open mode: writer truncating
ONOLCK = 1 << 4   open mode: open without locking
OLCKNB = 1 << 5   open mode: lock without blocking
OTSYNC = 1 << 6   open mode: synchronize every transaction

Public Class methods

Create a B+ tree database object.
The return value is the new B+ tree database object.

Public Instance methods

Add a real number to a record.
`key' specifies the key.
`num' specifies the additional value.
If successful, the return value is the summation value, else, it is `nil'.
If the corresponding record exists, the value is treated as a real number and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `d' operator after retrieval.

Add an integer to a record.
`key' specifies the key.
`num' specifies the additional value.
If successful, the return value is the summation value, else, it is `nil'.
If the corresponding record exists, the value is treated as an integer and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack' method with the `i' operator after retrieval.

Close the database file.
If successful, the return value is true, else, it is false.
Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.

Copy the database file.
`path' specifies the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.
If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.
The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.

Get the last happened error code.
The return value is the last happened error code.
The following error codes are defined: `TokyoCabinet::BDB::ESUCCESS' for success, `TokyoCabinet::BDB::ETHREAD' for threading error, `TokyoCabinet::BDB::EINVALID' for invalid operation, `TokyoCabinet::BDB::ENOFILE' for file not found, `TokyoCabinet::BDB::ENOPERM' for no permission, `TokyoCabinet::BDB::EMETA' for invalid meta data, `TokyoCabinet::BDB::ERHEAD' for invalid record header, `TokyoCabinet::BDB::EOPEN' for open error, `TokyoCabinet::BDB::ECLOSE' for close error, `TokyoCabinet::BDB::ETRUNC' for trunc error, `TokyoCabinet::BDB::ESYNC' for sync error, `TokyoCabinet::BDB::ESTAT' for stat error, `TokyoCabinet::BDB::ESEEK' for seek error, `TokyoCabinet::BDB::EREAD' for read error, `TokyoCabinet::BDB::EWRITE' for write error, `TokyoCabinet::BDB::EMMAP' for mmap error, `TokyoCabinet::BDB::ELOCK' for lock error, `TokyoCabinet::BDB::EUNLINK' for unlink error, `TokyoCabinet::BDB::ERENAME' for rename error, `TokyoCabinet::BDB::EMKDIR' for mkdir error, `TokyoCabinet::BDB::ERMDIR' for rmdir error, `TokyoCabinet::BDB::EKEEP' for existing record, `TokyoCabinet::BDB::ENOREC' for no record found, and `TokyoCabinet::BDB::EMISC' for miscellaneous error.

Get the message string corresponding to an error code.
`ecode' specifies the error code. If it is not defined or negative, the last happened error code is specified.
The return value is the message string of the error code.

Get the size of the database file.
The return value is the size of the database file or 0 if the object does not connect to any database file.

Get forward matching keys.
`prefix' specifies the prefix of the corresponding keys.
`max' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.
The return value is a list object of the keys of the corresponding records. This method does never fail. It returns an empty list even if no record corresponds.

Retrieve a record.
`key' specifies the key.
If successful, the return value is the value of the corresponding record. `nil' is returned if no record corresponds.
If the key of duplicated records is specified, the value of the first one is selected.

Retrieve records.
`key' specifies the key.
If successful, the return value is a list object of the values of the corresponding records. `nil' is returned if no record corresponds.

Open a database file.
`path' specifies the path of the database file.
`omode' specifies the connection mode: `TokyoCabinet::BDB::OWRITER' as a writer, `TokyoCabinet::BDB::OREADER' as a reader. If the mode is `TokyoCabinet::BDB::OWRITER', the following may be added by bitwise-or: `TokyoCabinet::BDB::OCREAT', which means it creates a new database if not exist, `TokyoCabinet::BDB::OTRUNC', which means it creates a new database regardless if one exists, `TokyoCabinet::BDB::OTSYNC', which means every transaction synchronizes updated contents with the device. Both of `TokyoCabinet::BDB::OREADER' and `TokyoCabinet::BDB::OWRITER' can be added to by bitwise-or: `TokyoCabinet::BDB::ONOLCK', which means it opens the database file without file locking, or `TokyoCabinet::BDB::OLCKNB', which means locking is performed without blocking. If it is not defined, `TokyoCabinet::BDB::OREADER' is specified.
If successful, the return value is true, else, it is false.

Optimize the database file.
`lmemb' specifies the number of members in each leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 128.
`nmemb' specifies the number of members in each non-leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 256.
`bnum' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is two times of the number of pages.
`apow' specifies the size of record alignment by power of 2. If it is not defined or negative, the current setting is not changed.
`fpow' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the current setting is not changed.
`opts' specifies options by bitwise-or: `TokyoCabinet::BDB::TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::BDB::TDEFLATE' specifies that each record is compressed with Deflate encoding, `TokyoCabinet::BDB::TBZIP' specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::BDB::TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined or 0xff, the current setting is not changed.
If successful, the return value is true, else, it is false.
This method is useful to reduce the size of the database file with data fragmentation by successive updating.

Remove a record.
`key' specifies the key.
If successful, the return value is true, else, it is false.
If the key of duplicated records is specified, the value of the first one is selected.

Remove records.
`key' specifies the key.
If successful, the return value is true, else, it is false.
If the key of duplicated records is specified, all of them are removed.

Get the path of the database file.
The return value is the path of the database file or `nil' if the object does not connect to any database file.

Store a record.
`key' specifies the key.
`value' specifies the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, it is overwritten.

Concatenate a value at the end of the existing record.
`key' specifies the key.
`value' specifies the value.
If successful, the return value is true, else, it is false.
If there is no corresponding record, a new record is created.

Store a record with allowing duplication of keys.
`key' specifies the key.
`value' specifies the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, the new record is placed after the existing one.

Store a new record.
`key' specifies the key.
`value' specifies the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, this method has no effect.

Store records with allowing duplication of keys.
`key' specifies the key.
`values' specifies an array of the values.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, the new records are placed after the existing one.

Get keys of ranged records.
`bkey' specifies the key of the beginning border. If it is not defined, the first record is specified.
`binc' specifies whether the beginning border is inclusive or not. If it is not defined, false is specified.
`ekey' specifies the key of the ending border. If it is not defined, the last record is specified.
`einc' specifies whether the ending border is inclusive or not. If it is not defined, false is specified.
`max' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.
The return value is a list object of the keys of the corresponding records. This method does never fail. It returns an empty list even if no record corresponds.

Get the number of records.
The return value is the number of records or 0 if the object does not connect to any database file.

Set the caching parameters.
`lcnum' specifies the maximum number of leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 1024.
`ncnum' specifies the maximum number of non-leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 512.
If successful, the return value is true, else, it is false.
Note that the tuning parameters of the database should be set before the database is opened.

Set the custom comparison function.
`cmp' specifies the custom comparison function. It should be an instance of the class `Proc'.
If successful, the return value is true, else, it is false.
The default comparison function compares keys of two records by lexical order. The constants `TokyoCabinet::BDB::CMPLEXICAL' (dafault), `TokyoCabinet::BDB::CMPDECIMAL', `TokyoCabinet::BDB::CMPINT32', and `TokyoCabinet::BDB::CMPINT64' are built-in. Note that the comparison function should be set before the database is opened. Moreover, user-defined comparison functions should be set every time the database is being opened.

Set the unit step number of auto defragmentation.
`dfunit' specifie the unit step number. If it is not more than 0, the auto defragmentation is disabled. It is disabled by default.
If successful, the return value is true, else, it is false.
Note that the defragmentation parameters should be set before the database is opened.

Set the size of the extra mapped memory.
`xmsiz' specifies the size of the extra mapped memory. If it is not defined or not more than 0, the extra mapped memory is disabled. It is disabled by default.
If successful, the return value is true, else, it is false.
Note that the mapping parameters should be set before the database is opened.

Synchronize updated contents with the file and the device.
If successful, the return value is true, else, it is false.
This method is useful when another process connects the same database file.

Abort the transaction.
If successful, the return value is true, else, it is false.
Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.

Begin the transaction.
If successful, the return value is true, else, it is false.
The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. Because all pages are cached on memory while the transaction, the amount of referred records is limited by the memory capacity. If the database is closed during transaction, the transaction is aborted implicitly.

Commit the transaction.
If successful, the return value is true, else, it is false.
Update in the transaction is fixed when it is committed successfully.

Set the tuning parameters.
`lmemb' specifies the number of members in each leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 128.
`nmemb' specifies the number of members in each non-leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 256.
`bnum' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 32749. Suggested size of the bucket array is about from 1 to 4 times of the number of all pages to be stored.
`apow' specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^8=256.
`fpow' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.
`opts' specifies options by bitwise-or: `TokyoCabinet::BDB::TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::BDB::TDEFLATE' specifies that each record is compressed with Deflate encoding, `TokyoCabinet::BDB::TBZIP' specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::BDB::TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.
If successful, the return value is true, else, it is false. Note that the tuning parameters of the database should be set before the database is opened.

Remove all records.
If successful, the return value is true, else, it is false.

Get the number of records corresponding a key.
`key' specifies the key.
If successful, the return value is the number of the corresponding records, else, it is 0.

Get the size of the value of a record.
`key' specifies the key.
If successful, the return value is the size of the value of the corresponding record, else, it is -1.
If the key of duplicated records is specified, the value of the first one is selected.

tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/0000755000175000017500000000000011547412351021241 5ustar spkspktokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000056.html0000644000175000017500000000146411547412351023003 0ustar spkspk adddouble (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 563
    def adddouble(key, num)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000033.html0000644000175000017500000000140611547412351022772 0ustar spkspk errmsg (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 391
    def errmsg(ecode)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000042.html0000644000175000017500000000145211547412351022773 0ustar spkspk put (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 458
    def put(key, value)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000052.html0000644000175000017500000000140011547412351022765 0ustar spkspk vsiz (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 530
    def vsiz(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000038.html0000644000175000017500000000141211547412351022774 0ustar spkspk setxmsiz (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 430
    def setxmsiz(xmsiz)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000055.html0000644000175000017500000000145611547412351023003 0ustar spkspk addint (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 555
    def addint(key, num)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000051.html0000644000175000017500000000140011547412351022764 0ustar spkspk vnum (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 523
    def vnum(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000059.html0000644000175000017500000000133411547412351023002 0ustar spkspk vanish (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 586
    def vanish()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000043.html0000644000175000017500000000146211547412351022775 0ustar spkspk putkeep (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 466
    def putkeep(key, value)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000058.html0000644000175000017500000000174211547412351023004 0ustar spkspk optimize (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 581
    def optimize(lmemb, nmemb, bnum, apow, fpow, opts)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000065.html0000644000175000017500000000133011547412351022773 0ustar spkspk rnum (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 621
    def rnum()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000040.html0000644000175000017500000000145511547412351022774 0ustar spkspk open (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 444
    def open(path, omode)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000045.html0000644000175000017500000000146011547412351022775 0ustar spkspk putdup (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 482
    def putdup(key, value)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000035.html0000644000175000017500000000141411547412351022773 0ustar spkspk setcmpfunc (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 404
    def setcmpfunc(cmp)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000041.html0000644000175000017500000000133211547412351022767 0ustar spkspk close (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 450
    def close()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000032.html0000644000175000017500000000133511547412351022772 0ustar spkspk new (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 385
    def initialize()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000060.html0000644000175000017500000000140111547412351022765 0ustar spkspk copy (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 593
    def copy(path)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000046.html0000644000175000017500000000146311547412351023001 0ustar spkspk putlist (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 490
    def putlist(key, values)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000049.html0000644000175000017500000000137611547412351023007 0ustar spkspk get (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 511
    def get(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000039.html0000644000175000017500000000141511547412351023000 0ustar spkspk setdfunit (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 437
    def setdfunit(dfunit)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000061.html0000644000175000017500000000134211547412351022772 0ustar spkspk tranbegin (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 599
    def tranbegin()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000054.html0000644000175000017500000000146311547412351023000 0ustar spkspk fwmkeys (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 547
    def fwmkeys(prefix, max)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000048.html0000644000175000017500000000140611547412351023000 0ustar spkspk outlist (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 504
    def outlist(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000057.html0000644000175000017500000000133011547412351022774 0ustar spkspk sync (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 569
    def sync()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000047.html0000644000175000017500000000137611547412351023005 0ustar spkspk out (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 497
    def out(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000044.html0000644000175000017500000000146011547412351022774 0ustar spkspk putcat (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 474
    def putcat(key, value)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000062.html0000644000175000017500000000134411547412351022775 0ustar spkspk trancommit (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 605
    def trancommit()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000063.html0000644000175000017500000000134211547412351022774 0ustar spkspk tranabort (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 611
    def tranabort()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000034.html0000644000175000017500000000133211547412351022771 0ustar spkspk ecode (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 397
    def ecode()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000037.html0000644000175000017500000000146611547412351023004 0ustar spkspk setcache (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 423
    def setcache(lcnum, ncnum)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000036.html0000644000175000017500000000173211547412351022777 0ustar spkspk tune (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 415
    def tune(lmemb, nmemb, bnum, apow, fpow, opts)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000053.html0000644000175000017500000000165611547412351023003 0ustar spkspk range (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 540
    def range(bkey, binc, ekey, einc, max)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000066.html0000644000175000017500000000133011547412351022774 0ustar spkspk fsiz (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 626
    def fsiz()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000050.html0000644000175000017500000000140611547412351022771 0ustar spkspk getlist (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 517
    def getlist(key)
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet/BDB.src/M000064.html0000644000175000017500000000133011547412351022772 0ustar spkspk path (TokyoCabinet::BDB)
# File tokyocabinet-doc.rb, line 616
    def path()
      # (native code)
    end
tokyocabinet-ruby-1.31/doc/classes/TokyoCabinet.html0000644000175000017500000003220311547412351020752 0ustar spkspk Module: TokyoCabinet [Tokyo Cabinet]
Module TokyoCabinet
In: tokyocabinet-doc.rb

Ruby Binding of Tokyo Cabinet

Tokyo Cabinet: a modern implementation of DBM

INTRODUCTION

Tokyo Cabinet is a library of routines for managing a database. The database is a simple data file containing records, each is a pair of a key and a value. Every key and value is serial bytes with variable length. Both binary data and character string can be used as a key and a value. There is neither concept of data tables nor data types. Records are organized in hash table, B+ tree, or fixed-length array.

As for database of hash table, each key must be unique within a database, so it is impossible to store two or more records with a key overlaps. The following access methods are provided to the database: storing a record with a key and a value, deleting a record by a key, retrieving a record by a key. Moreover, traversal access to every key are provided, although the order is arbitrary. These access methods are similar to ones of DBM (or its followers: NDBM and GDBM) library defined in the UNIX standard. Tokyo Cabinet is an alternative for DBM because of its higher performance.

As for database of B+ tree, records whose keys are duplicated can be stored. Access methods of storing, deleting, and retrieving are provided as with the database of hash table. Records are stored in order by a comparison function assigned by a user. It is possible to access each record with the cursor in ascending or descending order. According to this mechanism, forward matching search for strings and range search for integers are realized.

As for database of fixed-length array, records are stored with unique natural numbers. It is impossible to store two or more records with a key overlaps. Moreover, the length of each record is limited by the specified length. Provided operations are the same as ones of hash database.

Table database is also provided as a variant of hash database. Each record is identified by the primary key and has a set of named columns. Although there is no concept of data schema, it is possible to search for records with complex conditions efficiently by using indices of arbitrary columns.

Setting

Install the latest version of Tokyo Cabinet beforehand and get the package of the Ruby binding of Tokyo Cabinet.

Enter the directory of the extracted package then perform installation.

 ruby extconf.rb
 make
 su
 make install

The package `tokyocabinet' should be loaded in each source file of application programs.

 require 'tokyocabinet'

All symbols of Tokyo Cabinet are defined in the module `TokyoCabinet'. You can access them without any prefix by including the module.

 include TokyoCabinet

EXAMPLE

The following code is an example to use a hash database.

 require 'tokyocabinet'
 include TokyoCabinet

 # create the object
 hdb = HDB::new

 # open the database
 if !hdb.open("casket.tch", HDB::OWRITER | HDB::OCREAT)
   ecode = hdb.ecode
   STDERR.printf("open error: %s\n", hdb.errmsg(ecode))
 end

 # store records
 if !hdb.put("foo", "hop") ||
     !hdb.put("bar", "step") ||
     !hdb.put("baz", "jump")
   ecode = hdb.ecode
   STDERR.printf("put error: %s\n", hdb.errmsg(ecode))
 end

 # retrieve records
 value = hdb.get("foo")
 if value
   printf("%s\n", value)
 else
   ecode = hdb.ecode
   STDERR.printf("get error: %s\n", hdb.errmsg(ecode))
 end

 # traverse records
 hdb.iterinit
 while key = hdb.iternext
   value = hdb.get(key)
   if value
     printf("%s:%s\n", key, value)
   end
 end

 # hash-like usage
 hdb["quux"] = "touchdown"
 printf("%s\n", hdb["quux"])
 hdb.each do |key, value|
   printf("%s:%s\n", key, value)
 end

 # close the database
 if !hdb.close
   ecode = hdb.ecode
   STDERR.printf("close error: %s\n", hdb.errmsg(ecode))
 end

The following code is an example to use a B+ tree database.

 require 'tokyocabinet'
 include TokyoCabinet

 # create the object
 bdb = BDB::new

 # open the database
 if !bdb.open("casket.tcb", BDB::OWRITER | BDB::OCREAT)
   ecode = bdb.ecode
   STDERR.printf("open error: %s\n", bdb.errmsg(ecode))
 end

 # store records
 if !bdb.put("foo", "hop") ||
     !bdb.put("bar", "step") ||
     !bdb.put("baz", "jump")
   ecode = bdb.ecode
   STDERR.printf("put error: %s\n", bdb.errmsg(ecode))
 end

 # retrieve records
 value = bdb.get("foo")
 if value
   printf("%s\n", value)
 else
   ecode = bdb.ecode
   STDERR.printf("get error: %s\n", bdb.errmsg(ecode))
 end

 # traverse records
 cur = BDBCUR::new(bdb)
 cur.first
 while key = cur.key
   value = cur.val
   if value
     printf("%s:%s\n", key, value)
   end
   cur.next
 end

 # hash-like usage
 bdb["quux"] = "touchdown"
 printf("%s\n", bdb["quux"])
 bdb.each do |key, value|
   printf("%s:%s\n", key, value)
 end

 # close the database
 if !bdb.close
   ecode = bdb.ecode
   STDERR.printf("close error: %s\n", bdb.errmsg(ecode))
 end

The following code is an example to use a fixed-length database.

 require 'tokyocabinet'
 include TokyoCabinet

 # create the object
 fdb = FDB::new

 # open the database
 if !fdb.open("casket.tcf", FDB::OWRITER | FDB::OCREAT)
   ecode = fdb.ecode
   STDERR.printf("open error: %s\n", fdb.errmsg(ecode))
 end

 # store records
 if !fdb.put(1, "one") ||
     !fdb.put(12, "twelve") ||
     !fdb.put(144, "one forty four")
   ecode = fdb.ecode
   STDERR.printf("put error: %s\n", fdb.errmsg(ecode))
 end

 # retrieve records
 value = fdb.get(1)
 if value
   printf("%s\n", value)
 else
   ecode = fdb.ecode
   STDERR.printf("get error: %s\n", fdb.errmsg(ecode))
 end

 # traverse records
 fdb.iterinit
 while key = fdb.iternext
   value = fdb.get(key)
   if value
     printf("%s:%s\n", key, value)
   end
 end

 # hash-like usage
 fdb[1728] = "seventeen twenty eight"
 printf("%s\n", fdb[1728])
 fdb.each do |key, value|
   printf("%s:%s\n", key, value)
 end

 # close the database
 if !fdb.close
   ecode = fdb.ecode
   STDERR.printf("close error: %s\n", fdb.errmsg(ecode))
 end

The following code is an example to use a table database.

 require 'tokyocabinet'
 include TokyoCabinet

 # create the object
 tdb = TDB::new

 # open the database
 if !tdb.open("casket.tct", TDB::OWRITER | TDB::OCREAT)
   ecode = tdb.ecode
   STDERR.printf("open error: %s\n", tdb.errmsg(ecode))
 end

 # store a record
 pkey = tdb.genuid
 cols = { "name" => "mikio", "age" => "30", "lang" => "ja,en,c" }
 if !tdb.put(pkey, cols)
   ecode = tdb.ecode
   STDERR.printf("get error: %s\n", tdb.errmsg(ecode))
 end

 # store another record
 cols = { "name" => "falcon", "age" => "31", "lang" => "ja", "skill" => "cook,blog" }
 if !tdb.put("x12345", cols)
   ecode = tdb.ecode
   STDERR.printf("get error: %s\n", tdb.errmsg(ecode))
 end

 # search for records
 qry = TDBQRY::new(tdb)
 qry.addcond("age", TDBQRY::QCNUMGE, "20")
 qry.addcond("lang", TDBQRY::QCSTROR, "ja,en")
 qry.setorder("name", TDBQRY::QOSTRASC)
 qry.setlimit(10)
 res = qry.search
 res.each do |rkey|
   rcols = tdb.get(rkey)
   printf("name:%s\n", rcols["name"])
 end

 # hash-like usage
 tdb["joker"] = { "name" => "ozma", "lang" => "en", "skill" => "song,dance" }
 printf("%s\n", tdb["joker"]["name"])
 tdb.each do |key, value|
   printf("%s:%s\n", key, value["name"])
 end

 # close the database
 if !tdb.close
   ecode = tdb.ecode
   STDERR.printf("close error: %s\n", tdb.errmsg(ecode))
 end

The following code is an example to use an abstract database.

 require 'tokyocabinet'
 include TokyoCabinet

 # create the object
 adb = ADB::new

 # open the database
 if !adb.open("casket.tch")
   STDERR.printf("open error\n")
 end

 # store records
 if !adb.put("foo", "hop") ||
     !adb.put("bar", "step") ||
     !adb.put("baz", "jump")
   STDERR.printf("put error\n")
 end

 # retrieve records
 value = adb.get("foo")
 if value
   printf("%s\n", value)
 else
   STDERR.printf("get error\n")
 end

 # traverse records
 adb.iterinit
 while key = adb.iternext
   value = adb.get(key)
   if value
     printf("%s:%s\n", key, value)
   end
 end

 # hash-like usage
 adb["quux"] = "touchdown"
 printf("%s\n", adb["quux"])
 adb.each do |key, value|
   printf("%s:%s\n", key, value)
 end

 # close the database
 if !adb.close
   STDERR.printf("close error\n")
 end

LICENSE

 Copyright (C) 2006-2010 FAL Labs
 All rights reserved.

Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Tokyo Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

Constants

VERSION = "x.y.z"   the version information
tokyocabinet-ruby-1.31/doc/fr_file_index.html0000644000175000017500000000117411547412351017522 0ustar spkspk Files [Tokyo Cabinet] tokyocabinet-ruby-1.31/doc/fr_class_index.html0000644000175000017500000000220111547412351017700 0ustar spkspk Classes [Tokyo Cabinet] tokyocabinet-ruby-1.31/doc/fr_method_index.html0000644000175000017500000003711011547412351020062 0ustar spkspk Methods [Tokyo Cabinet]

Methods

addcond (TokyoCabinet::TDBQRY)
adddouble (TokyoCabinet::BDB)
adddouble (TokyoCabinet::HDB)
adddouble (TokyoCabinet::FDB)
adddouble (TokyoCabinet::ADB)
adddouble (TokyoCabinet::TDB)
addint (TokyoCabinet::TDB)
addint (TokyoCabinet::FDB)
addint (TokyoCabinet::BDB)
addint (TokyoCabinet::ADB)
addint (TokyoCabinet::HDB)
close (TokyoCabinet::ADB)
close (TokyoCabinet::TDB)
close (TokyoCabinet::BDB)
close (TokyoCabinet::HDB)
close (TokyoCabinet::FDB)
copy (TokyoCabinet::ADB)
copy (TokyoCabinet::HDB)
copy (TokyoCabinet::BDB)
copy (TokyoCabinet::TDB)
copy (TokyoCabinet::FDB)
ecode (TokyoCabinet::BDB)
ecode (TokyoCabinet::HDB)
ecode (TokyoCabinet::TDB)
ecode (TokyoCabinet::FDB)
errmsg (TokyoCabinet::TDB)
errmsg (TokyoCabinet::FDB)
errmsg (TokyoCabinet::HDB)
errmsg (TokyoCabinet::BDB)
first (TokyoCabinet::BDBCUR)
fsiz (TokyoCabinet::FDB)
fsiz (TokyoCabinet::HDB)
fsiz (TokyoCabinet::TDB)
fsiz (TokyoCabinet::BDB)
fwmkeys (TokyoCabinet::TDB)
fwmkeys (TokyoCabinet::HDB)
fwmkeys (TokyoCabinet::ADB)
fwmkeys (TokyoCabinet::BDB)
genuid (TokyoCabinet::TDB)
get (TokyoCabinet::FDB)
get (TokyoCabinet::HDB)
get (TokyoCabinet::ADB)
get (TokyoCabinet::BDB)
get (TokyoCabinet::TDB)
getlist (TokyoCabinet::BDB)
hint (TokyoCabinet::TDBQRY)
iterinit (TokyoCabinet::ADB)
iterinit (TokyoCabinet::TDB)
iterinit (TokyoCabinet::FDB)
iterinit (TokyoCabinet::HDB)
iternext (TokyoCabinet::ADB)
iternext (TokyoCabinet::TDB)
iternext (TokyoCabinet::HDB)
iternext (TokyoCabinet::FDB)
jump (TokyoCabinet::BDBCUR)
key (TokyoCabinet::BDBCUR)
kwic (TokyoCabinet::TDBQRY)
last (TokyoCabinet::BDBCUR)
metasearch (TokyoCabinet::TDBQRY)
misc (TokyoCabinet::ADB)
new (TokyoCabinet::FDB)
new (TokyoCabinet::ADB)
new (TokyoCabinet::TDBQRY)
new (TokyoCabinet::BDB)
new (TokyoCabinet::BDBCUR)
new (TokyoCabinet::TDB)
new (TokyoCabinet::HDB)
next (TokyoCabinet::BDBCUR)
open (TokyoCabinet::FDB)
open (TokyoCabinet::HDB)
open (TokyoCabinet::BDB)
open (TokyoCabinet::TDB)
open (TokyoCabinet::ADB)
optimize (TokyoCabinet::FDB)
optimize (TokyoCabinet::HDB)
optimize (TokyoCabinet::ADB)
optimize (TokyoCabinet::TDB)
optimize (TokyoCabinet::BDB)
out (TokyoCabinet::HDB)
out (TokyoCabinet::BDB)
out (TokyoCabinet::BDBCUR)
out (TokyoCabinet::ADB)
out (TokyoCabinet::FDB)
out (TokyoCabinet::TDB)
outlist (TokyoCabinet::BDB)
path (TokyoCabinet::BDB)
path (TokyoCabinet::FDB)
path (TokyoCabinet::TDB)
path (TokyoCabinet::ADB)
path (TokyoCabinet::HDB)
prev (TokyoCabinet::BDBCUR)
proc (TokyoCabinet::TDBQRY)
put (TokyoCabinet::ADB)
put (TokyoCabinet::BDBCUR)
put (TokyoCabinet::TDB)
put (TokyoCabinet::FDB)
put (TokyoCabinet::HDB)
put (TokyoCabinet::BDB)
putasync (TokyoCabinet::HDB)
putcat (TokyoCabinet::ADB)
putcat (TokyoCabinet::FDB)
putcat (TokyoCabinet::HDB)
putcat (TokyoCabinet::BDB)
putcat (TokyoCabinet::TDB)
putdup (TokyoCabinet::BDB)
putkeep (TokyoCabinet::BDB)
putkeep (TokyoCabinet::FDB)
putkeep (TokyoCabinet::HDB)
putkeep (TokyoCabinet::TDB)
putkeep (TokyoCabinet::ADB)
putlist (TokyoCabinet::BDB)
range (TokyoCabinet::FDB)
range (TokyoCabinet::BDB)
rnum (TokyoCabinet::FDB)
rnum (TokyoCabinet::TDB)
rnum (TokyoCabinet::ADB)
rnum (TokyoCabinet::HDB)
rnum (TokyoCabinet::BDB)
search (TokyoCabinet::TDBQRY)
searchout (TokyoCabinet::TDBQRY)
setcache (TokyoCabinet::HDB)
setcache (TokyoCabinet::BDB)
setcache (TokyoCabinet::TDB)
setcmpfunc (TokyoCabinet::BDB)
setdfunit (TokyoCabinet::TDB)
setdfunit (TokyoCabinet::BDB)
setdfunit (TokyoCabinet::HDB)
setindex (TokyoCabinet::TDB)
setlimit (TokyoCabinet::TDBQRY)
setorder (TokyoCabinet::TDBQRY)
setxmsiz (TokyoCabinet::HDB)
setxmsiz (TokyoCabinet::BDB)
setxmsiz (TokyoCabinet::TDB)
size (TokyoCabinet::ADB)
sync (TokyoCabinet::HDB)
sync (TokyoCabinet::BDB)
sync (TokyoCabinet::TDB)
sync (TokyoCabinet::ADB)
sync (TokyoCabinet::FDB)
tranabort (TokyoCabinet::ADB)
tranabort (TokyoCabinet::HDB)
tranabort (TokyoCabinet::FDB)
tranabort (TokyoCabinet::TDB)
tranabort (TokyoCabinet::BDB)
tranbegin (TokyoCabinet::TDB)
tranbegin (TokyoCabinet::FDB)
tranbegin (TokyoCabinet::ADB)
tranbegin (TokyoCabinet::BDB)
tranbegin (TokyoCabinet::HDB)
trancommit (TokyoCabinet::ADB)
trancommit (TokyoCabinet::HDB)
trancommit (TokyoCabinet::TDB)
trancommit (TokyoCabinet::BDB)
trancommit (TokyoCabinet::FDB)
tune (TokyoCabinet::HDB)
tune (TokyoCabinet::BDB)
tune (TokyoCabinet::TDB)
tune (TokyoCabinet::FDB)
val (TokyoCabinet::BDBCUR)
vanish (TokyoCabinet::BDB)
vanish (TokyoCabinet::ADB)
vanish (TokyoCabinet::TDB)
vanish (TokyoCabinet::FDB)
vanish (TokyoCabinet::HDB)
vnum (TokyoCabinet::BDB)
vsiz (TokyoCabinet::FDB)
vsiz (TokyoCabinet::HDB)
vsiz (TokyoCabinet::BDB)
vsiz (TokyoCabinet::ADB)
vsiz (TokyoCabinet::TDB)
tokyocabinet-ruby-1.31/doc/rdoc-style.css0000644000175000017500000001051511547412351016635 0ustar spkspkbody { font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 90%; margin: 0; margin-left: 40px; padding: 0; background: white; color: black; } h1, h2, h3, h4 { margin: 0; background: transparent; } h1 { font-size: 150%; } h2,h3,h4 { margin-top: 1em; } :link, :visited { background: #eef; color: #039; text-decoration: none; } :link:hover, :visited:hover { background: #039; color: #eef; } /* Override the base stylesheet's Anchor inside a table cell */ td > :link, td > :visited { background: transparent; color: #039; text-decoration: none; } /* and inside a section title */ .section-title > :link, .section-title > :visited { background: transparent; color: #eee; text-decoration: none; } /* === Structural elements =================================== */ .index { margin: 0; margin-left: -40px; padding: 0; font-size: 90%; } .index :link, .index :visited { margin-left: 0.7em; } .index .section-bar { margin-left: 0px; padding-left: 0.7em; background: #ccc; font-size: small; } #classHeader, #fileHeader { width: auto; color: white; padding: 0.5em 1.5em 0.5em 1.5em; margin: 0; margin-left: -40px; border-bottom: 3px solid #006; } #classHeader :link, #fileHeader :link, #classHeader :visited, #fileHeader :visited { background: inherit; color: white; } #classHeader td, #fileHeader td { background: inherit; color: white; } #fileHeader { background: #057; } #classHeader { background: #048; } .class-name-in-header { font-size: 180%; font-weight: bold; } #bodyContent { padding: 0 1.5em 0 1.5em; } #description { padding: 0.5em 1.5em; background: #efefef; border: 1px dotted #999; } #description h1, #description h2, #description h3, #description h4, #description h5, #description h6 { color: #125; background: transparent; } #validator-badges { text-align: center; } #validator-badges img { border: 0; } #copyright { color: #333; background: #efefef; font: 0.75em sans-serif; margin-top: 5em; margin-bottom: 0; padding: 0.5em 2em; } /* === Classes =================================== */ table.header-table { color: white; font-size: small; } .type-note { font-size: small; color: #dedede; } .section-bar { color: #333; border-bottom: 1px solid #999; margin-left: -20px; } .section-title { background: #79a; color: #eee; padding: 3px; margin-top: 2em; margin-left: -30px; border: 1px solid #999; } .top-aligned-row { vertical-align: top } .bottom-aligned-row { vertical-align: bottom } #diagram img { border: 0; } /* --- Context section classes ----------------------- */ .context-row { } .context-item-name { font-family: monospace; font-weight: bold; color: black; } .context-item-value { font-size: small; color: #448; } .context-item-desc { color: #333; padding-left: 2em; } /* --- Method classes -------------------------- */ .method-detail { background: #efefef; padding: 0; margin-top: 0.5em; margin-bottom: 1em; border: 1px dotted #ccc; } .method-heading { color: black; background: #ccc; border-bottom: 1px solid #666; padding: 0.2em 0.5em 0 0.5em; } .method-signature { color: black; background: inherit; } .method-name { font-weight: bold; } .method-args { font-style: italic; } .method-description { padding: 0 0.5em 0 0.5em; } /* --- Source code sections -------------------- */ :link.source-toggle, :visited.source-toggle { font-size: 90%; } div.method-source-code { background: #262626; color: #ffdead; margin: 1em; padding: 0.5em; border: 1px dashed #999; overflow: auto; } div.method-source-code pre { color: #ffdead; } /* --- Ruby keyword styles --------------------- */ .standalone-code { background: #221111; color: #ffdead; overflow: auto; } .ruby-constant { color: #7fffd4; background: transparent; } .ruby-keyword { color: #00ffff; background: transparent; } .ruby-ivar { color: #eedd82; background: transparent; } .ruby-operator { color: #00ffee; background: transparent; } .ruby-identifier { color: #ffdead; background: transparent; } .ruby-node { color: #ffa07a; background: transparent; } .ruby-comment { color: #b22222; font-weight: bold; background: transparent; } .ruby-regexp { color: #ffa07a; background: transparent; } .ruby-value { color: #7fffd4; background: transparent; } tokyocabinet-ruby-1.31/doc/created.rid0000644000175000017500000000004011547412351016135 0ustar spkspkMon, 19 Jul 2010 15:13:57 +0900 tokyocabinet-ruby-1.31/doc/index.html0000644000175000017500000000125511547412351016034 0ustar spkspk Tokyo Cabinet tokyocabinet-ruby-1.31/tcbtest.rb0000644000175000017500000003271211547412351015271 0ustar spkspk#! /usr/bin/ruby -w #------------------------------------------------------------------------------------------------- # The test cases of the B+ tree database API # Copyright (C) 2006-2010 FAL Labs # This file is part of Tokyo Cabinet. # Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of # the GNU Lesser General Public License as published by the Free Software Foundation; either # version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope # that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. # You should have received a copy of the GNU Lesser General Public License along with Tokyo # Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA. #------------------------------------------------------------------------------------------------- require 'tokyocabinet' include TokyoCabinet # main routine def main ARGV.length >= 1 || usage if ARGV[0] == "write" rv = runwrite elsif ARGV[0] == "read" rv = runread elsif ARGV[0] == "remove" rv = runremove elsif ARGV[0] == "misc" rv = runmisc else usage end GC.start return rv end # print the usage and exit def usage STDERR.printf("%s: test cases of the B+ tree database API\n", $progname) STDERR.printf("\n") STDERR.printf("usage:\n") STDERR.printf(" %s write [-tl] [-td|-tb|-tt] [-nl|-nb] path rnum" + " [lmemb [nmemb [bnum [apow [fpow]]]]]\n", $progname) STDERR.printf(" %s read [-nl|-nb] path\n", $progname) STDERR.printf(" %s remove [-nl|-nb] path\n", $progname) STDERR.printf(" %s misc [-tl] [-td|-tb|-tt] [-nl|-nb] path rnum\n", $progname) STDERR.printf("\n") exit(1) end # print error message of B+ tree database def eprint(bdb, func) path = bdb.path STDERR.printf("%s: %s: %s: %s\n", $progname, path ? path : "-", func, bdb.errmsg) end # parse arguments of write command def runwrite path = nil rnum = nil lmemb = nil nmemb = nil bnum = nil apow = nil fpow = nil opts = 0 omode = 0 i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-tl" opts |= BDB::TLARGE elsif ARGV[i] == "-td" opts |= BDB::TDEFLATE elsif ARGV[i] == "-tb" opts |= BDB::TBZIP elsif ARGV[i] == "-tt" opts |= BDB::TTCBS elsif ARGV[i] == "-nl" omode |= BDB::ONOLCK elsif ARGV[i] == "-nb" omode |= BDB::OLCKNB else usage end elsif !path path = ARGV[i] elsif !rnum rnum = ARGV[i].to_i elsif !lmemb lmemb = ARGV[i].to_i elsif !nmemb nmemb = ARGV[i].to_i elsif !bnum bnum = ARGV[i].to_i elsif !apow apow = ARGV[i].to_i elsif !fpow fpow = ARGV[i].to_i else usage end i += 1 end usage if !path || !rnum || rnum < 1 lmemb = lmemb ? lmemb : -1 nmemb = nmemb ? nmemb : -1 bnum = bnum ? bnum : -1 apow = apow ? apow : -1 fpow = fpow ? fpow : -1 rv = procwrite(path, rnum, lmemb, nmemb, bnum, apow, fpow, opts, omode) return rv end # parse arguments of read command def runread path = nil omode = 0 i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-nl" omode |= BDB::ONOLCK elsif ARGV[i] == "-nb" omode |= BDB::OLCKNB else usage end elsif !path path = ARGV[i] else usage end i += 1 end usage if !path rv = procread(path, omode) return rv end # parse arguments of remove command def runremove path = nil omode = 0 i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-nl" omode |= BDB::ONOLCK elsif ARGV[i] == "-nb" omode |= BDB::OLCKNB else usage end elsif !path path = ARGV[i] else usage end i += 1 end usage if !path rv = procremove(path, omode) return rv end # parse arguments of misc command def runmisc path = nil rnum = nil opts = 0 omode = 0 i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-tl" opts |= BDB::TLARGE elsif ARGV[i] == "-td" opts |= BDB::TDEFLATE elsif ARGV[i] == "-tb" opts |= BDB::TBZIP elsif ARGV[i] == "-tt" opts |= BDB::TTCBS elsif ARGV[i] == "-nl" omode |= BDB::ONOLCK elsif ARGV[i] == "-nb" omode |= BDB::OLCKNB else usage end elsif !path path = ARGV[i] elsif !rnum rnum = ARGV[i].to_i else usage end i += 1 end usage if !path || !rnum || rnum < 1 rv = procmisc(path, rnum, opts, omode) return rv end # perform write command def procwrite(path, rnum, lmemb, nmemb, bnum, apow, fpow, opts, omode) printf("\n path=%s rnum=%d lmemb=%d nmemb=%d bnum=%d apow=%d fpow=%d" + " opts=%d omode=%d\n\n", path, rnum, lmemb, nmemb, bnum, apow, fpow, opts, omode) err = false stime = Time.now bdb = BDB::new if !bdb.tune(lmemb, nmemb, bnum, apow, fpow, opts) eprint(bdb, "tune") err = true end if !bdb.open(path, BDB::OWRITER | BDB::OCREAT | BDB::OTRUNC | omode) eprint(bdb, "open") err = true end for i in 1..rnum buf = sprintf("%08d", i) if !bdb.put(buf, buf) eprint(bdb, "put") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("record number: %d\n", bdb.rnum) printf("size: %d\n", bdb.fsiz) if !bdb.close eprint(bdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # perform read command def procread(path, omode) printf("\n path=%s omode=%d\n\n", path, omode) err = false stime = Time.now bdb = BDB::new if !bdb.open(path, BDB::OREADER | omode) eprint(bdb, "open") err = true end rnum = bdb.rnum for i in 1..rnum buf = sprintf("%08d", i) if !bdb.get(buf) eprint(bdb, "get") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("record number: %d\n", bdb.rnum) printf("size: %d\n", bdb.fsiz) if !bdb.close eprint(bdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # perform remove command def procremove(path, omode) printf("\n path=%s omode=%d\n\n", path, omode) err = false stime = Time.now bdb = BDB::new if !bdb.open(path, BDB::OWRITER | omode) eprint(bdb, "open") err = true end rnum = bdb.rnum for i in 1..rnum buf = sprintf("%08d", i) if !bdb.out(buf) eprint(bdb, "out") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("record number: %d\n", bdb.rnum) printf("size: %d\n", bdb.fsiz) if !bdb.close eprint(bdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # perform misc command def procmisc(path, rnum, opts, omode) printf("\n path=%s rnum=%d opts=%d omode=%d\n\n", path, rnum, opts, omode) err = false stime = Time.now bdb = BDB::new if !bdb.tune(10, 10, rnum / 50, 2, -1, opts) eprint(bdb, "tune") err = true end if !bdb.setcache(128, 256) eprint(bdb, "setcache") err = true end if !bdb.setxmsiz(rnum * 4) eprint(bdb, "setxmsiz") err = true end if !bdb.setdfunit(8) eprint(bdb, "setdfunit") err = true end if !bdb.open(path, BDB::OWRITER | BDB::OCREAT | BDB::OTRUNC | omode) eprint(bdb, "open") err = true end printf("writing:\n") for i in 1..rnum buf = sprintf("%08d", i) if !bdb.put(buf, buf) eprint(bdb, "put") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("reading:\n") for i in 1..rnum buf = sprintf("%08d", i) if !bdb.get(buf) eprint(bdb, "get") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("removing:\n") for i in 1..rnum buf = sprintf("%08d", i) if rand(2) == 0 && !bdb.out(buf) eprint(bdb, "out") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("checking cursor:\n") cur = BDBCUR::new(bdb) if !cur.first && bdb.ecode != BDB::ENOREC eprint(bdb, "cur::first") err = true end inum = 0 while key = cur.key value = cur.val if !value eprint(bdb, "cur::val") err = true end cur.next if inum > 0 && rnum > 250 && inum % (rnum / 250) == 0 print('.') if inum == rnum || inum % (rnum / 10) == 0 printf(" (%08d)\n", inum) end end inum += 1 end printf(" (%08d)\n", inum) if rnum > 250 if bdb.ecode != BDB::ENOREC || inum != bdb.rnum eprint(bdb, "(validation)") err = true end keys = bdb.fwmkeys("0", 10) if bdb.rnum >= 10 && keys.size != 10 eprint(bdb, "fwmkeys") err = true end printf("checking counting:\n") for i in 1..rnum buf = sprintf("[%d]", rand(rnum)) if rand(2) == 0 if !bdb.addint(buf, 1) && bdb.ecode != BDB::EKEEP eprint(bdb, "addint") err = true break end else if !bdb.adddouble(buf, 1) && bdb.ecode != BDB::EKEEP eprint(bdb, "adddouble") err = true break end end if i > 0 && rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end if !bdb.sync eprint(bdb, "sync") err = true end if !bdb.optimize eprint(bdb, "optimize") err = true end npath = path + "-tmp" if !bdb.copy(npath) eprint(bdb, "copy") err = true end File::unlink(npath) if !bdb.vanish eprint(bdb, "vanish") err = true end printf("random writing:\n") for i in 1..rnum buf = sprintf("%08d", rand(i)) if !bdb.putdup(buf, buf) eprint(bdb, "putdup") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("cursor updating:\n") for i in 1..rnum if rand(10) == 0 buf = sprintf("%08d", rand(rnum)) cur.jump(buf) for j in 1..10 key = cur.key break if !key if rand(3) == 0 cur.out else cpmode = BDBCUR::CPCURRENT + rand(3) cur.put(buf, cpmode) end cur.next j += 1 end end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end if !bdb.tranbegin eprint(bdb, "tranbegin") err = true end bdb.putdup("::1", "1") bdb.putdup("::2", "2a") bdb.putdup("::2", "2b") bdb.putdup("::3", "3") cur.jump("::2") cur.put("2A") cur.put("2-", BDBCUR::CPBEFORE) cur.put("2+") cur.next cur.next cur.put("mid", BDBCUR::CPBEFORE) cur.put("2C", BDBCUR::CPAFTER) cur.prev cur.out vals = bdb.getlist("::2") if !vals || vals.size != 4 eprint(bdb, "getlist") err = true end pvals = [ "hop", "step", "jump" ] if !bdb.putlist("::1", pvals) eprint(bdb, "putlist") err = true end if !bdb.outlist("::1") eprint(bdb, "outlist") err = true end if !bdb.trancommit eprint(bdb, "trancommit") err = true end if !bdb.tranbegin || !bdb.tranabort eprint(bdb, "tranbegin") err = true end printf("checking hash-like updating:\n") for i in 1..rnum buf = sprintf("[%d]", rand(rnum)) rnd = rand(4) if rnd == 0 bdb[buf] = buf + "hoge" elsif rnd == 1 value = bdb[buf] elsif rnd == 2 res = bdb.key?(buf) elsif rnd == 3 bdb.delete(buf) end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("checking hash-like iterator:\n") inum = 0 bdb.each do |tkey, tvalue| if inum > 0 && rnum > 250 && inum % (rnum / 250) == 0 print('.') if inum == rnum || inum % (rnum / 10) == 0 printf(" (%08d)\n", inum) end end inum += 1 end printf(" (%08d)\n", inum) if rnum > 250 bdb.clear printf("record number: %d\n", bdb.rnum) printf("size: %d\n", bdb.fsiz) if !bdb.close eprint(bdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # execute main STDOUT.sync = true $progname = $0.dup $progname.gsub!(/.*\//, "") srand exit(main) # END OF FILE tokyocabinet-ruby-1.31/makedoc.sh0000755000175000017500000000062511547412351015234 0ustar spkspk#! /bin/sh LANG=C LC_ALL=C PATH="$PATH:/usr/local/bin:$HOME/bin:.:.." export LANG LC_ALL PATH rm -rf doc rdoc --title "Tokyo Cabinet" -o doc tokyocabinet-doc.rb find doc -type f -name '*.html' | while read file do fgrep -v '[Validate]' "$file" | sed -e "s/’/'/g" -e 's/%%//g' > tmp.html mv -f tmp.html "$file" done rm -f tmp.html tokyocabinet-ruby-1.31/tcttest.rb0000644000175000017500000004346311547412351015320 0ustar spkspk#! /usr/bin/ruby -w #------------------------------------------------------------------------------------------------- # The test cases of the table database API # Copyright (C) 2006-2010 FAL Labs # This file is part of Tokyo Cabinet. # Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of # the GNU Lesser General Public License as published by the Free Software Foundation; either # version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope # that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. # You should have received a copy of the GNU Lesser General Public License along with Tokyo # Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA. #------------------------------------------------------------------------------------------------- require 'tokyocabinet' include TokyoCabinet # main routine def main ARGV.length >= 1 || usage if ARGV[0] == "write" rv = runwrite elsif ARGV[0] == "read" rv = runread elsif ARGV[0] == "remove" rv = runremove elsif ARGV[0] == "misc" rv = runmisc else usage end GC.start return rv end # print the usage and exit def usage STDERR.printf("%s: test cases of the table database API\n", $progname) STDERR.printf("\n") STDERR.printf("usage:\n") STDERR.printf(" %s write [-tl] [-td|-tb|-tt] [-ip|-is|-in|-it|-if|-ix] [-nl|-nb] path rnum" + " [bnum [apow [fpow]]]\n", $progname) STDERR.printf(" %s read [-nl|-nb] path\n", $progname) STDERR.printf(" %s remove [-nl|-nb] path\n", $progname) STDERR.printf(" %s misc [-tl] [-td|-tb|-tt] [-nl|-nb] path rnum\n", $progname) STDERR.printf("\n") exit(1) end # print error message of table database def eprint(tdb, func) path = tdb.path STDERR.printf("%s: %s: %s: %s\n", $progname, path ? path : "-", func, tdb.errmsg) end # parse arguments of write command def runwrite path = nil rnum = nil bnum = nil apow = nil fpow = nil opts = 0 iflags = 0 omode = 0 i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-tl" opts |= TDB::TLARGE elsif ARGV[i] == "-td" opts |= TDB::TDEFLATE elsif ARGV[i] == "-tb" opts |= TDB::TBZIP elsif ARGV[i] == "-tt" opts |= TDB::TTCBS elsif ARGV[i] == "-ip" iflags |= 1 << 0 elsif ARGV[i] == "-is" iflags |= 1 << 1 elsif ARGV[i] == "-in" iflags |= 1 << 2 elsif ARGV[i] == "-it" iflags |= 1 << 3 elsif ARGV[i] == "-if" iflags |= 1 << 4 elsif ARGV[i] == "-ix" iflags |= 1 << 5 elsif ARGV[i] == "-nl" omode |= TDB::ONOLCK elsif ARGV[i] == "-nb" omode |= TDB::OLCKNB else usage end elsif !path path = ARGV[i] elsif !rnum rnum = ARGV[i].to_i elsif !bnum bnum = ARGV[i].to_i elsif !apow apow = ARGV[i].to_i elsif !fpow fpow = ARGV[i].to_i else usage end i += 1 end usage if !path || !rnum || rnum < 1 bnum = bnum ? bnum : -1 apow = apow ? apow : -1 fpow = fpow ? fpow : -1 rv = procwrite(path, rnum, bnum, apow, fpow, opts, iflags, omode) return rv end # parse arguments of read command def runread path = nil omode = 0 i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-nl" omode |= TDB::ONOLCK elsif ARGV[i] == "-nb" omode |= TDB::OLCKNB else usage end elsif !path path = ARGV[i] else usage end i += 1 end usage if !path rv = procread(path, omode) return rv end # parse arguments of remove command def runremove path = nil omode = 0 i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-nl" omode |= TDB::ONOLCK elsif ARGV[i] == "-nb" omode |= TDB::OLCKNB else usage end elsif !path path = ARGV[i] else usage end i += 1 end usage if !path rv = procremove(path, omode) return rv end # parse arguments of misc command def runmisc path = nil rnum = nil opts = 0 omode = 0 i = 1 while i < ARGV.length if !path && ARGV[i] =~ /^-/ if ARGV[i] == "-tl" opts |= TDB::TLARGE elsif ARGV[i] == "-td" opts |= TDB::TDEFLATE elsif ARGV[i] == "-tb" opts |= TDB::TBZIP elsif ARGV[i] == "-tt" opts |= TDB::TTCBS elsif ARGV[i] == "-nl" omode |= TDB::ONOLCK elsif ARGV[i] == "-nb" omode |= TDB::OLCKNB else usage end elsif !path path = ARGV[i] elsif !rnum rnum = ARGV[i].to_i else usage end i += 1 end usage if !path || !rnum || rnum < 1 rv = procmisc(path, rnum, opts, omode) return rv end # perform write command def procwrite(path, rnum, bnum, apow, fpow, opts, iflags, omode) printf("\n path=%s rnum=%d bnum=%d apow=%d fpow=%d opts=%d iflags=%d" + " omode=%d\n\n", path, rnum, bnum, apow, fpow, opts, iflags, omode) err = false stime = Time.now tdb = TDB::new if !tdb.tune(bnum, apow, fpow, opts) eprint(tdb, "tune") err = true end if !tdb.open(path, TDB::OWRITER | TDB::OCREAT | TDB::OTRUNC | omode) eprint(tdb, "open") err = true end if (iflags & (1 << 0)) != 0 && !tdb.setindex("", TDB::ITDECIMAL) eprint(tdb, "setindex") err = true end if (iflags & (1 << 1)) != 0 && !tdb.setindex("str", TDB::ITLEXICAL) eprint(tdb, "setindex") err = true end if (iflags & (1 << 2)) != 0 && !tdb.setindex("num", TDB::ITDECIMAL) eprint(tdb, "setindex") err = true end if (iflags & (1 << 3)) != 0 && !tdb.setindex("type", TDB::ITDECIMAL) eprint(tdb, "setindex") err = true end if (iflags & (1 << 4)) != 0 && !tdb.setindex("flag", TDB::ITTOKEN) eprint(tdb, "setindex") err = true end if (iflags & (1 << 5)) != 0 && !tdb.setindex("text", TDB::ITQGRAM) eprint(tdb, "setindex") err = true end for i in 1..rnum id = tdb.genuid cols = { "str" => id, "num" => rand(id) + 1, "type" => rand(32) + 1, } vbuf = "" num = rand(5) pt = 0 for j in 1..num pt += rand(5) + 1 vbuf += "," if vbuf.length > 0 vbuf += pt.to_s end if vbuf.length > 0 cols["flag"] = vbuf cols["text"] = vbuf end if !tdb.put(id, cols) eprint(tdb, "put") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("record number: %d\n", tdb.rnum) printf("size: %d\n", tdb.fsiz) if !tdb.close eprint(tdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # perform read command def procread(path, omode) printf("\n path=%s omode=%d\n\n", path, omode) err = false stime = Time.now tdb = TDB::new if !tdb.open(path, TDB::OREADER | omode) eprint(tdb, "open") err = true end rnum = tdb.rnum for i in 1..rnum if !tdb.get(i) eprint(tdb, "get") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("record number: %d\n", tdb.rnum) printf("size: %d\n", tdb.fsiz) if !tdb.close eprint(tdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # perform remove command def procremove(path, omode) printf("\n path=%s omode=%d\n\n", path, omode) err = false stime = Time.now tdb = TDB::new if !tdb.open(path, TDB::OWRITER | omode) eprint(tdb, "open") err = true end rnum = tdb.rnum for i in 1..rnum if !tdb.out(i) eprint(tdb, "out") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("record number: %d\n", tdb.rnum) printf("size: %d\n", tdb.fsiz) if !tdb.close eprint(tdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # perform misc command def procmisc(path, rnum, opts, omode) printf("\n path=%s rnum=%d opts=%d omode=%d\n\n", path, rnum, opts, omode) err = false stime = Time.now tdb = TDB::new if !tdb.tune(rnum / 50, 2, -1, opts) eprint(tdb, "tune") err = true end if !tdb.setcache(rnum / 10, 128, 256) eprint(tdb, "setcache") err = true end if !tdb.setxmsiz(rnum * 4) eprint(tdb, "setxmsiz") err = true end if !tdb.setdfunit(8) eprint(tdb, "setdfunit") err = true end if !tdb.open(path, TDB::OWRITER | TDB::OCREAT | TDB::OTRUNC | omode) eprint(tdb, "open") err = true end if !tdb.setindex("", TDB::ITDECIMAL) eprint(tdb, "setindex") err = true end if !tdb.setindex("str", TDB::ITLEXICAL) eprint(tdb, "setindex") err = true end if !tdb.setindex("num", TDB::ITDECIMAL) eprint(tdb, "setindex") err = true end if !tdb.setindex("type", TDB::ITDECIMAL) eprint(tdb, "setindex") err = true end if !tdb.setindex("flag", TDB::ITTOKEN) eprint(tdb, "setindex") err = true end if !tdb.setindex("text", TDB::ITQGRAM) eprint(tdb, "setindex") err = true end printf("writing:\n") for i in 1..rnum id = tdb.genuid cols = { "str" => id, "num" => rand(id) + 1, "type" => rand(32) + 1, } vbuf = "" num = rand(5) pt = 0 for j in 1..num pt += rand(5) + 1 vbuf += "," if vbuf.length > 0 vbuf += pt.to_s end if vbuf.length > 0 cols["flag"] = vbuf cols["text"] = vbuf end if !tdb.put(id, cols) eprint(tdb, "put") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("reading:\n") for i in 1..rnum if !tdb.get(i) eprint(tdb, "get") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("removing:\n") for i in 1..rnum if rand(2) == 0 && !tdb.out(i) eprint(tdb, "out") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("checking iterator:\n") if !tdb.iterinit eprint(tdb, "iterinit") err = true end inum = 0 while pkey = tdb.iternext inum += 1 if !tdb.get(pkey) eprint(tdb, "get") err = true end if rnum > 250 && inum % (rnum / 250) == 0 print('.') if inum == rnum || inum % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf(" (%08d)\n", inum) if rnum > 250 if tdb.ecode != TDB::ENOREC || inum != tdb.rnum eprint(tdb, "(validation)") err = true end pkeys = tdb.fwmkeys("1", 10) printf("checking counting:\n") for i in 1..rnum buf = sprintf("i:%d", rand(rnum)) if rand(2) == 0 if !tdb.addint(buf, 1) eprint(tdb, "addint") err = true break end else if !tdb.adddouble(buf, 1) eprint(tdb, "adddouble") err = true break end end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end if !tdb.sync eprint(tdb, "sync") err = true end if !tdb.optimize eprint(tdb, "optimize") err = true end npath = path + "-tmp" if !tdb.copy(npath) eprint(tdb, "copy") err = true end Dir.glob("#{npath}.idx.*").each do |tpath| File.unlink(tpath) end File.unlink(npath) printf("searching:\n") qry = TDBQRY::new(tdb) names = [ "", "str", "num", "type", "flag", "text", "c1" ] ops = [ TDBQRY::QCSTREQ, TDBQRY::QCSTRINC, TDBQRY::QCSTRBW, TDBQRY::QCSTREW, TDBQRY::QCSTRAND, TDBQRY::QCSTROR, TDBQRY::QCSTROREQ, TDBQRY::QCSTRRX, TDBQRY::QCNUMEQ, TDBQRY::QCNUMGT, TDBQRY::QCNUMGE, TDBQRY::QCNUMLT, TDBQRY::QCNUMLE, TDBQRY::QCNUMBT, TDBQRY::QCNUMOREQ ] ftsops = [ TDBQRY::QCFTSPH, TDBQRY::QCFTSAND, TDBQRY::QCFTSOR, TDBQRY::QCFTSEX ] types = [ TDBQRY::QOSTRASC, TDBQRY::QOSTRDESC, TDBQRY::QONUMASC, TDBQRY::QONUMDESC ] for i in 1..rnum qry = TDBQRY::new(tdb) if rand(10) > 0 cnum = rand(4) for j in 1..cnum name = names[rand(names.length)] op = ops[rand(ops.length)] op = ftsops[rand(ftsops.length)] if rand(10) == 0 op |= TDBQRY::QCNEGATE if rand(20) == 0 op |= TDBQRY::QCNOIDX if rand(20) == 0 expr = rand(i).to_s expr += "," + rand(i).to_s if rand(10) == 0 expr += "," + rand(i).to_s if rand(10) == 0 qry.addcond(name, op, expr) end if rand(3) != 0 name = names[rand(names.length)] type = types[rand(types.length)] qry.setorder(name, type) end qry.setlimit(rand(i), rand(10)) if rand(3) != 0 res = qry.search if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end qry = TDBQRY::new(tdb) qry.addcond("", TDBQRY::QCSTRBW, "i:") qry.setorder("_num", TDBQRY::QONUMDESC) ires = qry.search irnum = ires.length itnum = tdb.rnum icnt = 0 rv = qry.proc do |tpkey, tcols| icnt += 1 tcols["icnt"] = icnt TDBQRY::QPPUT end if !rv eprint(tdb, "qry::proc") err = true end qry.addcond("icnt", TDBQRY::QCNUMGT, 0) mures = qry.metasearch([ qry, qry ], TDBQRY::MSUNION) if mures.length != irnum eprint(tdb, "qry::metasearch") err = true end mires = qry.metasearch([ qry, qry ], TDBQRY::MSISECT) if mires.length != irnum eprint(tdb, "qry::metasearch") err = true end mdres = qry.metasearch([ qry, qry ], TDBQRY::MSDIFF) if mdres.length != 0 eprint(tdb, "qry::metasearch") err = true end if !qry.searchout eprint(tdb, "qry::searchout") err = true end if tdb.rnum != itnum - irnum eprint(tdb, "(validation)") err = true end qry = TDBQRY::new(tdb) qry.addcond("text", TDBQRY::QCSTRBW, "1") qry.setlimit(100, 1) qry.search().each do |tpkey| cols = tdb.get(tpkey) if cols texts = qry.kwic(cols, "text", -1, TDBQRY::KWMUBRCT) if texts.length > 0 texts.each do |text| if !text.index("1") eprint(tdb, "(validation)") err = true break end end else eprint(tdb, "(validation)") err = true break end else eprint(tdb, "get") err = true break end end if !tdb.vanish eprint(tdb, "vanish") err = true end printf("checking transaction commit:\n") if !tdb.tranbegin eprint(tdb, "tranbegin") err = true end for i in 1..rnum id = rand(rnum) + 1 if rand(2) == 0 if !tdb.addint(id, 1) eprint(tdb, "addint") err = true break end else if !tdb.out(id) && tdb.ecode != TDB::ENOREC eprint(tdb, "out") err = true break end end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end if !tdb.trancommit eprint(tdb, "trancommit") err = true end printf("checking transaction abort:\n") ornum = tdb.rnum ofsiz = tdb.fsiz if !tdb.tranbegin eprint(tdb, "tranbegin") err = true end for i in 1..rnum id = rand(rnum) + 1 if rand(2) == 0 if !tdb.addint(id, 1) eprint(tdb, "addint") err = true break end else if !tdb.out(id) && tdb.ecode != TDB::ENOREC eprint(tdb, "out") err = true break end end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end if !tdb.tranabort eprint(tdb, "tranabort") err = true end if tdb.rnum != ornum || tdb.fsiz != ofsiz eprint(tdb, "(validation)") err = true end printf("checking hash-like updating:\n") for i in 1..rnum buf = sprintf("[%d]", rand(rnum)) rnd = rand(4) if rnd == 0 cols = { "name" => buf, "num" => i, } tdb[buf] = cols elsif rnd == 1 value = tdb[buf] elsif rnd == 2 tdb.key?(buf) elsif rnd == 3 tdb.delete(buf) end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("checking hash-like iterator:\n") inum = 0 tdb.each do |tkey, tvalue| if inum > 0 && rnum > 250 && inum % (rnum / 250) == 0 print('.') if inum == rnum || inum % (rnum / 10) == 0 printf(" (%08d)\n", inum) end end inum += 1 end printf(" (%08d)\n", inum) if rnum > 250 tdb.clear printf("record number: %d\n", tdb.rnum) printf("size: %d\n", tdb.fsiz) if !tdb.close eprint(tdb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # execute main STDOUT.sync = true $progname = $0.dup $progname.gsub!(/.*\//, "") srand exit(main) # END OF FILE tokyocabinet-ruby-1.31/tcatest.rb0000644000175000017500000002527511547412351015276 0ustar spkspk#! /usr/bin/ruby -w #------------------------------------------------------------------------------------------------- # The test cases of the abstract database API # Copyright (C) 2006-2010 FAL Labs # This file is part of Tokyo Cabinet. # Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of # the GNU Lesser General Public License as published by the Free Software Foundation; either # version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope # that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. # You should have received a copy of the GNU Lesser General Public License along with Tokyo # Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA. #------------------------------------------------------------------------------------------------- require 'tokyocabinet' include TokyoCabinet # main routine def main ARGV.length >= 1 || usage if ARGV[0] == "write" rv = runwrite elsif ARGV[0] == "read" rv = runread elsif ARGV[0] == "remove" rv = runremove elsif ARGV[0] == "misc" rv = runmisc else usage end GC.start return rv end # print the usage and exit def usage STDERR.printf("%s: test cases of the abstract database API\n", $progname) STDERR.printf("\n") STDERR.printf("usage:\n") STDERR.printf(" %s write name rnum\n", $progname) STDERR.printf(" %s read name\n", $progname) STDERR.printf(" %s remove name\n", $progname) STDERR.printf(" %s misc name rnum\n", $progname) STDERR.printf("\n") exit(1) end # print error message of abstract database def eprint(adb, func) path = adb.path STDERR.printf("%s: %s: %s: error\n", $progname, path ? path : "-", func) end # parse arguments of write command def runwrite name = nil rnum = nil i = 1 while i < ARGV.length if !name && ARGV[i] =~ /^-/ usage elsif !name name = ARGV[i] elsif !rnum rnum = ARGV[i].to_i else usage end i += 1 end usage if !name || !rnum || rnum < 1 rv = procwrite(name, rnum) return rv end # parse arguments of read command def runread name = nil i = 1 while i < ARGV.length if !name && ARGV[i] =~ /^-/ usage elsif !name name = ARGV[i] else usage end i += 1 end usage if !name rv = procread(name) return rv end # parse arguments of remove command def runremove name = nil i = 1 while i < ARGV.length if !name && ARGV[i] =~ /^-/ usage elsif !name name = ARGV[i] else usage end i += 1 end usage if !name rv = procremove(name) return rv end # parse arguments of misc command def runmisc name = nil rnum = nil i = 1 while i < ARGV.length if !name && ARGV[i] =~ /^-/ usage elsif !name name = ARGV[i] elsif !rnum rnum = ARGV[i].to_i else usage end i += 1 end usage if !name || !rnum || rnum < 1 rv = procmisc(name, rnum) return rv end # perform write command def procwrite(name, rnum) printf("\n name=%s rnum=%d\n\n", name, rnum) err = false stime = Time.now adb = ADB::new if !adb.open(name) eprint(adb, "open") err = true end for i in 1..rnum buf = sprintf("%08d", i) if !adb.put(buf, buf) eprint(adb, "put") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("record number: %d\n", adb.rnum) printf("size: %d\n", adb.size) if !adb.close eprint(adb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # perform read command def procread(name) printf("\n name=%s\n\n", name) err = false stime = Time.now adb = ADB::new if !adb.open(name) eprint(adb, "open") err = true end rnum = adb.rnum for i in 1..rnum buf = sprintf("%08d", i) if !adb.get(buf) eprint(adb, "get") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("record number: %d\n", adb.rnum) printf("size: %d\n", adb.size) if !adb.close eprint(adb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # perform remove command def procremove(name) printf("\n name=%s\n\n", name) err = false stime = Time.now adb = ADB::new if !adb.open(name) eprint(adb, "open") err = true end rnum = adb.rnum for i in 1..rnum buf = sprintf("%08d", i) if !adb.out(buf) eprint(adb, "out") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("record number: %d\n", adb.rnum) printf("size: %d\n", adb.size) if !adb.close eprint(adb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # perform misc command def procmisc(name, rnum) printf("\n name=%s rnum=%d\n\n", name, rnum) err = false stime = Time.now adb = ADB::new if !adb.open(name) eprint(adb, "open") err = true end printf("writing:\n") for i in 1..rnum buf = sprintf("%08d", i) if !adb.put(buf, buf) eprint(adb, "put") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("reading:\n") for i in 1..rnum buf = sprintf("%08d", i) if !adb.get(buf) eprint(adb, "get") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("removing:\n") for i in 1..rnum buf = sprintf("%08d", i) if rand(2) == 0 && !adb.out(buf) eprint(adb, "out") err = true break end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("checking iterator:\n") if !adb.iterinit eprint(adb, "iterinit") err = true end inum = 0 while key = adb.iternext value = adb.get(key) if !value eprint(adb, "get") err = true end if inum > 0 && rnum > 250 && inum % (rnum / 250) == 0 print('.') if inum == rnum || inum % (rnum / 10) == 0 printf(" (%08d)\n", inum) end end inum += 1 end printf(" (%08d)\n", inum) if rnum > 250 if inum != adb.rnum eprint(adb, "(validation)") err = true end keys = adb.fwmkeys("0", 10) if adb.rnum >= 10 && keys.size != 10 eprint(adb, "fwmkeys") err = true end printf("checking counting:\n") for i in 1..rnum buf = sprintf("[%d]", rand(rnum)) if rand(2) == 0 adb.addint(buf, 1) else adb.adddouble(buf, 1) end if i > 0 && rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("checking versatile functions:\n") for i in 1..rnum rnd = rand(3) if rnd == 0 name = "putlist" elsif rnd == 1 name = "outlist" else name = "getlist" end if !adb.misc(name, [rand(rnum), rand(rnum)]) eprint(adb, "(validation)") err = true end if i > 0 && rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end if !adb.sync eprint(adb, "sync") err = true end if !adb.optimize eprint(adb, "optimize") err = true end npath = adb.path + "-tmp" if !adb.copy(npath) eprint(adb, "copy") err = true end File::unlink(npath) if !adb.vanish eprint(adb, "vanish") err = true end printf("checking transaction commit:\n") if !adb.tranbegin eprint(adb, "tranbegin") err = true end for i in 1..rnum buf = sprintf("%d", rand(rnum)) if rand(2) == 0 if !adb.putcat(buf, buf) eprint(adb, "putcat") err = true break end else adb.out(buf) end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end if !adb.trancommit eprint(adb, "trancommit") err = true end printf("checking transaction abort:\n") ornum = adb.rnum osize = adb.size if !adb.tranbegin eprint(adb, "tranbegin") err = true end for i in 1..rnum buf = sprintf("%d", rand(rnum)) if rand(2) == 0 if !adb.putcat(buf, buf) eprint(adb, "putcat") err = true break end else adb.out(buf) end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end if !adb.tranabort eprint(adb, "trancommit") err = true end if adb.rnum != ornum || adb.size != osize eprint(adb, "(validation)") err = true end printf("checking hash-like updating:\n") for i in 1..rnum buf = sprintf("[%d]", rand(rnum)) rnd = rand(4) if rnd == 0 adb[buf] = buf elsif rnd == 1 value = adb[buf] elsif rnd == 2 res = adb.key?(buf) elsif rnd == 3 adb.delete(buf) end if rnum > 250 && i % (rnum / 250) == 0 print('.') if i == rnum || i % (rnum / 10) == 0 printf(" (%08d)\n", i) end end end printf("checking hash-like iterator:\n") inum = 0 adb.each do |tkey, tvalue| if inum > 0 && rnum > 250 && inum % (rnum / 250) == 0 print('.') if inum == rnum || inum % (rnum / 10) == 0 printf(" (%08d)\n", inum) end end inum += 1 end printf(" (%08d)\n", inum) if rnum > 250 adb.clear printf("record number: %d\n", adb.rnum) printf("size: %d\n", adb.size) if !adb.close eprint(adb, "close") err = true end printf("time: %.3f\n", Time.now - stime) printf("%s\n\n", err ? "error" : "ok") return err ? 1 : 0 end # execute main STDOUT.sync = true $progname = $0.dup $progname.gsub!(/.*\//, "") srand exit(main) # END OF FILE tokyocabinet-ruby-1.31/package.sh0000755000175000017500000000042111547412351015216 0ustar spkspk#! /bin/sh LANG=C LC_ALL=C PATH="$PATH:/usr/local/bin:$HOME/bin:.:.." export LANG LC_ALL PATH if [ -f Makefile ] then make distclean fi rm -rf casket casket* *~ *.tmp *.gem hoge moge name="${PWD##*/}" cd .. if [ -d "$name" ] then tar zcvf "$name.tar.gz" "$name" fi tokyocabinet-ruby-1.31/MANIFEST0000644000175000017500000000037511547412351014425 0ustar spkspkMANIFEST extconf.rb tokyocabinet.c tokyocabinet-doc.rb tchtest.rb tcbtest.rb tcftest.rb tcttest.rb tcatest.rb test.rb memsize.rb example/tchdbex.rb example/tcbdbex.rb example/tcfdbex.rb example/tctdbex.rb example/tcadbex.rb tokyocabinet.gemspec COPYING