All Projects → chrislusf → cdb64

chrislusf / cdb64

Licence: other
A pure Go implmentation of CDB, but without 4GB size limit.

Programming Languages

go
31211 projects - #10 most used programming language

CDB64

This is a native Go implementation of cdb, a constant key/value database with some very nice properties, but without the 4GB size limit.

Adapted from the original design doc:

cdb is a fast, reliable, simple package for creating and reading constant databases. Its database structure provides several features:

  • Fast lookups: A successful lookup in a large database normally takes just two disk accesses. An unsuccessful lookup takes only one.
  • Low overhead: A database uses 4096 bytes, plus 32 bytes per record, plus the space for keys and data.
  • No random limits: cdb can handle any database up to 16 exabytes. There are no other restrictions; records don't even have to fit into memory. Databases are stored in a machine-independent format.

This repo is based on https://github.com/colinmarc/cdb

Usage

writer, err := cdb64.Create("/tmp/example.cdb")
if err != nil {
  log.Fatal(err)
}

// Write some key/value pairs to the database.
writer.Put([]byte("Alice"), []byte("Practice"))
writer.Put([]byte("Bob"), []byte("Hope"))
writer.Put([]byte("Charlie"), []byte("Horse"))

// Freeze the database, and open it for reads.
db, err := writer.Freeze()
if err != nil {
  log.Fatal(err)
}

// Fetch a value.
v, err := db.Get([]byte("Alice"))
if err != nil {
  log.Fatal(err)
}

log.Println(string(v))
// => Practice

// Iterate over the database
iter := db.Iter()
for iter.Next() {
    log.Printf("The key %s has a value of length %d\n", string(iter.Key()), len(iter.Value()))
}

if err := iter.Err(); err != nil {
    log.Fatal(err)
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].