APBCDB
Download Latest Version.
APBCDB is a constant key-value database library. That means:
- constant - You generate a database once, then look up keys in it. You cannot mix reads and writes.
- key-value - Apbcdb stores key-value pairs.
- Both keys and values are strings (byte sequences).
- Any richer structure in values must be imposed by the application.
- Values can only be retrieved by primary key.
- library - Apbcdb is a library for C programmers. It cannot be used directly by users.
Advantages
- Fast lookups.
- Multiple readers can share the db efficiently.
- UTF-8 safe and binary-safe. Merely stores byte sequences.
- C API for DB creation.
- Clear, maintainable code.
- Permissive license.
Performance
Benchmarked as follows:
- 1.8 GHz machine; 1GB RAM
- Lookup keys were randomly distributed.
- 50% of lookup keys were present in the database.
The performance goes down as the number of keys in the database increases:
| # KEYS | LOOKUPS/SEC |
| 10k | 1.8M |
| 100k | 779k |
| 1M | 684k |
How to use APBCDB
General
- Include apbcdb.h
- All functions return a result code.
- Always check it.
- If it's nonzero, it's one of the errors listed in the header file.
- Don't proceed past an error result.
- Add the apbcdb directory to your project and link with:
- apbcdb_writer.o
- apbcdb_reader.o
- apbindex/apbindex.o
Creating a DB
apbcdb_writer w;
int rc;
rc = apbcdb_begin_write(&w, "phonebook.dat");
rc = apbcdb_add_entry(&w, strlen("Bob Smith"), "Bob Smith",
strlen("408.921.9191"), "408.921.9191");
rc = apbcdb_add_entry(&w, strlen("Jen Rapp"), "Jen Rapp",
strlen("714.334.5543"), "714.334.5543");
rc = apbcdb_end_write(&w);
/* this creates phonebook.dat.idx; both files must be present to read */
Reading a DB
apbcdb_reader r;
int rc;
char val[0x400];
uint vallen;
rc = apbcdb_ropen(&r, "phonebook.dat");
vallen = sizeof(val);
rc = apbcdb_get(&r, "Bob Smith", strlen("Bob Smith"), val, &vallen);
/* now val contains Bob's phone number, and vallen contains the
* phone number's length */
rc = apbcdb_rclose(&r);
Download
Latest Version
asher@wildsparx.com