Code Monkey home page Code Monkey logo

db's Introduction

A New DBM in Pure C


Demo:
=====
db_t db;
db_option_t option;

option.table  = 256;	/* table number,keep this small if data not too much */
option.bucket = 256;    /* initialize bucket number in per table,will incrase when key add */
option.rdonly = 0;
if (db_open(&db, /* data file */ "foo.db", /* index file */ "foo.db", &option) != DB_OK) {
        fprintf(stderr, "open db failed\n");
        return 0;
}

if (db_put(&db, "hi", strlen(...), "hello,world", strlen(...)) != DB_OK) {
        fprintf(stderr, "NOT OK\n");
}

if ((len = db_get(&db, "hi", strlen(...), val, sizeof(val))) == 0) {
        fprintf(stderr, "NOT FOUND\n");
}

db_close(&db);


Limited:
========

In 32 bit platform database file size is limited 4GiB*

Key/Value length is 32 bit unsigned int

*Depends Your Operation System,Mostly can't get 4GiB map


Design:
=======

                +----------+
                |          |
                |  header  |
                |          |
                +----------+
                | table[0] |---------+
                +----------+         |
                | table[1] |------------+
                +----------+         |  |
                | table[2] |         |  |
                +----------+         |  |
                |    .     |         |  |
                |    .     |         |  |
                |    .     |         |  |
                +----------+         |  |
                | table[N] |         |  |
                +----------+         |  |
          +-----| bucket[0]|<--------|  |
          |     +----------+            |
          |     | bucket[1]|            |
          |     +----------+            |
       +--------| bucket[2]|            |
       |  |     +----------+            |
       |  |     |    .     |            |
       |  |     |    .     |<-----------+
       |  |     |    .     |
       |  |     +----------+
       |  |     | bucket[N]|
       |  |     +----------+
       |  +---->|   klen   |
       |        +----------+
       |        |   vlen   |
       |        +----------+
       |        |    .     |
       |        |   klen   |
       |        |  bytes   |
       |        |    .     |
       |        +----------+
       |        |    .     |
       |        |   vlen   |
       |        |  bytes   |
       |        |    .     |
       |        +----------+
       +------->|   klen   |
                +----------+
                |   vlen   |
                +----------+
                |    .     |
                |   klen   |
                |  bytes   |
                |    .     |
                +----------+
                |    .     |
                |   vlen   |
                |  bytes   |
                |    .     |
                +----------+
                |    .     |
                |    .     |
                |    .     |
                +----------+


Goal:
=====

Keep it simple, stupid

Next Release will has Dynamic Hash Implementation*
And Mmap Maybe not required.

*Litwin, Witold (1980), "Linear hashing: A new tool for file and table addressing"


FAQ:
====

Q: Do you use `mmap'? What if I don't want use `mmap'?
A: Yes.Just use others,there is a lot of key/value database you can choose.

Q: I tried this library,It's waste to much disk space and memory!
A: I'll write compaction function later,will reduce disk space in high update application,you can use db-export and db-import to a new database file.The future compaction function will do same thing.Memory is control by the kernel,Sorry.

Q: Compression?
A: Maybe.

Q: Encryption?
A: Maybe.

Q: I use this in my Web Server,I have a problem!
A: Please contact the author.

Q: I use this in my Mobile Phone,I have a problem!
A: Please contact the author.

Q: I want do X,Will be OK?
A: Just try.If don't,Please contact the author.

Q: I have a problem!
A: Please contact the author.


License:
========

Public Domain License

db's People

Contributors

zhicheng avatar

Watchers

weimingtom avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.