<commit_before>package rkive

import (
	"github.com/philhofer/rkive/rpbc"
	"sync"
)

// Bucket represents a Riak bucket
type Bucket struct {
	c  *Client
	nm string
}

// Bucket returns a Riak bucket
// with the provided name
func (c *Client) Bucket(name string) *Bucket {
	return &Bucket{c: c, nm: name}
}

// Fetch performs a fetch with the bucket's default properties
func (b *Bucket) Fetch(o Object, key string) error { return b.c.Fetch(o, b.nm, key, nil) }

// New performs a new store with the bucket's default properties
func (b *Bucket) New(o Object, key *string) error { return b.c.New(o, b.nm, key, nil) }

// Push pushes an object with a bucket's default properties
func (b *Bucket) Push(o Object) error { return b.c.Push(o, nil) }

// Store stores an object with a bucket's default properties
func (b *Bucket) Store(o Object) error { return b.c.Store(o, nil) }

// Update updates an object in a bucket
func (b *Bucket) Update(o Object) (bool, error) { return b.c.Update(o, nil) }

// IndexLookup performs a secondary index query on the bucket
func (b *Bucket) IndexLookup(idx string, val string) (*IndexQueryRes, error) {
	return b.c.IndexLookup(b.nm, idx, val, nil)
}

// IndexRange performs a secondary index range query on the bucket
func (b *Bucket) IndexRange(idx string, min int64, max int64) (*IndexQueryRes, error) {
	return b.c.IndexRange(b.nm, idx, min, max, nil)
}

// GetProperties retreives the properties of the bucket
func (b *Bucket) GetProperties() (*rpbc.RpbBucketProps, error) {
	req := &rpbc.RpbGetBucketReq{
		Bucket: []byte(b.nm),
	}
	res := &rpbc.RpbGetBucketResp{}
	_, err := b.c.req(req, 19, res)
	return res.GetProps(), err
}

// SetProperties sets the properties of the bucket
func (b *Bucket) SetProperties(props *rpbc.RpbBucketProps) error {
	req := &rpbc.RpbSetBucketReq{
		Bucket: []byte(b.nm),
		Props:  props,
	}
	_, err := b.c.req(req, 21, nil)
	return err
}

var (
	ptrTrue         = true
	ptrFalse        = false
	memNval  uint32 = 1
	memR     uint32 = 1
	memW     uint32 = 1
	// properties for memory-backed cache bucket
	cacheProps = rpbc.RpbBucketProps{
		Backend:       []byte("cache"), // this has to come from the riak.conf
		NotfoundOk:    &ptrTrue,
		AllowMult:     &ptrFalse,
		LastWriteWins: &ptrFalse,
		BasicQuorum:   &ptrFalse,
		NVal:          &memNval,
		R:             &memR,
		W:             &memW,
	}
)

// MakeCache makes a memory-backed bucket. You
// must have the "multi"-backend option enabled
// in your configuration in order for this to
// work.
func (b *Bucket) MakeCache() error {
	return b.SetProperties(&cacheProps)

}

// Reset resets the bucket's properties
func (b *Bucket) Reset() error {
	req := &rpbc.RpbResetBucketReq{
		Bucket: ustr(b.nm),
	}
	code, err := b.c.req(req, 29, nil)<commit_msg>document cache bucket<commit_after>package rkive

import (
	"github.com/philhofer/rkive/rpbc"
	"sync"
)

// Bucket represents a Riak bucket
type Bucket struct {
	c  *Client
	nm string
}

// Bucket returns a Riak bucket
// with the provided name
func (c *Client) Bucket(name string) *Bucket {
	return &Bucket{c: c, nm: name}
}

// Fetch performs a fetch with the bucket's default properties
func (b *Bucket) Fetch(o Object, key string) error { return b.c.Fetch(o, b.nm, key, nil) }

// New performs a new store with the bucket's default properties
func (b *Bucket) New(o Object, key *string) error { return b.c.New(o, b.nm, key, nil) }

// Push pushes an object with a bucket's default properties
func (b *Bucket) Push(o Object) error { return b.c.Push(o, nil) }

// Store stores an object with a bucket's default properties
func (b *Bucket) Store(o Object) error { return b.c.Store(o, nil) }

// Update updates an object in a bucket
func (b *Bucket) Update(o Object) (bool, error) { return b.c.Update(o, nil) }

// IndexLookup performs a secondary index query on the bucket
func (b *Bucket) IndexLookup(idx string, val string) (*IndexQueryRes, error) {
	return b.c.IndexLookup(b.nm, idx, val, nil)
}

// IndexRange performs a secondary index range query on the bucket
func (b *Bucket) IndexRange(idx string, min int64, max int64) (*IndexQueryRes, error) {
	return b.c.IndexRange(b.nm, idx, min, max, nil)
}

// GetProperties retreives the properties of the bucket
func (b *Bucket) GetProperties() (*rpbc.RpbBucketProps, error) {
	req := &rpbc.RpbGetBucketReq{
		Bucket: []byte(b.nm),
	}
	res := &rpbc.RpbGetBucketResp{}
	_, err := b.c.req(req, 19, res)
	return res.GetProps(), err
}

// SetProperties sets the properties of the bucket
func (b *Bucket) SetProperties(props *rpbc.RpbBucketProps) error {
	req := &rpbc.RpbSetBucketReq{
		Bucket: []byte(b.nm),
		Props:  props,
	}
	_, err := b.c.req(req, 21, nil)
	return err
}

var (
	ptrTrue         = true
	ptrFalse        = false
	memNval  uint32 = 1
	memR     uint32 = 1
	memW     uint32 = 1
	// properties for memory-backed cache bucket
	cacheProps = rpbc.RpbBucketProps{
		Backend:       []byte("cache"), // this has to come from the riak.conf
		NotfoundOk:    &ptrTrue,
		AllowMult:     &ptrFalse,
		LastWriteWins: &ptrFalse,
		BasicQuorum:   &ptrFalse,
		NVal:          &memNval,
		R:             &memR,
		W:             &memW,
	}
)

// MakeCache makes a memory-backed cache bucket. You will
// most likely need the following options enabled in your riak.conf:
//
//   # this enables multiple backends
//   storage_backend = multi
//
//   # this creates a backend called 'cache' backed by RAM
//   multi_backend.cache.storage_backend = memory
//
//   # this makes a backend called 'std' and sets its storage backend
//   # (you can name this one whatever you would like)
//   multi_backend.std.storage_backend = <leveldb OR bitcask>
//   multi_backend.default = std
//
func (b *Bucket) MakeCache() error {
	return b.SetProperties(&cacheProps)

}

// Reset resets the bucket's properties
func (b *Bucket) Reset() error {
	req := &rpbc.RpbResetBucketReq{
		Bucket: ustr(b.nm),
	}
	code, err := b.c.req(req, 29, nil)
{'fraction_non_alphanumeric': 0.12401144203264344, 'fraction_numerical': 0.0063940770654551575, 'mean_word_length': 3.4391336818521285, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1133263', 'n_tokens_mistral': 2122, 'n_tokens_neox': 2025, 'n_words': 695}