[NOD-828] Make bucket a type alias instead of a struct.

This commit is contained in:
stasatdaglabs
2020-03-24 15:10:17 +02:00
parent cc4458fa32
commit 1fd3965256

View File

@@ -4,27 +4,25 @@ import "bytes"
var separator = []byte("/")
// Bucket is a helper struct meant to combine buckets,
// Bucket is a helper type meant to combine buckets,
// sub-buckets, and keys into a single full key-value
// database key.
type Bucket struct {
path [][]byte
}
type Bucket [][]byte
// MakeBucket creates a new Bucket using the given path
// of buckets.
func MakeBucket(path ...[]byte) *Bucket {
return &Bucket{path: path}
func MakeBucket(path ...[]byte) Bucket {
return path
}
// Bucket returns the sub-bucket of the current bucket
// defined by bucketBytes.
func (b *Bucket) Bucket(bucketBytes []byte) *Bucket {
return &Bucket{path: append(b.path, bucketBytes)}
func (b Bucket) Bucket(bucketBytes []byte) Bucket {
return append(b, bucketBytes)
}
// Key returns the key inside of the current bucket.
func (b *Bucket) Key(key []byte) []byte {
func (b Bucket) Key(key []byte) []byte {
bucketPath := b.Path()
fullKeyLength := len(bucketPath) + len(key)
@@ -36,8 +34,8 @@ func (b *Bucket) Key(key []byte) []byte {
}
// Path returns the full path of the current bucket.
func (b *Bucket) Path() []byte {
bucketPath := bytes.Join(b.path, separator)
func (b Bucket) Path() []byte {
bucketPath := bytes.Join(b, separator)
bucketPathWithFinalSeperator := make([]byte, len(bucketPath)+len(separator))
copy(bucketPathWithFinalSeperator, bucketPath)