storage: generalize Level/Bolt seek implementations
Too much in common. Just refactoring. no functional changes.
This commit is contained in:
parent
a5f8b8870a
commit
51b804ab0e
3 changed files with 51 additions and 60 deletions
|
@ -4,6 +4,8 @@ import (
|
|||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/syndtr/goleveldb/leveldb/util"
|
||||
)
|
||||
|
||||
// KeyPrefix constants.
|
||||
|
@ -133,6 +135,24 @@ func AppendPrefixInt(k KeyPrefix, n int) []byte {
|
|||
return AppendPrefix(k, b)
|
||||
}
|
||||
|
||||
func seekRangeToPrefixes(sr SeekRange) *util.Range {
|
||||
var (
|
||||
rang *util.Range
|
||||
start = make([]byte, len(sr.Prefix)+len(sr.Start))
|
||||
)
|
||||
copy(start, sr.Prefix)
|
||||
copy(start[len(sr.Prefix):], sr.Start)
|
||||
|
||||
if !sr.Backwards {
|
||||
rang = util.BytesPrefix(sr.Prefix)
|
||||
rang.Start = start
|
||||
} else {
|
||||
rang = util.BytesPrefix(start)
|
||||
rang.Start = sr.Prefix
|
||||
}
|
||||
return rang
|
||||
}
|
||||
|
||||
// NewStore creates storage with preselected in configuration database type.
|
||||
func NewStore(cfg DBConfiguration) (Store, error) {
|
||||
var store Store
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue