MCPcopy Create free account
hub / github.com/egonelbre/exp / Add

Method Add

cache/random.go:47–63  ·  view source on GitHub ↗
(hash Hash, size int)

Source from the content-addressed store, hash-verified

45}
46
47func (cache *Random) Add(hash Hash, size int) (ok bool) {
48 if size > cache.maxSize {
49 return false
50 }
51
52 cache.currentSize += size
53 for cache.currentSize > cache.maxSize {
54 cache.evict(len(cache.items) - 1)
55 }
56
57 index := len(cache.items)
58 cache.lookup[hash] = index
59 cache.items = append(cache.items, Entry{hash, size})
60 cache.bump(index)
61
62 return true
63}
64
65func (cache *Random) bump(index int) {
66 low := index * lowFactor / divisor

Callers 1

BenchmarkRandom_GrowingFunction · 0.95

Calls 2

evictMethod · 0.95
bumpMethod · 0.95

Tested by 1

BenchmarkRandom_GrowingFunction · 0.76