asar coverage - build #323


src/asar/
File: src/asar/assocarr.h
Date: 2025-10-31 21:01:18
Lines:
19/21
90.5%
Functions:
40/41
97.6%
Branches:
22/37
59.5%

Line Branch Exec Source
1 // this used to be a custom map type, now replaced with just a wrapper around std::unordered_map.
2
3 #pragma once
4
5 #include <initializer_list>
6 #include <unordered_map>
7 #include "libstr.h"
8
9 template<typename right>
10 class assocarr {
11 private:
12
13 std::unordered_map<string, right> storage;
14
15 public:
16
17 55411 bool exists(const char* key) const
18 {
19
4/8
✓ Branch 0 taken 19685 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19685 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20457 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 20457 times.
✗ Branch 7 not taken.
55411 return storage.find(key) != storage.end();
20 }
21
22 34489 right& find(const char* key)
23 {
24
4/7
✓ Branch 0 taken 10431 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10431 times.
✓ Branch 3 taken 10606 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 10606 times.
✗ Branch 6 not taken.
34489 return storage.find(key)->second;
25 }
26
27 10238 right& create(const char* key)
28 {
29
3/6
✓ Branch 0 taken 4130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8860 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4730 times.
✗ Branch 5 not taken.
10238 return storage[key];
30 }
31
32 201 void remove(const char* key)
33 {
34
3/6
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 201 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 117 times.
✗ Branch 5 not taken.
201 storage.erase(key);
35 201 }
36
37 4309 void reset()
38 {
39 4309 storage.clear();
40 4309 }
41
42 365 assocarr()
43 365 {
44 365 }
45
46 assocarr(std::initializer_list<std::pair<const char*, right>> list)
47 {
48 for (auto& it : list) {
49 storage.insert(std::move(it));
50 }
51 }
52
53 right& operator[](const char* key)
54 {
55 return create(key);
56 }
57
58 //void(*func)(const char * key, right& value)
59 6258 template<typename T> void each(T func)
60 {
61
4/4
✓ Branch 0 taken 1958 times.
✓ Branch 1 taken 1392 times.
✓ Branch 2 taken 2430 times.
✓ Branch 3 taken 1742 times.
15004 for (auto& it : storage) {
62
4/6
✓ Branch 0 taken 1720 times.
✓ Branch 1 taken 223 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2184 times.
✓ Branch 4 taken 231 times.
✗ Branch 5 not taken.
8746 func(it.first, it.second);
63 }
64 6258 }
65
66 };
67