MCPcopy Create free account
hub / github.com/comaps/comaps / WriteVarUInt32SortedShortArray

Function WriteVarUInt32SortedShortArray

libs/coding/varint.hpp:304–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302/// @{
303template <class Sink>
304void WriteVarUInt32SortedShortArray(std::vector<uint32_t> const & cont, Sink & sink)
305{
306 CHECK(!cont.empty(), ());
307 CHECK(base::IsSortedAndUnique(cont), ());
308
309 uint32_t prev = 0;
310 size_t const sz = cont.size();
311 for (size_t i = 0; i < sz; ++i)
312 {
313 uint32_t v = cont[i] - prev;
314 prev = cont[i];
315
316 CHECK((v & (uint32_t(3) << 30)) == 0, ()); // leading 2 bits are zeros
317 v <<= 1;
318 // set 1-bit if have a next value
319 if (i + 1 < sz)
320 v |= 0x1;
321
322 WriteVarUint(sink, v);
323 }
324}
325
326/// @todo Refactor on raw pointers (same as ReadXXX functions above).
327/// ArrayByteSource isn't as fast as pointers :)

Callers 1

UNIT_TESTFunction · 0.85

Calls 4

IsSortedAndUniqueFunction · 0.85
WriteVarUintFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45

Tested by 1

UNIT_TESTFunction · 0.68