Maps each byte 0-255 to a unique unicode character (as UTF-8 string). Printable bytes map to themselves; non-printable bytes map to U+0100..U+0143.
| 1142 | // Maps each byte 0-255 to a unique unicode character (as UTF-8 string). |
| 1143 | // Printable bytes map to themselves; non-printable bytes map to U+0100..U+0143. |
| 1144 | static void sam3_init_byte_encoder(std::unordered_map<uint8_t, std::string>& enc) { |
| 1145 | // Collect printable byte values |
| 1146 | std::vector<int> bs; |
| 1147 | for (int i = 33; i <= 126; ++i) bs.push_back(i); |
| 1148 | for (int i = 161; i <= 172; ++i) bs.push_back(i); |
| 1149 | for (int i = 174; i <= 255; ++i) bs.push_back(i); |
| 1150 | |
| 1151 | // Corresponding codepoints (printable → identity) |
| 1152 | std::vector<int> cs(bs.begin(), bs.end()); |
| 1153 | |
| 1154 | // Non-printable bytes get codepoints starting at 256 |
| 1155 | int n = 0; |
| 1156 | for (int b = 0; b < 256; ++b) { |
| 1157 | if (std::find(bs.begin(), bs.end(), b) == bs.end()) { |
| 1158 | bs.push_back(b); |
| 1159 | cs.push_back(256 + n); |
| 1160 | n++; |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | enc.clear(); |
| 1165 | for (size_t i = 0; i < bs.size(); ++i) { |
| 1166 | enc[(uint8_t)bs[i]] = sam3_codepoint_to_utf8(cs[i]); |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | /* |
| 1171 | ** ── Merge key helper ───────────────────────────────────────────────────────── |
no test coverage detected