* 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:
Jae Kwon
2017-11-09 17:42:32 -05:00
committed by GitHub
parent 176c2ceed6
commit 8481c49c82
23 changed files with 1699 additions and 354 deletions

26
merkle/simple_map.go Normal file
View 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)
}