Returns index to track entry
(key string, exp uint64, bytes uint)
| 62 | |
| 63 | // Returns index to track entry |
| 64 | func (h *indexedHeap) put(key string, exp uint64, bytes uint) int { |
| 65 | idx := 0 |
| 66 | if len(h.entries) < h.maxidx { |
| 67 | // Steal index from previously removed entry |
| 68 | // capacity > size is guaranteed |
| 69 | n := len(h.entries) |
| 70 | idx = h.entries[:n+1][n].idx |
| 71 | } else { |
| 72 | idx = h.maxidx |
| 73 | h.maxidx++ |
| 74 | h.indices = append(h.indices, idx) |
| 75 | } |
| 76 | // Push manually to avoid allocation |
| 77 | h.pushInternal(heapEntry{ |
| 78 | key: key, exp: exp, idx: idx, bytes: bytes, |
| 79 | }) |
| 80 | heap.Fix(h, h.Len()-1) |
| 81 | return idx |
| 82 | } |
| 83 | |
| 84 | func (h *indexedHeap) removeInternal(realIdx int) (key string, size uint) { //nolint:nonamedreturns // gocritic unnamedResult prefers named key and size when removing heap entries |
| 85 | x := heap.Remove(h, realIdx).(heapEntry) //nolint:forcetypeassert,errcheck // Forced type assertion required to implement the heap.Interface interface |