MCPcopy Create free account
hub / github.com/alibaba/zvec / EncodeUniformUint8Record

Function EncodeUniformUint8Record

tests/core/algorithm/flat/flat_streamer_test.cc:121–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119} // namespace zvec
120
121std::string EncodeUniformUint8Record(size_t dimension, uint32_t seed) {
122 std::string record(dimension + sizeof(uint32_t), '\0');
123 uint32_t sum_squared = 0;
124 for (size_t d = 0; d < dimension; ++d) {
125 const uint8_t code =
126 static_cast<uint8_t>((seed * 73U + d * 29U + d * seed * 3U) & 0xffU);
127 record[d] = static_cast<char>(static_cast<int>(code) - 128);
128 sum_squared += static_cast<uint32_t>(code) * code;
129 }
130 std::memcpy(record.data() + dimension, &sum_squared, sizeof(sum_squared));
131 return record;
132}
133
134class FlatStreamerTest : public testing::Test {
135 protected:

Callers 1

TEST_FFunction · 0.70

Calls 1

dataMethod · 0.45

Tested by

no test coverage detected