| 185 | |
| 186 | template <size_t BATCH_SIZE> |
| 187 | int FlatBuilder<BATCH_SIZE>::write_mapping(const std::vector<uint64_t> &keys, |
| 188 | IndexDumper *dumper) { |
| 189 | std::vector<uint32_t> mapping(keys.size()); |
| 190 | std::iota(mapping.begin(), mapping.end(), 0); |
| 191 | std::sort( |
| 192 | mapping.begin(), mapping.end(), |
| 193 | [&keys](uint32_t lhs, uint32_t rhs) { return (keys[lhs] < keys[rhs]); }); |
| 194 | |
| 195 | size_t mapping_size = mapping.size() * sizeof(uint32_t); |
| 196 | size_t mapping_padding_size = ailego_align(mapping_size, 32) - mapping_size; |
| 197 | if (dumper->write(mapping.data(), mapping_size) != mapping_size) { |
| 198 | LOG_ERROR("Failed to write data into dumper %s", dumper->name().c_str()); |
| 199 | return IndexError_WriteData; |
| 200 | } |
| 201 | |
| 202 | // Write the padding if need |
| 203 | if (mapping_padding_size) { |
| 204 | std::string padding(mapping_padding_size, '\0'); |
| 205 | if (dumper->write(padding.data(), padding.size()) != padding.size()) { |
| 206 | LOG_ERROR("Failed to write data into dumper %s", dumper->name().c_str()); |
| 207 | return IndexError_WriteData; |
| 208 | } |
| 209 | } |
| 210 | return dumper->append(FLAT_SEGMENT_MAPPING_SEG_ID, mapping_size, |
| 211 | mapping_padding_size, 0); |
| 212 | } |
| 213 | |
| 214 | template <size_t BATCH_SIZE> |
| 215 | template <typename T> |