| 1278 | |
| 1279 | |
| 1280 | string getPauliStrAsIndexString(PauliStr str, int numPaulis) { |
| 1281 | |
| 1282 | string out = ""; |
| 1283 | |
| 1284 | // prematurely optimise (hehe) by avoiding repeated allocations |
| 1285 | // induced by below string concatenation, since we can bound the |
| 1286 | // string length; each Pauli is 1 char, each index is max 2 digits |
| 1287 | // (<64) and each inter-Pauli space is 1 char, so <=4 chars per Pauli. |
| 1288 | int maxLen = numPaulis * 4; // <= 256 always |
| 1289 | out.reserve(maxLen); |
| 1290 | |
| 1291 | for (int i=0; i<numPaulis; i++) { |
| 1292 | int code = paulis_getPauliAt(str, i); |
| 1293 | |
| 1294 | // don't report identities |
| 1295 | if (code == 0) |
| 1296 | continue; |
| 1297 | |
| 1298 | // e.g. X12 |
| 1299 | out += global_pauliChars[code] + toStr(i) + PAULI_SPACE_CHAR; |
| 1300 | } |
| 1301 | |
| 1302 | // out includes a trailing PAULI_SPACE_CHAR which is fine, |
| 1303 | // since nothing else is ever post-printed on the same line |
| 1304 | return out; |
| 1305 | } |
| 1306 | |
| 1307 | |
| 1308 | string getPauliStrAsString(PauliStr str, int numPauliChars=0) { |
no test coverage detected