| 76 | } |
| 77 | |
| 78 | LRUHandle* Insert(LRUHandle* h) { |
| 79 | LRUHandle** ptr = FindPointer(h->key(), h->hash); |
| 80 | LRUHandle* old = *ptr; |
| 81 | h->next_hash = (old == nullptr ? nullptr : old->next_hash); |
| 82 | *ptr = h; |
| 83 | if (old == nullptr) { |
| 84 | ++elems_; |
| 85 | if (elems_ > length_) { |
| 86 | // Since each cache entry is fairly large, we aim for a small |
| 87 | // average linked list length (<= 1). |
| 88 | Resize(); |
| 89 | } |
| 90 | } |
| 91 | return old; |
| 92 | } |
| 93 | |
| 94 | LRUHandle* Remove(const Slice& key, uint32_t hash) { |
| 95 | LRUHandle** ptr = FindPointer(key, hash); |