From 6a3a37d5a69ca748e30e5b58d5b3e318c5885599 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Fri, 1 Dec 2017 09:24:02 -0800 Subject: [PATCH] Update store types to new spec --- store/types.go | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/store/types.go b/store/types.go index 44e2673d0..82388870e 100644 --- a/store/types.go +++ b/store/types.go @@ -9,8 +9,8 @@ type CommitID struct { Hash []byte } -type (cid CommitID) IsZero() bool { - return cid.Version == 0 && len(cid.Hash) == 0 +func (cid CommitID) IsZero() bool { + return cid.Version == 0 && len(cid.Hash) == 0 } type Committer interface { @@ -21,42 +21,44 @@ type Committer interface { type CommitterLoader func(id CommitID) (Committer, error) -// A Store is anything that can be wrapped with a cache. -type CacheWrappable interface { - - // CacheWrap() wraps a thing with a cache. After calling - // .Write() on the CacheWrap, all previous CacheWraps on the - // object expire. - // - // CacheWrap() should not return a Committer, since Commit() on - // CacheWraps make no sense. It can return KVStore, IterKVStore, - // etc. - // - // NOTE: https://dave.cheney.net/2017/07/22/should-go-2-0-support-generics. - // The returned object may or may not implement CacheWrap() as well. - CacheWrap() interface{} -} - // KVStore is a simple interface to get/set data type KVStore interface { - CacheWrappable // CacheWrap returns KVStore - Set(key, value []byte) (prev []byte) Get(key []byte) (value []byte, exists bool) Has(key []byte) (exists bool) Remove(key []byte) (prev []byte, removed bool) + + // CacheKVStore() wraps a thing with a cache. After + // calling .Write() on the CacheKVStore, all previous + // CacheWraps on the object expire. + CacheKVStore() CacheKVStore +} + +type CacheKVStore interface { + KVStore + Write() // Writes operations to underlying KVStore } // IterKVStore can be iterated on // CONTRACT: No writes may happen within a domain while an iterator exists over it. type IterKVStore interface { - KVStore // CacheWrap returns IterKVMap + KVStore Iterator(start, end []byte) Iterator ReverseIterator(start, end []byte) Iterator First(start, end []byte) (kv KVPair, ok bool) Last(start, end []byte) (kv KVPair, ok bool) + + // CacheIterKVStore() wraps a thing with a cache. + // After calling .Write() on the CacheIterKVStore, all + // previous CacheWraps on the object expire. + CacheIterKVStore() CacheIterKVStore +} + +type CacheIterKVStore interface { + IterKVStore + Write() // Writes operations to underlying KVStore } type KVPair struct {