| 38 | } |
| 39 | |
| 40 | int insert(TKey const& key) |
| 41 | { |
| 42 | auto index = find_index(key); |
| 43 | if (index != -1) { |
| 44 | return index; |
| 45 | } |
| 46 | |
| 47 | auto keyIdx = keysSize_++; |
| 48 | |
| 49 | if (keyIdx >= keyLayout_.capacity()) { |
| 50 | auto layout = keyLayout_; |
| 51 | PagedOps<int32_t, TAllocator>::Resize(keyIdx + 1, nextIds_, layout, *this); |
| 52 | PagedOps<TKey, TAllocator>::Resize(keyIdx + 1, keys_, keyLayout_, *this); |
| 53 | } |
| 54 | |
| 55 | *keyLayout_.at(keys_, keyIdx) = key; |
| 56 | *keyLayout_.at(nextIds_, keyIdx) = -1; |
| 57 | |
| 58 | if (hashSize_ >= keysSize_ + (keysSize_ >> 1)) { |
| 59 | hash_insert(key, keyIdx); |
| 60 | } else { |
| 61 | rehash(keysSize_ + (keysSize_ >> 1)); |
| 62 | } |
| 63 | |
| 64 | return (int)keyIdx; |
| 65 | } |
| 66 | |
| 67 | private: |
| 68 | void hash_insert(TKey const& key, int keyIdx) |
no test coverage detected