MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / writeBoolVector

Function writeBoolVector

include/storage/serialization.hpp:79–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77
78template <typename VectorT>
79void writeBoolVector(tar::FileWriter &writer, const std::string &name, const VectorT &data)
80{
81 const auto count = data.size();
82 writer.WriteElementCount64(name, count);
83 std::uint64_t index = 0;
84
85 using BlockType = std::uint64_t;
86 constexpr std::uint64_t BLOCK_BITS = CHAR_BIT * sizeof(BlockType);
87
88 // FIXME on old boost version the function_input_iterator does not work with lambdas
89 // so we need to wrap it in a function here.
90 const std::function<BlockType()> encode_function = [&]() -> BlockType
91 {
92 auto write_size = std::min<std::size_t>(count - index, BLOCK_BITS);
93 auto packed = packBits<VectorT, BlockType>(data, index, write_size);
94 index += BLOCK_BITS;
95 return packed;
96 };
97
98 std::uint64_t number_of_blocks = (count + BLOCK_BITS - 1) / BLOCK_BITS;
99 writer.WriteStreaming<BlockType>(
100 name, osrm::util::make_function_input_iterator(encode_function), number_of_blocks);
101}
102} // namespace detail
103
104/* All vector formats here use the same on-disk format.

Callers 1

write<bool>Function · 0.85

Calls 3

sizeMethod · 0.45
WriteElementCount64Method · 0.45

Tested by

no test coverage detected