asar coverage - build #274


src/asar/
File: src/asar/assocarr.h
Date: 2025-03-04 15:06:12
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 35613 bool exists(const char* key) const
18 {
19
4/8
✓ Branch 0 taken 14096 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14096 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12826 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12826 times.
✗ Branch 7 not taken.
35613 return storage.find(key) != storage.end();
20 }
21
22 21378 right& find(const char* key)
23 {
24
4/7
✓ Branch 0 taken 7667 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7667 times.
✓ Branch 3 taken 6815 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6815 times.
✗ Branch 6 not taken.
21378 return storage.find(key)->second;
25 }
26
27 10194 right& create(const char* key)
28 {
29
3/6
✓ Branch 0 taken 4102 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8837 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4735 times.
✗ Branch 5 not taken.
10194 return storage[key];
30 }
31
32 202 void remove(const char* key)
33 {
34
3/6
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 202 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 118 times.
✗ Branch 5 not taken.
202 storage.erase(key);
35 202 }
36
37 4304 void reset()
38 {
39 4304 storage.clear();
40 4304 }
41
42 377 assocarr()
43 377 {
44 377 }
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 6250 template<typename T> void each(T func)
60 {
61
4/4
✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 1381 times.
✓ Branch 2 taken 2441 times.
✓ Branch 3 taken 1749 times.
14980 for (auto& it : storage) {
62
4/6
✓ Branch 0 taken 1707 times.
✓ Branch 1 taken 217 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2199 times.
✓ Branch 4 taken 227 times.
✗ Branch 5 not taken.
8730 func(it.first, it.second);
63 }
64 6250 }
65
66 };
67