mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-28 20:21:47 +00:00
CacheDB (#67)
* Add CacheDB & SimpleMap * Generic memBatch; Fix cLevelDB tests * CacheWrap() for CacheDB and MemDB * Change Iterator to match LeviGo Iterator * Fixes from review * cacheWrapWriteMutex and some race fixes * Use tmlibs/common * NewCWWMutex is exposed. DB can be CacheWrap'd * Remove GetOK, not needed * Fsdb (#72) * Add FSDB * Review fixes from Anton * Review changes * Fixes from review
This commit is contained in:
26
merkle/simple_map.go
Normal file
26
merkle/simple_map.go
Normal file
@ -0,0 +1,26 @@
|
||||
package merkle
|
||||
|
||||
type SimpleMap struct {
|
||||
kvz KVPairs
|
||||
}
|
||||
|
||||
func NewSimpleMap() *SimpleMap {
|
||||
return &SimpleMap{
|
||||
kvz: nil,
|
||||
}
|
||||
}
|
||||
|
||||
func (sm *SimpleMap) Set(k string, o interface{}) {
|
||||
sm.kvz = append(sm.kvz, KVPair{Key: k, Value: o})
|
||||
}
|
||||
|
||||
// Merkle root hash of items sorted by key.
|
||||
// NOTE: Behavior is undefined when key is duplicate.
|
||||
func (sm *SimpleMap) Hash() []byte {
|
||||
sm.kvz.Sort()
|
||||
kvPairsH := make([]Hashable, 0, len(sm.kvz))
|
||||
for _, kvp := range sm.kvz {
|
||||
kvPairsH = append(kvPairsH, kvp)
|
||||
}
|
||||
return SimpleHashFromHashables(kvPairsH)
|
||||
}
|
Reference in New Issue
Block a user