| 190 | } |
| 191 | |
| 192 | void sample_result::append(const ExecutionResult &result, bool concatenate) { |
| 193 | // If given a result corresponding to the same register name, either a) |
| 194 | // replace the existing one if concatenate is false, or b) if concatenate is |
| 195 | // true, stitch the bitstrings from "result" into the existing one. |
| 196 | auto iter = sampleResults.find(result.registerName); |
| 197 | if (iter != sampleResults.end()) { |
| 198 | auto &existingExecResult = iter->second; |
| 199 | if (concatenate) { |
| 200 | // Stitch the bitstrings together |
| 201 | if (this->totalShots == result.sequentialData.size()) { |
| 202 | existingExecResult.counts.clear(); |
| 203 | for (std::size_t i = 0; i < this->totalShots; i++) { |
| 204 | std::string newStr = |
| 205 | existingExecResult.sequentialData[i] + result.sequentialData[i]; |
| 206 | existingExecResult.counts[newStr]++; |
| 207 | existingExecResult.sequentialData[i] = std::move(newStr); |
| 208 | } |
| 209 | } |
| 210 | } else { |
| 211 | // Replace the existing one |
| 212 | existingExecResult = result; |
| 213 | } |
| 214 | } else { |
| 215 | sampleResults.insert({result.registerName, result}); |
| 216 | } |
| 217 | if (!totalShots) |
| 218 | for (auto &[bits, count] : result.counts) |
| 219 | totalShots += count; |
| 220 | } |
| 221 | |
| 222 | bool sample_result::operator==(const sample_result &counts) const { |
| 223 | return sampleResults == counts.sampleResults; |
no test coverage detected