MCPcopy Create free account
hub / github.com/Norbyte/bg3se / insert

Method insert

CoreLib/Base/PagedMap.h:40–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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
67private:
68 void hash_insert(TKey const& key, int keyIdx)

Callers 1

add_uninitializedMethod · 0.45

Calls 2

atMethod · 0.80
capacityMethod · 0.45

Tested by

no test coverage detected