Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | // Copyright 2019-2022 Cambridge Quantum Computing | |||
2 | // | |||
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |||
4 | // you may not use this file except in compliance with the License. | |||
5 | // You may obtain a copy of the License at | |||
6 | // | |||
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |||
8 | // | |||
9 | // Unless required by applicable law or agreed to in writing, software | |||
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |||
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
12 | // See the License for the specific language governing permissions and | |||
13 | // limitations under the License. | |||
14 | ||||
15 | #include "SymTable.hpp" | |||
16 | ||||
17 | namespace tket { | |||
18 | ||||
19 | 2946 | std::unordered_set<std::string>& SymTable::get_registered_symbols() { | ||
20 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2945 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
2946 | static std::unordered_set<std::string> symbols; | |
21 | 2946 | return symbols; | ||
22 | } | |||
23 | ||||
24 | 48 | Sym SymTable::fresh_symbol(const std::string& preferred) { | ||
25 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | std::string new_symbol = preferred; | |
26 | 48 | unsigned suffix = 0; | ||
27 |
2/4✓ Branch 1 taken 237 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 237 times.
✗ Branch 5 not taken.
|
0/1? Decision couldn't be analyzed.
|
285 | while (get_registered_symbols().find(new_symbol) != |
28 |
3/4✓ Branch 1 taken 237 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 189 times.
✓ Branch 6 taken 48 times.
|
474 | get_registered_symbols().cend()) { | |
29 | 189 | suffix++; | ||
30 |
3/6✓ Branch 1 taken 189 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 189 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 189 times.
✗ Branch 8 not taken.
|
189 | new_symbol = preferred + "_" + std::to_string(suffix); | |
31 | } | |||
32 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | register_symbol(new_symbol); | |
33 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
96 | return SymEngine::symbol(new_symbol); | |
34 | 48 | } | ||
35 | ||||
36 | 48 | void SymTable::register_symbol(const std::string& symbol) { | ||
37 | 48 | get_registered_symbols().insert(symbol); | ||
38 | 48 | } | ||
39 | ||||
40 | 1232799 | void SymTable::register_symbols(const SymSet& ss) { | ||
41 |
2/2✓ Branch 5 taken 2422 times.
✓ Branch 6 taken 1232799 times.
|
2/2✓ Decision 'true' taken 2422 times.
✓ Decision 'false' taken 1232799 times.
|
1235221 | for (const auto& s : ss) { |
42 |
3/6✓ Branch 1 taken 2422 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2422 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 2422 times.
✗ Branch 9 not taken.
|
2422 | get_registered_symbols().insert(s->get_name()); | |
43 | } | |||
44 | 1232799 | } | ||
45 | ||||
46 | } // namespace tket | |||
47 |