mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-12 21:01:21 +00:00
New canonical Iterator
This commit is contained in:
88
db/db.go
88
db/db.go
@ -1,93 +1,5 @@
|
||||
package db
|
||||
|
||||
import . "github.com/tendermint/tmlibs/common"
|
||||
|
||||
type DB interface {
|
||||
Get([]byte) []byte // NOTE: returns nil iff never set or deleted.
|
||||
Set([]byte, []byte)
|
||||
SetSync([]byte, []byte)
|
||||
Delete([]byte)
|
||||
DeleteSync([]byte)
|
||||
Close()
|
||||
NewBatch() Batch
|
||||
Iterator() Iterator
|
||||
|
||||
// For debugging
|
||||
Print()
|
||||
|
||||
// Stats returns a map of property values for all keys and the size of the cache.
|
||||
Stats() map[string]string
|
||||
|
||||
// CacheDB wraps the DB w/ a cache.
|
||||
CacheDB() CacheDB
|
||||
}
|
||||
|
||||
type CacheDB interface {
|
||||
DB
|
||||
Write() // Write to the underlying DB
|
||||
}
|
||||
|
||||
type SetDeleter interface {
|
||||
Set(key, value []byte)
|
||||
Delete(key []byte)
|
||||
}
|
||||
|
||||
type Batch interface {
|
||||
SetDeleter
|
||||
Write()
|
||||
}
|
||||
|
||||
/*
|
||||
Usage:
|
||||
|
||||
for itr.Seek(mykey); itr.Valid(); itr.Next() {
|
||||
k, v := itr.Key(); itr.Value()
|
||||
....
|
||||
}
|
||||
*/
|
||||
type Iterator interface {
|
||||
|
||||
// Seek moves the iterator the position of the key given or, if the key
|
||||
// doesn't exist, the next key that does exist in the database. If the key
|
||||
// doesn't exist, and there is no next key, the Iterator becomes invalid.
|
||||
Seek(key []byte)
|
||||
|
||||
// Valid returns false only when an Iterator has iterated past either the
|
||||
// first or the last key in the database.
|
||||
Valid() bool
|
||||
|
||||
// Next moves the iterator to the next sequential key in the database, as
|
||||
// defined by the Comparator in the ReadOptions used to create this Iterator.
|
||||
//
|
||||
// If Valid returns false, this method will panic.
|
||||
Next()
|
||||
|
||||
// Prev moves the iterator to the previous sequential key in the database, as
|
||||
// defined by the Comparator in the ReadOptions used to create this Iterator.
|
||||
//
|
||||
// If Valid returns false, this method will panic.
|
||||
Prev()
|
||||
|
||||
// Key returns the key of the cursor.
|
||||
//
|
||||
// If Valid returns false, this method will panic.
|
||||
Key() []byte
|
||||
|
||||
// Value returns the key of the cursor.
|
||||
//
|
||||
// If Valid returns false, this method will panic.
|
||||
Value() []byte
|
||||
|
||||
// GetError returns an IteratorError from LevelDB if it had one during
|
||||
// iteration.
|
||||
//
|
||||
// This method is safe to call when Valid returns false.
|
||||
GetError() error
|
||||
|
||||
// Close deallocates the given Iterator.
|
||||
Close()
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main entry
|
||||
|
||||
|
Reference in New Issue
Block a user