| 121 | } |
| 122 | |
| 123 | RLHandle* Insert(RLHandle* h) { |
| 124 | RLHandle** ptr = FindPointer(h->key(), h->hash); |
| 125 | RLHandle* old = *ptr; |
| 126 | h->next_hash = (old == nullptr ? nullptr : old->next_hash); |
| 127 | *ptr = h; |
| 128 | if (old == nullptr) { |
| 129 | ++elems_; |
| 130 | if (elems_ > length_) { |
| 131 | // Since each cache entry is fairly large, we aim for a small |
| 132 | // average linked list length (<= 1). |
| 133 | Resize(); |
| 134 | } |
| 135 | } |
| 136 | return old; |
| 137 | } |
| 138 | |
| 139 | RLHandle* Remove(const Slice& key, uint32_t hash) { |
| 140 | RLHandle** ptr = FindPointer(key, hash); |