https://github.com/opencoff/go-cdb
DJB's Constant DB - with changes to add sha256 checksum to the generated DB
https://github.com/opencoff/go-cdb
Last synced: 10 months ago
JSON representation
DJB's Constant DB - with changes to add sha256 checksum to the generated DB
- Host: GitHub
- URL: https://github.com/opencoff/go-cdb
- Owner: opencoff
- License: mit
- Created: 2018-02-28T21:53:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-28T22:09:21.000Z (over 8 years ago)
- Last Synced: 2025-04-01T11:08:57.775Z (about 1 year ago)
- Language: Go
- Size: 8.79 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
CDB
===
[](https://godoc.org/github.com/colinmarc/cdb) [](https://travis-ci.org/colinmarc/hdfs)
This is a native Go implementation of [cdb][1], a constant key/value database
with some very nice properties. From the [design doc][1]:
> 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 2048 bytes, plus 24 bytes per record, plus the space for keys and data.
> - No random limits: cdb can handle any database up to 4 gigabytes. There are no other restrictions; records don't even have to fit into memory. Databases are stored in a machine-independent format.
This version is modified by Sudhi Herle:
- addition of a SHA256 checksum over the entire CDB (appended to end
of file) and verified when opened
- uses Zi Long Tan's superfast hash
[1]: http://cr.yp.to/cdb.html
Usage
-----
```go
writer, err := cdb.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)
}
```