mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-02-21 19:22:53 +00:00
[NOD-828] Make bucket a type alias instead of a struct.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user