(hash Hash, size int)
| 45 | } |
| 46 | |
| 47 | func (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 | |
| 65 | func (cache *Random) bump(index int) { |
| 66 | low := index * lowFactor / divisor |