From 1fd39652563e8ee4757b4aa44cf0de9f2835920c Mon Sep 17 00:00:00 2001 From: stasatdaglabs Date: Tue, 24 Mar 2020 15:10:17 +0200 Subject: [PATCH] [NOD-828] Make bucket a type alias instead of a struct. --- database2/bucket.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/database2/bucket.go b/database2/bucket.go index a56b13ddb..438673bad 100644 --- a/database2/bucket.go +++ b/database2/bucket.go @@ -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)