added more test

This commit is contained in:
Sunny Aggarwal
2018-04-01 18:00:28 +02:00
parent d98ea3764f
commit c441ccdf01
5 changed files with 122 additions and 23 deletions
+33
View File
@@ -111,6 +111,14 @@ type KVStore interface {
// CONTRACT: No writes may happen within a domain while an iterator exists over it.
ReverseIterator(start, end []byte) Iterator
// Iterator over all the keys with a certain prefix in ascending order.
// CONTRACT: No writes may happen within a domain while an iterator exists over it.
Subspace(prefix []byte) Iterator
// Iterator over all the keys with a certain prefix in descending order.
// CONTRACT: No writes may happen within a domain while an iterator exists over it.
ReverseSubspace(prefix []byte) Iterator
// TODO Not yet implemented.
// CreateSubKVStore(key *storeKey) (KVStore, error)
@@ -222,3 +230,28 @@ func (key *KVStoreKey) Name() string {
func (key *KVStoreKey) String() string {
return fmt.Sprintf("KVStoreKey{%p, %s}", key, key.name)
}
// TODO: Move to TmLibs
func PrefixEndBytes(prefix []byte) []byte {
if prefix == nil {
return nil
}
end := make([]byte, len(prefix))
copy(end, prefix)
finished := false
for !finished {
if end[len(end)-1] != byte(255) {
end[len(end)-1]++
finished = true
} else {
end = end[:len(end)-1]
if len(end) == 0 {
end = nil
finished = true
}
}
}
return end
}