GCC Code Coverage Report


Directory: src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 80.8% 21 / 0 / 26
Functions: 71.4% 5 / 0 / 7
Branches: 59.1% 13 / 0 / 22

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 382 explicit DramUnorderedMapIndex(const BaseKVConfig& config) : Index(config) {}
12
13 103474 void Get(Key_t key, Value_t& pointer, unsigned tid) override {
14 (void)tid;
15
1/2
✓ Branch 1 taken 103474 times.
✗ Branch 2 not taken.
103474 std::shared_lock<std::shared_mutex> lock(mu_);
16
1/2
✓ Branch 1 taken 103474 times.
✗ Branch 2 not taken.
103474 auto it = map_.find(key);
17
2/2
✓ Branch 2 taken 2546 times.
✓ Branch 3 taken 100928 times.
103474 pointer = (it == map_.end()) ? NONE : it->second;
18 103474 }
19
20 138408 Value_t Put(Key_t key, Value_t pointer, unsigned tid) override {
21 (void)tid;
22
1/2
✓ Branch 1 taken 138408 times.
✗ Branch 2 not taken.
138408 std::unique_lock<std::shared_mutex> lock(mu_);
23
1/2
✓ Branch 1 taken 138408 times.
✗ Branch 2 not taken.
138408 auto it = map_.find(key);
24
2/2
✓ Branch 2 taken 75554 times.
✓ Branch 3 taken 62854 times.
138408 Value_t old_handle = (it == map_.end()) ? kValueHandleNone : it->second;
25
1/2
✓ Branch 1 taken 138408 times.
✗ Branch 2 not taken.
138408 map_[key] = pointer;
26 138408 return old_handle;
27 138408 }
28
29 630 void BatchGet(base::ConstArray<Key_t> keys,
30 Value_t* pointers,
31 unsigned tid) override {
32
2/2
✓ Branch 1 taken 23352 times.
✓ Branch 2 taken 630 times.
23982 for (int i = 0; i < keys.Size(); ++i) {
33 23352 Get(keys[i], pointers[i], tid);
34 }
35 630 }
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 bool Delete(Key_t& key) override {
46 std::unique_lock<std::shared_mutex> lock(mu_);
47 return map_.erase(key) > 0;
48 }
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