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 | 350 | explicit DramUnorderedMapIndex(const BaseKVConfig& config) : Index(config) {} | |
| 12 | |||
| 13 | 103562 | void Get(Key_t key, Value_t& pointer, unsigned tid) override { | |
| 14 | (void)tid; | ||
| 15 |
1/2✓ Branch 1 taken 103562 times.
✗ Branch 2 not taken.
|
103562 | std::shared_lock<std::shared_mutex> lock(mu_); |
| 16 |
1/2✓ Branch 1 taken 103562 times.
✗ Branch 2 not taken.
|
103562 | auto it = map_.find(key); |
| 17 |
2/2✓ Branch 2 taken 2650 times.
✓ Branch 3 taken 100912 times.
|
103562 | pointer = (it == map_.end()) ? NONE : it->second; |
| 18 | 103562 | } | |
| 19 | |||
| 20 | 138250 | Value_t Put(Key_t key, Value_t pointer, unsigned tid) override { | |
| 21 | (void)tid; | ||
| 22 |
1/2✓ Branch 1 taken 138250 times.
✗ Branch 2 not taken.
|
138250 | std::unique_lock<std::shared_mutex> lock(mu_); |
| 23 |
1/2✓ Branch 1 taken 138250 times.
✗ Branch 2 not taken.
|
138250 | auto it = map_.find(key); |
| 24 |
2/2✓ Branch 2 taken 75518 times.
✓ Branch 3 taken 62732 times.
|
138250 | Value_t old_handle = (it == map_.end()) ? kValueHandleNone : it->second; |
| 25 |
1/2✓ Branch 1 taken 138250 times.
✗ Branch 2 not taken.
|
138250 | map_[key] = pointer; |
| 26 | 138250 | return old_handle; | |
| 27 | 138250 | } | |
| 28 | |||
| 29 | 624 | void BatchGet(base::ConstArray<Key_t> keys, | |
| 30 | Value_t* pointers, | ||
| 31 | unsigned tid) override { | ||
| 32 |
2/2✓ Branch 1 taken 23340 times.
✓ Branch 2 taken 624 times.
|
23964 | for (int i = 0; i < keys.Size(); ++i) { |
| 33 | 23340 | Get(keys[i], pointers[i], tid); | |
| 34 | } | ||
| 35 | 624 | } | |
| 36 | |||
| 37 | 18 | void BatchPut(base::ConstArray<Key_t> keys, | |
| 38 | Value_t* pointers, | ||
| 39 | unsigned tid) override { | ||
| 40 |
2/2✓ Branch 1 taken 144 times.
✓ Branch 2 taken 18 times.
|
162 | for (int i = 0; i < keys.Size(); ++i) { |
| 41 | 144 | Put(keys[i], pointers[i], tid); | |
| 42 | } | ||
| 43 | 18 | } | |
| 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 |