MCPcopy Create free account
hub / github.com/AdRoll/baker / newColdCache

Function newColdCache

pkg/buffercache/cold.go:27–44  ·  view source on GitHub ↗

newColdCache returns a coldCache with len(bsizes) buckets, each of which can hold ncells cells (or buffers), bsizes is the list of bucket cell sizes. NOTE: the following statements must be true of newColdCache returns an error: - the total number of cells must be a multiple of 64 - bsizes must be s

(ncells int, bsizes []int)

Source from the content-addressed store, hash-verified

25// - the total number of cells must be a multiple of 64
26// - bsizes must be sorted in ascending order
27func newColdCache(ncells int, bsizes []int) (*coldCache, error) {
28 if ncells == 0 || ncells%64 != 0 {
29 return nil, errInvalidConfig("the number of cells per bucket must be positive and a multiple of 64")
30 }
31
32 // Ensure bucket sizes are sorted since, upon insertion of a buffer, we loop
33 // them to find the first big enough to hold the buffer. It's also handy for
34 // bucket metrics.
35 if !sort.IntsAreSorted(bsizes) {
36 return nil, errInvalidConfig("bucket sizes must be sorted in ascending order")
37 }
38
39 buckets := make([]bucket, 0)
40 for _, bsize := range bsizes {
41 buckets = append(buckets, newBucket(bsize, ncells))
42 }
43 return &coldCache{buckets: buckets}, nil
44}
45
46// smallestFitBucket returns the smallest bucket in which fits a buffer of length l
47// or -1 if all buckets are too small.

Callers 3

NewFunction · 0.85
TestColdCacheMetricsFunction · 0.85

Calls 2

errInvalidConfigTypeAlias · 0.85
newBucketFunction · 0.85

Tested by 2

TestColdCacheMetricsFunction · 0.68