本文整理匯總了Golang中C.leveldb_free函數的典型用法代碼示例。如果您正苦於以下問題:Golang leveldb_free函數的具體用法?Golang leveldb_free怎麽用?Golang leveldb_free使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了leveldb_free函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetApproximateSizes
// GetApproximateSizes returns the approximate number of bytes of file system
// space used by one or more key ranges.
//
// The keys counted will begin at Range.Start and end on the key before
// Range.Limit.
func (db *DB) GetApproximateSizes(ranges []Range) []uint64 {
starts := make([]*C.char, len(ranges))
limits := make([]*C.char, len(ranges))
startLens := make([]C.size_t, len(ranges))
limitLens := make([]C.size_t, len(ranges))
for i, r := range ranges {
starts[i] = C.CString(string(r.Start))
startLens[i] = C.size_t(len(r.Start))
limits[i] = C.CString(string(r.Limit))
limitLens[i] = C.size_t(len(r.Limit))
}
sizes := make([]uint64, len(ranges))
numranges := C.int(len(ranges))
startsPtr := &starts[0]
limitsPtr := &limits[0]
startLensPtr := &startLens[0]
limitLensPtr := &limitLens[0]
sizesPtr := (*C.uint64_t)(&sizes[0])
C.go_leveldb_approximate_sizes(
db.Ldb, numranges, startsPtr, startLensPtr,
limitsPtr, limitLensPtr, sizesPtr)
for i := range ranges {
C.leveldb_free(unsafe.Pointer(starts[i]))
C.leveldb_free(unsafe.Pointer(limits[i]))
}
return sizes
}
示例2: DestroyDatabase
// DestroyDatabase removes a database entirely, removing everything from the
// filesystem.
func DestroyDatabase(dbname string, o *Options) error {
var errStr *C.char
ldbname := C.CString(dbname)
defer C.leveldb_free(unsafe.Pointer(ldbname))
C.leveldb_destroy_db(o.Opt, ldbname, &errStr)
if errStr != nil {
gs := C.GoString(errStr)
C.leveldb_free(unsafe.Pointer(errStr))
return DatabaseError(gs)
}
return nil
}
示例3: Open
// Open opens a database.
//
// Creating a new database is done by calling SetCreateIfMissing(true) on the
// Options passed to Open.
//
// It is usually wise to set a Cache object on the Options with SetCache to
// keep recently used data from that database in memory.
func Open(dbname string, o *Options) (*DB, error) {
var errStr *C.char
ldbname := C.CString(dbname)
defer C.leveldb_free(unsafe.Pointer(ldbname))
leveldb := C.leveldb_open(o.Opt, ldbname, &errStr)
if errStr != nil {
gs := C.GoString(errStr)
C.leveldb_free(unsafe.Pointer(errStr))
return nil, DatabaseError(gs)
}
return &DB{leveldb}, nil
}
示例4: Put
// Put writes data associated with a key to the database.
//
// If a nil []byte is passed in as value, it will be returned by Get
// as an zero-length slice. The WriteOptions passed in can be reused
// by multiple calls to this and if the WriteOptions is left unchanged.
//
// The key and value byte slices may be reused safely. Put takes a copy of
// them before returning.
func (db *DB) Put(wo *WriteOptions, key, value []byte) error {
var errStr *C.char
// leveldb_put, _get, and _delete call memcpy() (by way of Memtable::Add)
// when called, so we do not need to worry about these []byte being
// reclaimed by GC.
var k, v *C.char
if len(key) != 0 {
k = (*C.char)(unsafe.Pointer(&key[0]))
}
if len(value) != 0 {
v = (*C.char)(unsafe.Pointer(&value[0]))
}
lenk := len(key)
lenv := len(value)
C.leveldb_put(
db.Ldb, wo.Opt, k, C.size_t(lenk), v, C.size_t(lenv), &errStr)
if errStr != nil {
gs := C.GoString(errStr)
C.leveldb_free(unsafe.Pointer(errStr))
return DatabaseError(gs)
}
return nil
}
示例5: saveError
func saveError(errStr *C.char) error {
if errStr != nil {
gs := C.GoString(errStr)
C.leveldb_free(unsafe.Pointer(errStr))
return fmt.Errorf(gs)
}
return nil
}
示例6: Delete
func (db *LevelDB) Delete(key string) (err error) {
opt := C.leveldb_writeoptions_create() // write option
defer C.leveldb_free(unsafe.Pointer(opt))
k := C.CString(key) // copy
defer C.leveldb_free(unsafe.Pointer(k))
var cerr *C.char
C.leveldb_delete(db.CLevelDB, opt, k, C.size_t(len(key)), &cerr)
if cerr != nil {
defer C.leveldb_free(unsafe.Pointer(cerr))
return errors.New(C.GoString(cerr))
}
return
}
示例7: Write
// Write atomically writes a WriteBatch to disk. The WriteOptions
// passed in can be reused by multiple calls to this and other methods.
func (db *DB) Write(wo *WriteOptions, w *WriteBatch) error {
var errStr *C.char
C.leveldb_write(db.Ldb, wo.Opt, w.wbatch, &errStr)
if errStr != nil {
gs := C.GoString(errStr)
C.leveldb_free(unsafe.Pointer(errStr))
return DatabaseError(gs)
}
return nil
}
示例8: GetError
// GetError returns an IteratorError from LevelDB if it had one during
// iteration.
//
// This method is safe to call when Valid returns false.
func (it *Iterator) GetError() error {
var errStr *C.char
C.leveldb_iter_get_error(it.Iter, &errStr)
if errStr != nil {
gs := C.GoString(errStr)
C.leveldb_free(unsafe.Pointer(errStr))
return IteratorError(gs)
}
return nil
}
示例9: OpenLevelDB
// Open LevelDB with given name
func OpenLevelDB(path string) (leveldb *LevelDB, err error) {
cpath := C.CString(path) // convert path to c string
defer C.leveldb_free(unsafe.Pointer(cpath))
// allocate LevelDB Option struct to open
opt := C.leveldb_options_create()
defer C.leveldb_free(unsafe.Pointer(opt))
// set open option
C.leveldb_options_set_create_if_missing(opt, C.uchar(1))
// open leveldb
var cerr *C.char
cleveldb := C.leveldb_open(opt, cpath, &cerr)
if cerr != nil {
defer C.leveldb_free(unsafe.Pointer(cerr))
return nil, errors.New(C.GoString(cerr))
}
return &LevelDB{cleveldb, path}, nil
}
示例10: open
func (db *DB) open() error {
db.initOptions(db.cfg)
var errStr *C.char
ldbname := C.CString(db.path)
defer C.leveldb_free(unsafe.Pointer(ldbname))
db.db = C.leveldb_open(db.opts.Opt, ldbname, &errStr)
if errStr != nil {
db.db = nil
return saveError(errStr)
}
return nil
}
示例11: Get
// Get returns the data associated with the key from the database.
//
// If the key does not exist in the database, a nil []byte is returned. If the
// key does exist, but the data is zero-length in the database, a zero-length
// []byte will be returned.
//
// The key byte slice may be reused safely. Get takes a copy of
// them before returning.
func (db *DB) Get(ro *ReadOptions, key []byte) ([]byte, error) {
var errStr *C.char
var vallen C.size_t
var k *C.char
if len(key) != 0 {
k = (*C.char)(unsafe.Pointer(&key[0]))
}
value := C.leveldb_get(
db.Ldb, ro.Opt, k, C.size_t(len(key)), &vallen, &errStr)
if errStr != nil {
gs := C.GoString(errStr)
C.leveldb_free(unsafe.Pointer(errStr))
return nil, DatabaseError(gs)
}
if value == nil {
return nil, nil
}
defer C.leveldb_free(unsafe.Pointer(value))
return C.GoBytes(unsafe.Pointer(value), C.int(vallen)), nil
}
示例12: Get
func (db *LevelDB) Get(key string) (value string, err error) {
opt := C.leveldb_readoptions_create() // write option
defer C.leveldb_free(unsafe.Pointer(opt))
k := C.CString(key) // copy
defer C.leveldb_free(unsafe.Pointer(k))
var vallen C.size_t
var cerr *C.char
cvalue := C.leveldb_get(db.CLevelDB, opt, k, C.size_t(len(key)), &vallen, &cerr)
if cerr != nil {
defer C.leveldb_free(unsafe.Pointer(cerr))
return "", errors.New(C.GoString(cerr))
}
if cvalue == nil {
return "", nil
}
defer C.leveldb_free(unsafe.Pointer(cvalue))
return C.GoString(cvalue), nil
}
示例13: Get
func Get(k *string) (v string, err error) {
var v_len C.size_t
key := C.CString(*k)
defer C.free(unsafe.Pointer(key))
val := C.get(key, C.size_t(len(*k)), &v_len)
if val == nil {
err = NotExist
return
}
defer C.leveldb_free(unsafe.Pointer(val))
v = C.GoStringN(val, C.int(v_len))
return
}
示例14: Delete
// Delete removes the data associated with the key from the database.
//
// The key byte slice may be reused safely. Delete takes a copy of
// them before returning. The WriteOptions passed in can be reused by
// multiple calls to this and if the WriteOptions is left unchanged.
func (db *DB) Delete(wo *WriteOptions, key []byte) error {
var errStr *C.char
var k *C.char
if len(key) != 0 {
k = (*C.char)(unsafe.Pointer(&key[0]))
}
C.leveldb_delete(
db.Ldb, wo.Opt, k, C.size_t(len(key)), &errStr)
if errStr != nil {
gs := C.GoString(errStr)
C.leveldb_free(unsafe.Pointer(errStr))
return DatabaseError(gs)
}
return nil
}
示例15: Destroy
func (db *DB) Destroy() error {
path := db.cfg.Path
db.Close()
opts := NewOptions()
defer opts.Close()
var errStr *C.char
ldbname := C.CString(path)
defer C.leveldb_free(unsafe.Pointer(ldbname))
C.leveldb_destroy_db(opts.Opt, ldbname, &errStr)
if errStr != nil {
return saveError(errStr)
}
return nil
}