B + -tree drive based implementation with fixed size keys and values

Is there any library that provides a disk-based B + -tree implementation specifically designed for a scenario in which all keys have a fixed size and all values ​​have a fixed size (not necessarily the same fixed size as the keys)

Note: Yes, I want to implement another toy, RDBMS with proof of concept. And a very good reason why I do not use SQL DBMS. The end of the note.

I especially don't like the language the library is written in. However, I have some specific requirements regarding the functionality of the library. For clarity, these requirements will be illustrated by examples written in C.

The library must be flexible enough so that I can use my own comparison function. For instance:

struct comparer { void * extra; int (*function)( void *, // closure over extra char *, // 1st value to be compared char * // 2nd value to be compared ); }; 

The mechanism for managing the index file is determined by a fixed length for all keys, a fixed length for all values, and a comparison function for keys. For instance:

 struct index_spec { size_t keylen, vallen; // fixed lengths for keys and values struct comparer comp; // comparison function for keys }; 

It would be very nice to touch (although not necessarily) if the library has established the difference between queries and updated indexes and the mechanism for using the updated index when the expected request is expected, but not vice versa. For instance:

 struct queryable_index { struct index_spec spec; FILE * file; // opened in read mode }; struct updateable_index { struct index_spec spec; FILE * file; // opened in read/write mode }; struct queryable_index open_queryable_index (struct index_spec, const char *); struct updateable_index open_updateable_index (struct index_spec spec, const char * filename); struct queryable_index just_queryable_index (struct updateable_index index) { struct queryable_index result; result.spec = index.spec; result.file = index.file; return result; } 
+4
source share
2 answers

The best implementation I know of is Berkeley DB . It is a high-performance embedded database system with very good B-tree implementations developed by Sleepycat and then acquired by Oracle.

It is written in C and supports the use cases that you use. It is open source, and the code is a very good place to find inspiration if you want to create your own implementation.

Good luck

+2
source

LevelDB: "The leveldb library provides persistent key storage. The keys and values ​​are arbitrary byte arrays. The keys are sorted into the key value storage according to the user-defined comparator function."

https://github.com/google/leveldb/blob/master/doc/index.md

+1
source

All Articles