文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
3.1 Tokyo Products
http://1978th.net/tokyocabinet/tokyoproducts.pdf
概述:
Tokyo Cabinet – database library
Tokyo Tyrant – database server
Tokyo Dystopia – full-text search engine
Tokyo Promenade – content management system
open source – released under LGPL
powerful, portable, practical – written in the standard C, optimized to POSIX
下图为 Tokyo Products
图 10 Tokyo Products
TC 实现
TC: database library. ( libtokyocabinet.so )
支持各种 storage 方式。
- hash (hdb)
- B+ tree (bdb)
- array: fixed-len (adb)
- table (tdb)
- …
Eg., B+tree db object:
tcbdbopen, tcbdbput2, tcbdbget2, #tcbdbcurnew, tcbdbclose
测试程序:(perl, Ruby…)
http://1978th.net/tokyocabinet/perldoc/#example
Example Code:
// Makefile: gcc tctest.c -ltokyocabinet
#include <tcutil.h>
#include <tchdb.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
int main(int argc, char **argv)
{
TCHDB *hdb;
int ecode;
char *key, *value;
/* create the object */
hdb = tchdbnew();
/* open the database */
if(!tchdbopen(hdb, "casket.hdb", HDBOWRITER | HDBOCREAT)) {
ecode = tchdbecode(hdb);
fprintf(stderr, "open error: %s¥n", tchdberrmsg(ecode));
}
/* store records */
if(!tchdbput2(hdb, "foo", "hop") ||
!tchdbput2(hdb, "bar", "step") ||
!tchdbput2(hdb, "baz", "jump")) {
ecode = tchdbecode(hdb);
fprintf(stderr, "put error: %s¥n", tchdberrmsg(ecode));
}
/* retrieve records */
value = tchdbget2(hdb, "foo");
if(value) {
printf("%s¥n", value);
free(value);
} else {
ecode = tchdbecode(hdb);
//fprintf(printf(stderr, "get error: %s/n", tchdberrmsg(ecode));
}
/* traverse records */
tchdbiterinit(hdb);
while((key = tchdbiternext2(hdb)) != NULL) {
value = tchdbget2(hdb, key);
if(value) {
printf("%s:%s¥n", key, value);
free(value);
}
free(key);
}
/* close the database */
if(!tchdbclose(hdb)) {
ecode = tchdbecode(hdb);
fprintf(stderr, "close error: %s¥n", tchdberrmsg(ecode));
}
/* delete the object */
tchdbdel(hdb);
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论