asar coverage - build #267


src/asar/
File: src/asar/assocarr.h
Date: 2025-03-01 20:31:10
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 35676 bool exists(const char* key) const
18 {
19
4/8
✓ Branch 0 taken 14136 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14136 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12820 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12820 times.
✗ Branch 7 not taken.
35676 return storage.find(key) != storage.end();
20 }
21
22 21564 right& find(const char* key)
23 {
24
4/7
✓ Branch 0 taken 7725 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7725 times.
✓ Branch 3 taken 6850 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6850 times.
✗ Branch 6 not taken.
21564 return storage.find(key)->second;
25 }
26
27 10050 right& create(const char* key)
28 {
29
3/6
✓ Branch 0 taken 4051 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8735 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4684 times.
✗ Branch 5 not taken.
10050 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 4244 void reset()
38 {
39 4244 storage.clear();
40 4244 }
41
42 373 assocarr()
43 373 {
44 373 }
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 6162 template<typename T> void each(T func)
60 {
61
4/4
✓ Branch 0 taken 1907 times.
✓ Branch 1 taken 1359 times.
✓ Branch 2 taken 2409 times.
✓ Branch 3 taken 1727 times.
14764 for (auto& it : storage) {
62
4/6
✓ Branch 0 taken 1681 times.
✓ Branch 1 taken 211 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2173 times.
✓ Branch 4 taken 221 times.
✗ Branch 5 not taken.
8602 func(it.first, it.second);
63 }
64 6162 }
65
66 };
67