Skip to content

Instantly share code, notes, and snippets.

@yannick
Created July 7, 2013 20:48
Show Gist options
  • Select an option

  • Save yannick/5944888 to your computer and use it in GitHub Desktop.

Select an option

Save yannick/5944888 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/binary"
"fmt"
"github.com/jmhodges/levigo"
)
func main() {
fmt.Println("open db")
opts := levigo.NewOptions()
opts.SetCreateIfMissing(true)
opts.SetWriteBufferSize(215343360)
//opts.SetCache(levigo.NewLRUCache(3<<30))
db, err := levigo.Open("./db", opts)
if err != nil {
fmt.Println(err)
}
wo := levigo.NewWriteOptions()
ro := levigo.NewReadOptions()
var written int
var buf []byte
var count uint64
buf = make([]byte, 8)
for count = 0; count < 10000000; count++ {
written = binary.PutUvarint(buf, count)
if count%1000000 == 0 {
fmt.Println(count)
fmt.Println(written)
}
err = db.Put(wo, buf[:written], buf[:written])
if err != nil {
fmt.Println(err)
}
}
buf = make([]byte, 8)
written = binary.PutUvarint(buf, 99999)
fmt.Printf("bytes written: %d \n%d\n", written, buf)
data, err := db.Get(ro, buf[:written])
if err != nil {
fmt.Println(err)
}
fmt.Printf("data: %d \n ", data)
res, bread := binary.Uvarint(data)
fmt.Printf("bytes read: %d \n", bread)
fmt.Printf("found key: %d \n", res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment