db: Simplify exists check, fix IsKeyInDomain signature, Iterator Close

+ *FSDB.HasKey now uses common.FileExists to test for file existence
+ IsKeyInDomain takes key as a []byte slice instead of as a string
to avoid extraneous []byte<-->string conversions for start and end
+ Iterator.Close() instead of Iterator.Release()
+ withDB helper to encapsulate DB creation, deferred cleanups
so that for loops can use opened DBs and discard them ASAP

Addressing accepted changes from review with @jaekwon
This commit is contained in:
Emmanuel Odeke
2017-12-15 02:48:40 -07:00
parent a2f7898b6d
commit a7b20d4e46
7 changed files with 37 additions and 45 deletions

View File

@ -2,7 +2,6 @@ package db
import (
"bytes"
"strings"
)
func IteratePrefix(db DB, prefix []byte) Iterator {
@ -39,8 +38,8 @@ func cpIncr(bz []byte) (ret []byte) {
return EndingKey()
}
func IsKeyInDomain(key string, start, end []byte) bool {
leftCondition := bytes.Equal(start, BeginningKey()) || strings.Compare(key, string(start)) >= 0
rightCondition := bytes.Equal(end, EndingKey()) || strings.Compare(key, string(end)) < 0
func IsKeyInDomain(key, start, end []byte) bool {
leftCondition := bytes.Equal(start, BeginningKey()) || bytes.Compare(key, start) >= 0
rightCondition := bytes.Equal(end, EndingKey()) || bytes.Compare(key, end) < 0
return leftCondition && rightCondition
}