BadgerDB
|
The files in this package are organized under the following hierarchy:
docs/ generated documentation src/ code for BadgerDB
You will likely be most interested in src
To build and run the system, you need the following packages:
The build system is configured to work on CSL RedHat 5 and 6 machines out of the box.
All command examples are meant to be run at the command prompt from the badgerdb
directory. When executing a command, omit the $
prompt (so “$ make
” means you just type “make
” and press enter).
To build the executable:
To run the executable, first build the code, then run:
If you want to edit what badgerdb_main
does, edit src/main.cpp
.
Documentation is generated by using Doxygen. If you have updated the documentation and need to regenerate the output files, run:
Resulting documentation will be placed in the docs/
directory; open index.html
with your web browser to view it.
Interaction with the underlying filesystem is handled by two classes: File and Page. Files store zero or more fixed-length pages; each page holds zero or more variable-length records.
Record data is represented using std::strings of arbitrary characters.
Files must first be created before they can be used:
If you want to open an existing file, use File::open like so:
Multiple File objects share the same stream to the underlying file. The stream will be automatically closed when the last File object is out of scope; no explicit close command is necessary.
You can delete a file with File::remove:
Data is added to a File by first allocating a Page, populating it with data, and then writing the Page back to the File.
For example:
Pages are read back from a File using their page numbers:
You can also iterate through all pages in the File:
Pages hold variable-length records containing arbitrary data.
To insert data on a page:
Data is read by using RecordIds, which are provided when data is inserted:
As Pages use std::string to represent data, it's very natural to insert strings; however, any data can be stored:
Note that serializing structures like this is not industrial strength; it's better to use something like Google's protocol buffers or Boost serialization.
You can also iterate through all records in the Page: