src/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
25 / 26
96.2%
Branches:
15 / 22
68.2%
Functions:
6 / 7
85.7%

storage/index/dram/unordered_map_index.h
Line Branch Exec Source
1 #pragma once
2
3 #include <shared_mutex>
4 #include <unordered_map>
5
6 #include "base/factory.h"
7 #include "storage/index/index.h"
8
9 class DramUnorderedMapIndex : public Index {
10 public:
11 406 explicit DramUnorderedMapIndex(const BaseKVConfig& config) : Index(config) {}
12
13 104468 void Get(Key_t key, Value_t& pointer, unsigned tid) override {
14 (void)tid;
15
1/2
✓ Branch 1 taken 104468 times.
✗ Branch 2 not taken.
104468 std::shared_lock<std::shared_mutex> lock(mu_);
16
1/2
✓ Branch 1 taken 104468 times.
✗ Branch 2 not taken.
104468 auto it = map_.find(key);
17
2/2
✓ Branch 2 taken 2666 times.
✓ Branch 3 taken 101802 times.
104468 pointer = (it == map_.end()) ? NONE : it->second;
18 104468 }
19
20 139164 Value_t Put(Key_t key, Value_t pointer, unsigned tid) override {
21 (void)tid;
22
1/2
✓ Branch 1 taken 139164 times.
✗ Branch 2 not taken.
139164 std::unique_lock<std::shared_mutex> lock(mu_);
23
1/2
✓ Branch 1 taken 139164 times.
✗ Branch 2 not taken.
139164 auto it = map_.find(key);
24
2/2
✓ Branch 2 taken 76400 times.
✓ Branch 3 taken 62764 times.
139164 Value_t old_handle = (it == map_.end()) ? kValueHandleNone : it->second;
25
1/2
✓ Branch 1 taken 139164 times.
✗ Branch 2 not taken.
139164 map_[key] = pointer;
26 139164 return old_handle;
27 139164 }
28
29 636 void BatchGet(base::ConstArray<Key_t> keys,
30 Value_t* pointers,
31 unsigned tid) override {
32
2/2
✓ Branch 1 taken 23376 times.
✓ Branch 2 taken 636 times.
24012 for (int i = 0; i < keys.Size(); ++i) {
33 23376 Get(keys[i], pointers[i], tid);
34 }
35 636 }
36
37 20 void BatchPut(base::ConstArray<Key_t> keys,
38 Value_t* pointers,
39 unsigned tid) override {
40
2/2
✓ Branch 1 taken 146 times.
✓ Branch 2 taken 20 times.
166 for (int i = 0; i < keys.Size(); ++i) {
41 146 Put(keys[i], pointers[i], tid);
42 }
43 20 }
44
45 4 bool Delete(Key_t& key) override {
46
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 std::unique_lock<std::shared_mutex> lock(mu_);
47
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
8 return map_.erase(key) > 0;
48 4 }
49
50 ✗ size_t Capacity() override { return map_.size(); }
51
52 private:
53 mutable std::shared_mutex mu_;
54 std::unordered_map<Key_t, Value_t> map_;
55 };
56
57 FACTORY_REGISTER(
58 Index, DRAM_UNORDERED_MAP, DramUnorderedMapIndex, const BaseKVConfig&);
59