sparkey-go
is cgo bindings around the sparkey
library.
sparkey
is a disk-based hash table, optimized for bulk writes and fast reads. It keeps two files on disk: a log file (e.g. "blargh.spl"), and an index file (e.g. "blargh.spi").
First install the sparkey
library:
- in OSX:
brew install sparkey
- in Unix: build from source
go get github.com/tiegz/sparkey-go
dep ensure -add github.com/tiegz/sparkey-go
import "github.com/tiegz/sparkey-go"
s := sparkey.New("sparkey_db", sparkey.COMPRESSION_NONE, 1024)
s.Put("first", "Hello")
s.Put("second", "Worlb")
s.Put("third", "Goodbye")
s.Put("fourth", "EOM")
s.Flush()
s.Delete("third")
s.Flush()
fmt.Printf("First value is %s", s.Get("first"))
// Hello
s.ForEachHash(func(k, v string) {
fmt.Printf("%s: %s\n", k, v)
})
// first: Hello
// second: Worlb
// fourth: EOM
s.PrettyPrintHash();
// {
// first => Hello
// second => Worlb
// fourth => EOM
// }
fmt.Printf("Sparkey info:\n\n")
fmt.Printf(" Basename:\t\t%s\n", s.Basename)
fmt.Printf(" CompressionType:\t\t%d\n", s.CompressionType)
fmt.Printf(" Size:\t\t%d\n", s.Size())
fmt.Printf(" LogWriter.CompressionType:\t\t%d\n", s.CompressionType)
fmt.Printf(" LogWriter.BlockSize:\t\t%d\n", s.BlockSize)
fmt.Printf(" MaxKeyLen:\t\t%d\n", s.MaxKeyLen())
fmt.Printf(" MaxValueLen:\t\t%d\n", s.MaxValueLen())
s.Close()
// Sparkey info:
//
// Basename: sparkey_db
// CompressionType: 0
// Size: 3
// LogWriter.CompressionType: 0
// LogWriter.BlockSize: 1024
// MaxKeyLen: 6
// MaxValueLen: 7
cd sparkey
go test -v .
cd sparkey
go test -bench=. -v