Format all C++ and Java code via clang-format

Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
Konstantin Pastbin
2025-08-17 14:32:37 +07:00
parent 9f0290c0ec
commit bfffa1fff4
2169 changed files with 56441 additions and 64188 deletions

View File

@@ -23,7 +23,7 @@ namespace base64
{
// From: http://stackoverflow.com/a/28471421
std::string Decode(const std::string & val)
std::string Decode(std::string const & val)
{
using namespace boost::archive::iterators;
using It = transform_width<binary_from_base64<std::string::const_iterator>, 8, 6>;

View File

@@ -8,7 +8,6 @@
#include <climits>
#include <cstdint>
static_assert(CHAR_BIT == 8);
template <typename TWriter>
@@ -168,13 +167,12 @@ public:
return result;
}
#define READ_BYTE(i) \
{ \
result = \
result | (static_cast<decltype(result)>(Read(std::min(n, kMinBits))) << (i * kMinBits)); \
if (n <= kMinBits) \
return result; \
n -= kMinBits; \
#define READ_BYTE(i) \
{ \
result = result | (static_cast<decltype(result)>(Read(std::min(n, kMinBits))) << (i * kMinBits)); \
if (n <= kMinBits) \
return result; \
n -= kMinBits; \
}
// Same as Read but accept up to 32 bits to read.

View File

@@ -35,10 +35,7 @@ public:
memcpy(p, m_data.get() + static_cast<size_t>(pos) + m_offset, size);
}
BufferReader SubReader(uint64_t pos, uint64_t size) const
{
return BufferReader(*this, pos, size);
}
BufferReader SubReader(uint64_t pos, uint64_t size) const { return BufferReader(*this, pos, size); }
std::unique_ptr<Reader> CreateSubReader(uint64_t pos, uint64_t size) const
{
@@ -47,8 +44,7 @@ public:
}
private:
BufferReader(BufferReader const & src, uint64_t pos, uint64_t size)
: m_data(src.m_data)
BufferReader(BufferReader const & src, uint64_t pos, uint64_t size) : m_data(src.m_data)
{
ASSERT_LESS_OR_EQUAL(pos + size, src.Size(), (pos, size));
@@ -67,7 +63,7 @@ private:
struct Deleter
{
void operator() (char * p) { delete [] p; }
void operator()(char * p) { delete[] p; }
};
std::shared_ptr<char> m_data;

View File

@@ -4,8 +4,7 @@
#include "base/assert.hpp"
BufferedFileWriter::BufferedFileWriter(std::string const & fileName,
Op operation /* = OP_WRITE_TRUNCATE */,
BufferedFileWriter::BufferedFileWriter(std::string const & fileName, Op operation /* = OP_WRITE_TRUNCATE */,
size_t bufferSize /* = 4096 */)
: FileWriter(fileName, operation)
{

View File

@@ -9,8 +9,7 @@
class BufferedFileWriter : public FileWriter
{
public:
explicit BufferedFileWriter(std::string const & fileName, Op operation = OP_WRITE_TRUNCATE,
size_t bufferSize = 4096);
explicit BufferedFileWriter(std::string const & fileName, Op operation = OP_WRITE_TRUNCATE, size_t bufferSize = 4096);
~BufferedFileWriter() noexcept(false) override;

View File

@@ -9,7 +9,7 @@
class ArrayByteSource
{
public:
explicit ArrayByteSource(const void * p) : m_p(static_cast<uint8_t const *>(p)) {}
explicit ArrayByteSource(void const * p) : m_p(static_cast<uint8_t const *>(p)) {}
uint8_t ReadByte() { return *m_p++; }
@@ -22,22 +22,17 @@ public:
void const * Ptr() const { return m_p; }
uint8_t const * PtrUint8() const { return m_p; }
void Advance(size_t size)
{
m_p += size;
}
void Advance(size_t size) { m_p += size; }
private:
uint8_t const * m_p;
};
template <class StorageT> class PushBackByteSink
template <class StorageT>
class PushBackByteSink
{
public:
explicit PushBackByteSink(StorageT & storage)
: m_Storage(storage)
{
}
explicit PushBackByteSink(StorageT & storage) : m_Storage(storage) {}
void Write(void const * p, size_t size)
{
@@ -46,10 +41,8 @@ public:
m_Storage.insert(m_Storage.end(), pp, pp + size);
}
size_t Pos() const
{
return m_Storage.size();
}
size_t Pos() const { return m_Storage.size(); }
private:
StorageT & m_Storage;
};
@@ -60,6 +53,7 @@ public:
CountingSink() : m_Count(0) {}
inline void Write(void const *, size_t size) { m_Count += size; }
inline size_t GetCount() const { return m_Count; }
private:
size_t m_Count;
};

View File

@@ -2,14 +2,13 @@
#include "coding/base64.hpp"
using namespace base64;
UNIT_TEST(Base64_Smoke)
{
char const * bytes[] = {"H", "He", "Hel", "Hell", "Hello", "Hello,", "Hello, ", "Hello, World!"};
char const * encoded[] = {"SA==", "SGU=", "SGVs", "SGVsbA==", "SGVsbG8=", "SGVsbG8s",
"SGVsbG8sIA==", "SGVsbG8sIFdvcmxkIQ=="};
char const * encoded[] = {
"SA==", "SGU=", "SGVs", "SGVsbA==", "SGVsbG8=", "SGVsbG8s", "SGVsbG8sIA==", "SGVsbG8sIFdvcmxkIQ=="};
TEST_EQUAL(ARRAY_SIZE(bytes), ARRAY_SIZE(encoded), ());
@@ -22,7 +21,8 @@ UNIT_TEST(Base64_Smoke)
}
char const * str = "MapsWithMe is the offline maps application for any device in the world.";
char const * encStr = "TWFwc1dpdGhNZSBpcyB0aGUgb2ZmbGluZSBtYXBzIGFwcGxpY2F0aW9uIGZvciBhbnkgZGV2aWNlIGluIHRoZSB3b3JsZC4=";
char const * encStr =
"TWFwc1dpdGhNZSBpcyB0aGUgb2ZmbGluZSBtYXBzIGFwcGxpY2F0aW9uIGZvciBhbnkgZGV2aWNlIGluIHRoZSB3b3JsZC4=";
TEST_EQUAL(Encode(str), encStr, ());
TEST_EQUAL(Decode(encStr), str, ());
}

View File

@@ -84,12 +84,10 @@ UNIT_TEST(BitStreams_Large)
BitWriter<TWriter> bits(w);
for (int i = 0; i <= 64; ++i)
{
if (i <= 32)
bits.WriteAtMost32Bits(static_cast<uint32_t>(kMask), i);
else
bits.WriteAtMost64Bits(kMask, i);
}
}
{

View File

@@ -18,24 +18,21 @@ void Intersect(vector<uint64_t> & setBits1, vector<uint64_t> & setBits2, vector<
{
sort(setBits1.begin(), setBits1.end());
sort(setBits2.begin(), setBits2.end());
set_intersection(setBits1.begin(), setBits1.end(), setBits2.begin(), setBits2.end(),
back_inserter(result));
set_intersection(setBits1.begin(), setBits1.end(), setBits2.begin(), setBits2.end(), back_inserter(result));
}
void Subtract(vector<uint64_t> & setBits1, vector<uint64_t> & setBits2, vector<uint64_t> & result)
{
sort(setBits1.begin(), setBits1.end());
sort(setBits2.begin(), setBits2.end());
set_difference(setBits1.begin(), setBits1.end(), setBits2.begin(), setBits2.end(),
back_inserter(result));
set_difference(setBits1.begin(), setBits1.end(), setBits2.begin(), setBits2.end(), back_inserter(result));
}
void Union(vector<uint64_t> & setBits1, vector<uint64_t> & setBits2, vector<uint64_t> & result)
{
sort(setBits1.begin(), setBits1.end());
sort(setBits2.begin(), setBits2.end());
set_union(setBits1.begin(), setBits1.end(), setBits2.begin(), setBits2.end(),
back_inserter(result));
set_union(setBits1.begin(), setBits1.end(), setBits2.begin(), setBits2.end(), back_inserter(result));
}
template <typename TBinaryOp>
@@ -56,14 +53,12 @@ void CheckIntersection(vector<uint64_t> & setBits1, vector<uint64_t> & setBits2,
CheckBinaryOp(&Intersect, setBits1, setBits2, cbv);
}
void CheckSubtraction(vector<uint64_t> & setBits1, vector<uint64_t> & setBits2,
coding::CompressedBitVector const & cbv)
void CheckSubtraction(vector<uint64_t> & setBits1, vector<uint64_t> & setBits2, coding::CompressedBitVector const & cbv)
{
CheckBinaryOp(&Subtract, setBits1, setBits2, cbv);
}
void CheckUnion(vector<uint64_t> & setBits1, vector<uint64_t> & setBits2,
coding::CompressedBitVector const & cbv)
void CheckUnion(vector<uint64_t> & setBits1, vector<uint64_t> & setBits2, coding::CompressedBitVector const & cbv)
{
CheckBinaryOp(&Union, setBits1, setBits2, cbv);
}
@@ -249,8 +244,8 @@ UNIT_TEST(CompressedBitVector_Union_Smoke)
vector<uint64_t> setBits1 = {};
vector<uint64_t> setBits2 = {};
CheckUnion(setBits1, coding::CompressedBitVector::StorageStrategy::Sparse /* strategy1 */,
setBits2, coding::CompressedBitVector::StorageStrategy::Sparse /* strategy2 */,
CheckUnion(setBits1, coding::CompressedBitVector::StorageStrategy::Sparse /* strategy1 */, setBits2,
coding::CompressedBitVector::StorageStrategy::Sparse /* strategy2 */,
coding::CompressedBitVector::StorageStrategy::Sparse /* resultStrategy */);
}
@@ -259,8 +254,8 @@ UNIT_TEST(CompressedBitVector_Union1)
vector<uint64_t> setBits1 = {};
vector<uint64_t> setBits2 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
CheckUnion(setBits1, coding::CompressedBitVector::StorageStrategy::Sparse /* strategy1 */,
setBits2, coding::CompressedBitVector::StorageStrategy::Dense /* strategy2 */,
CheckUnion(setBits1, coding::CompressedBitVector::StorageStrategy::Sparse /* strategy1 */, setBits2,
coding::CompressedBitVector::StorageStrategy::Dense /* strategy2 */,
coding::CompressedBitVector::StorageStrategy::Dense /* resultStrategy */);
}
@@ -269,8 +264,8 @@ UNIT_TEST(CompressedBitVector_Union2)
vector<uint64_t> setBits1 = {256, 1024};
vector<uint64_t> setBits2 = {0, 32, 64};
CheckUnion(setBits1, coding::CompressedBitVector::StorageStrategy::Sparse /* strategy1 */,
setBits2, coding::CompressedBitVector::StorageStrategy::Sparse /* strategy2 */,
CheckUnion(setBits1, coding::CompressedBitVector::StorageStrategy::Sparse /* strategy1 */, setBits2,
coding::CompressedBitVector::StorageStrategy::Sparse /* strategy2 */,
coding::CompressedBitVector::StorageStrategy::Sparse /* resultStrategy */);
}
@@ -282,8 +277,8 @@ UNIT_TEST(CompressedBitVector_Union3)
for (int i = 0; i < 256; ++i)
setBits2.push_back(i);
CheckUnion(setBits1, coding::CompressedBitVector::StorageStrategy::Dense /* strategy1 */,
setBits2, coding::CompressedBitVector::StorageStrategy::Dense /* strategy2 */,
CheckUnion(setBits1, coding::CompressedBitVector::StorageStrategy::Dense /* strategy1 */, setBits2,
coding::CompressedBitVector::StorageStrategy::Dense /* strategy2 */,
coding::CompressedBitVector::StorageStrategy::Dense /* resultStrategy */);
}
@@ -295,8 +290,8 @@ UNIT_TEST(CompressedBitVector_Union4)
vector<uint64_t> setBits2 = {1000000000};
CheckUnion(setBits1, coding::CompressedBitVector::StorageStrategy::Dense /* strategy1 */,
setBits2, coding::CompressedBitVector::StorageStrategy::Sparse /* strategy2 */,
CheckUnion(setBits1, coding::CompressedBitVector::StorageStrategy::Dense /* strategy1 */, setBits2,
coding::CompressedBitVector::StorageStrategy::Sparse /* strategy2 */,
coding::CompressedBitVector::StorageStrategy::Sparse /* resultStrategy */);
}
@@ -328,10 +323,8 @@ UNIT_TEST(CompressedBitVector_SerializationSparse)
int const kNumBits = 100;
vector<uint64_t> setBits;
for (size_t i = 0; i < kNumBits; ++i)
{
if (i % 10 == 0)
setBits.push_back(i);
}
vector<uint8_t> buf;
{
MemWriter<vector<uint8_t>> writer(buf);
@@ -361,25 +354,20 @@ UNIT_TEST(CompressedBitVector_ForEach)
}
auto denseCBV = coding::CompressedBitVectorBuilder::FromBitPositions(denseBits);
auto sparseCBV = coding::CompressedBitVectorBuilder::FromBitPositions(sparseBits);
TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Dense, denseCBV->GetStorageStrategy(),
());
TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Sparse, sparseCBV->GetStorageStrategy(),
());
TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Dense, denseCBV->GetStorageStrategy(), ());
TEST_EQUAL(coding::CompressedBitVector::StorageStrategy::Sparse, sparseCBV->GetStorageStrategy(), ());
set<uint64_t> denseSet;
uint64_t maxPos = 0;
coding::CompressedBitVectorEnumerator::ForEach(*denseCBV, [&](uint64_t pos)
{
denseSet.insert(pos);
maxPos = max(maxPos, pos);
});
{
denseSet.insert(pos);
maxPos = max(maxPos, pos);
});
TEST_EQUAL(denseSet.size(), kNumBits, ());
TEST_EQUAL(maxPos, kNumBits - 1, ());
coding::CompressedBitVectorEnumerator::ForEach(*sparseCBV, [](uint64_t pos)
{
TEST_EQUAL(pos % 15, 0, ());
});
coding::CompressedBitVectorEnumerator::ForEach(*sparseCBV, [](uint64_t pos) { TEST_EQUAL(pos % 15, 0, ()); });
}
UNIT_TEST(CompressedBitVector_DenseOneBit)
@@ -387,10 +375,7 @@ UNIT_TEST(CompressedBitVector_DenseOneBit)
vector<uint64_t> setBits = {0};
unique_ptr<coding::DenseCBV> cbv(new coding::DenseCBV(setBits));
TEST_EQUAL(cbv->PopCount(), 1, ());
coding::CompressedBitVectorEnumerator::ForEach(*cbv, [&](uint64_t pos)
{
TEST_EQUAL(pos, 0, ());
});
coding::CompressedBitVectorEnumerator::ForEach(*cbv, [&](uint64_t pos) { TEST_EQUAL(pos, 0, ()); });
}
UNIT_TEST(CompressedBitVector_LeaveFirstNBitsSmoke)
@@ -450,22 +435,18 @@ UNIT_TEST(CompressedBitVector_SparseLeaveFirstNBits)
cbv = cbv->LeaveFirstSetNBits(100);
TEST_EQUAL(cbv->PopCount(), 10, ());
for (uint64_t bit = 0; bit < (1 << 10); ++bit)
{
if (bit != 0 && (bit & (bit - 1)) == 0)
TEST(cbv->GetBit(bit), (bit));
else
TEST(!cbv->GetBit(bit), (bit));
}
cbv = cbv->LeaveFirstSetNBits(8);
TEST_EQUAL(cbv->PopCount(), 8, ());
for (uint64_t bit = 0; bit < (1 << 10); ++bit)
{
if (bit != 0 && (bit & (bit - 1)) == 0 && bit < (1 << 8))
TEST(cbv->GetBit(bit), (bit));
else
TEST(!cbv->GetBit(bit), (bit));
}
cbv = cbv->LeaveFirstSetNBits(0);
TEST_EQUAL(cbv->PopCount(), 0, ());

View File

@@ -144,7 +144,8 @@ UNIT_TEST(CSVReaderForEachRow)
FileReader fileReader(sf.GetFullPath());
auto reader = coding::CSVReader(fileReader);
size_t index = 0;
reader.ForEachRow([&](auto const & row) {
reader.ForEachRow([&](auto const & row)
{
TEST_EQUAL(row, answer[index], ());
++index;
});
@@ -202,10 +203,12 @@ UNIT_TEST(CSVReaderEmptyColumns)
UNIT_TEST(CSVReaderQuotes)
{
auto const kContentWithQuotes = R"(noquotes, "" , "with space","with, comma","""double"" quotes","""double,"", commas", """""",)";
auto const kContentWithQuotes =
R"(noquotes, "" , "with space","with, comma","""double"" quotes","""double,"", commas", """""",)";
auto const fileName = "test.csv";
ScopedFile sf(fileName, kContentWithQuotes);
Rows const answer = {{"noquotes", "", "with space", "with, comma", "\"double\" quotes", "\"double,\", commas","\"\"", ""}};
Rows const answer = {
{"noquotes", "", "with space", "with, comma", "\"double\" quotes", "\"double,\", commas", "\"\"", ""}};
coding::CSVReader reader(sf.GetFullPath());
size_t index = 0;
while (auto const optionalRow = reader.ReadRow())

View File

@@ -18,10 +18,10 @@ using namespace std;
UNIT_TEST(MyersSimpleDiff)
{
vector<char> tmp;
PushBackByteSink<vector<char> > sink(tmp);
PushBackByteSink<vector<char>> sink(tmp);
TEST_EQUAL(4, diff::DiffMyersSimple(string("axxxb"), string("cxxxd"), 5, sink), ());
TEST_EQUAL(5, diff::DiffMyersSimple(string("abcabba"), string("cbabac"), 10, sink), ());
TEST_EQUAL(5, diff::DiffMyersSimple(string("abcabba"), string("cbabac"), 5, sink), ());
TEST_EQUAL(5, diff::DiffMyersSimple(string("abcabba"), string("cbabac"), 10, sink), ());
TEST_EQUAL(5, diff::DiffMyersSimple(string("abcabba"), string("cbabac"), 5, sink), ());
TEST_EQUAL(-1, diff::DiffMyersSimple(string("abcabba"), string("cbabac"), 4, sink), ());
TEST_EQUAL(-1, diff::DiffMyersSimple(string("abcabba"), string("cbabac"), 2, sink), ());
TEST_EQUAL(-1, diff::DiffMyersSimple(string("abcabba"), string("cbabac"), 1, sink), ());
@@ -30,21 +30,16 @@ UNIT_TEST(MyersSimpleDiff)
class TestPatchWriter
{
public:
template <typename IterT> void WriteData(IterT it, uint64_t n)
template <typename IterT>
void WriteData(IterT it, uint64_t n)
{
for (uint64_t i = 0; i < n; ++i, ++it)
m_Stream << *it;
}
void WriteOperation(uint64_t op)
{
m_Stream << op << ".";
}
void WriteOperation(uint64_t op) { m_Stream << op << "."; }
string Str()
{
return m_Stream.str();
}
string Str() { return m_Stream.str(); }
private:
ostringstream m_Stream;
@@ -113,7 +108,8 @@ public:
m_Stream << "-" << n << ".";
}
template <typename IterT> void Insert(IterT it, size_t n)
template <typename IterT>
void Insert(IterT it, size_t n)
{
if (n == 0)
return;
@@ -124,6 +120,7 @@ public:
}
void Finalize() {}
string Str() { return m_Stream.str(); }
private:
ostringstream m_Stream;
};
@@ -134,8 +131,8 @@ UNIT_TEST(DiffSimpleReplace)
char const dst[] = "abcyydef";
MemReader srcReader(src, ARRAY_SIZE(src) - 1);
MemReader dstReader(dst, ARRAY_SIZE(dst) - 1);
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
diff::SimpleReplaceDiffer differ;
@@ -156,8 +153,8 @@ UNIT_TEST(DiffSimpleReplaceEmptyBegin)
char const dst[] = "yydef";
MemReader srcReader(src, ARRAY_SIZE(src) - 1);
MemReader dstReader(dst, ARRAY_SIZE(dst) - 1);
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
diff::SimpleReplaceDiffer differ;
@@ -178,8 +175,8 @@ UNIT_TEST(DiffSimpleReplaceEmptyEnd)
char const dst[] = "abcyy";
MemReader srcReader(src, ARRAY_SIZE(src) - 1);
MemReader dstReader(dst, ARRAY_SIZE(dst) - 1);
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
diff::SimpleReplaceDiffer differ;
@@ -200,8 +197,8 @@ UNIT_TEST(DiffSimpleReplaceAllEqual)
char const dst[] = "abcdef";
MemReader srcReader(src, ARRAY_SIZE(src) - 1);
MemReader dstReader(dst, ARRAY_SIZE(dst) - 1);
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
diff::SimpleReplaceDiffer differ;
@@ -222,8 +219,8 @@ UNIT_TEST(DiffWithRollingHashEqualStrings)
char const dst[] = "abcdefklmno";
MemReader srcReader(src, ARRAY_SIZE(src) - 1);
MemReader dstReader(dst, ARRAY_SIZE(dst) - 1);
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
diff::RollingHashDiffer<diff::SimpleReplaceDiffer, RollingHasher64> differ(3);
@@ -238,8 +235,8 @@ UNIT_TEST(DiffWithRollingHashCompletelyDifferentStrings)
char const dst[] = "abcdefgh";
MemReader srcReader(src, ARRAY_SIZE(src) - 1);
MemReader dstReader(dst, ARRAY_SIZE(dst) - 1);
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
diff::RollingHashDiffer<diff::SimpleReplaceDiffer, RollingHasher64> differ(3);
@@ -254,8 +251,8 @@ UNIT_TEST(DiffWithRollingHash1)
char const dst[] = "abcdfeghikkklmnop";
MemReader srcReader(src, ARRAY_SIZE(src) - 1);
MemReader dstReader(dst, ARRAY_SIZE(dst) - 1);
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
diff::RollingHashDiffer<diff::SimpleReplaceDiffer, RollingHasher64> differ(3);
@@ -270,8 +267,8 @@ UNIT_TEST(DiffWithRollingHash2)
char const dst[] = "abxdeflmnop";
MemReader srcReader(src, ARRAY_SIZE(src) - 1);
MemReader dstReader(dst, ARRAY_SIZE(dst) - 1);
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
DDVector<char, MemReader> srcV(srcReader); // since sizeof(char) == 1
DDVector<char, MemReader> dstV(dstReader); // since sizeof(char) == 1
diff::RollingHashDiffer<diff::SimpleReplaceDiffer, RollingHasher64> differ(3);

View File

@@ -51,6 +51,12 @@ void TestCoder(std::string const & name)
}
}
UNIT_TEST(EliasCoder_Gamma) { TestCoder<coding::GammaCoder>("Gamma"); }
UNIT_TEST(EliasCoder_Delta) { TestCoder<coding::DeltaCoder>("Delta"); }
UNIT_TEST(EliasCoder_Gamma)
{
TestCoder<coding::GammaCoder>("Gamma");
}
UNIT_TEST(EliasCoder_Delta)
{
TestCoder<coding::DeltaCoder>("Delta");
}
} // namespace

View File

@@ -2,40 +2,39 @@
#include "coding/endianness.hpp"
UNIT_TEST(Endianness1Byte)
{
TEST_EQUAL(uint8_t(0), ReverseByteOrder<uint8_t>(0), ());
TEST_EQUAL(uint8_t(17), ReverseByteOrder<uint8_t>(17), ());
TEST_EQUAL(uint8_t(0), ReverseByteOrder<uint8_t>(0), ());
TEST_EQUAL(uint8_t(17), ReverseByteOrder<uint8_t>(17), ());
TEST_EQUAL(uint8_t(255), ReverseByteOrder<uint8_t>(255), ());
TEST_EQUAL(uint8_t(0), ReverseByteOrder<uint8_t>(0), ());
TEST_EQUAL(uint8_t(17), ReverseByteOrder<uint8_t>(17), ());
TEST_EQUAL(uint8_t(0), ReverseByteOrder<uint8_t>(0), ());
TEST_EQUAL(uint8_t(17), ReverseByteOrder<uint8_t>(17), ());
TEST_EQUAL(uint8_t(255), ReverseByteOrder<uint8_t>(255), ());
}
UNIT_TEST(Endianness12Bytes)
{
TEST_EQUAL(uint16_t(0), ReverseByteOrder<uint16_t>(0), ());
TEST_EQUAL(uint16_t(256), ReverseByteOrder<uint16_t>(1), ());
TEST_EQUAL(uint16_t(0), ReverseByteOrder<uint16_t>(0), ());
TEST_EQUAL(uint16_t(256), ReverseByteOrder<uint16_t>(1), ());
TEST_EQUAL(uint16_t(0xE8FD), ReverseByteOrder<uint16_t>(0xFDE8), ());
TEST_EQUAL(uint16_t(0xFFFF), ReverseByteOrder<uint16_t>(0xFFFF), ());
TEST_EQUAL(uint16_t(0), ReverseByteOrder<uint16_t>(0), ());
TEST_EQUAL(uint16_t(256), ReverseByteOrder<uint16_t>(1), ());
TEST_EQUAL(uint16_t(0), ReverseByteOrder<uint16_t>(0), ());
TEST_EQUAL(uint16_t(256), ReverseByteOrder<uint16_t>(1), ());
TEST_EQUAL(uint16_t(0xE8FD), ReverseByteOrder<uint16_t>(0xFDE8), ());
TEST_EQUAL(uint16_t(0xFFFF), ReverseByteOrder<uint16_t>(0xFFFF), ());
}
UNIT_TEST(Endianness18Bytes)
{
TEST_EQUAL(0ULL, ReverseByteOrder(0ULL), ());
TEST_EQUAL(1ULL, ReverseByteOrder(1ULL << 56), ());
TEST_EQUAL(0xE2E4D7D5B1C3B8C6ULL, ReverseByteOrder(0xC6B8C3B1D5D7E4E2ULL), ());
TEST_EQUAL(0xFFFFFFFFFFFFFFFFULL, ReverseByteOrder(0xFFFFFFFFFFFFFFFFULL), ());
TEST_EQUAL(0ULL, ReverseByteOrder(0ULL), ());
TEST_EQUAL(1ULL, ReverseByteOrder(1ULL << 56), ());
TEST_EQUAL(0xE2E4D7D5B1C3B8C6ULL, ReverseByteOrder(0xC6B8C3B1D5D7E4E2ULL), ());
TEST_EQUAL(0xFFFFFFFFFFFFFFFFULL, ReverseByteOrder(0xFFFFFFFFFFFFFFFFULL), ());
TEST_EQUAL(0ULL, ReverseByteOrder(0ULL), ());
TEST_EQUAL(1ULL, ReverseByteOrder(1ULL << 56), ());
TEST_EQUAL(0xE2E4D7D5B1C3B8C6ULL, ReverseByteOrder(0xC6B8C3B1D5D7E4E2ULL), ());
TEST_EQUAL(0xFFFFFFFFFFFFFFFFULL, ReverseByteOrder(0xFFFFFFFFFFFFFFFFULL), ());
TEST_EQUAL(0ULL, ReverseByteOrder(0ULL), ());
TEST_EQUAL(1ULL, ReverseByteOrder(1ULL << 56), ());
TEST_EQUAL(0xE2E4D7D5B1C3B8C6ULL, ReverseByteOrder(0xC6B8C3B1D5D7E4E2ULL), ());
TEST_EQUAL(0xFFFFFFFFFFFFFFFFULL, ReverseByteOrder(0xFFFFFFFFFFFFFFFFULL), ());
}

View File

@@ -6,36 +6,35 @@
#include <fstream>
#include <string>
namespace file_data_test
{
std::string const name1 = "test1.file";
std::string const name2 = "test2.file";
std::string const name1 = "test1.file";
std::string const name2 = "test2.file";
void MakeFile(std::string const & name)
{
base::FileData f(name, base::FileData::Op::WRITE_TRUNCATE);
f.Write(name.c_str(), name.size());
}
void MakeFile(std::string const & name)
{
base::FileData f(name, base::FileData::Op::WRITE_TRUNCATE);
f.Write(name.c_str(), name.size());
}
void MakeFile(std::string const & name, size_t const size, const char c)
{
base::FileData f(name, base::FileData::Op::WRITE_TRUNCATE);
f.Write(std::string(size, c).c_str(), size);
}
void MakeFile(std::string const & name, size_t const size, char const c)
{
base::FileData f(name, base::FileData::Op::WRITE_TRUNCATE);
f.Write(std::string(size, c).c_str(), size);
}
#ifdef OMIM_OS_WINDOWS
void CheckFileOK(std::string const & name)
{
base::FileData f(name, base::FileData::Op::READ);
void CheckFileOK(std::string const & name)
{
base::FileData f(name, base::FileData::Op::READ);
uint64_t const size = f.Size();
TEST_EQUAL ( size, name.size(), () );
uint64_t const size = f.Size();
TEST_EQUAL(size, name.size(), ());
std::vector<char> buffer(size);
f.Read(0, &buffer[0], size);
TEST ( equal(name.begin(), name.end(), buffer.begin()), () );
}
std::vector<char> buffer(size);
f.Read(0, &buffer[0], size);
TEST(equal(name.begin(), name.end(), buffer.begin()), ());
}
#endif
UNIT_TEST(FileData_ApiSmoke)
@@ -202,7 +201,7 @@ UNIT_TEST(EmptyFile)
// Do copy.
TEST(CopyFileX(name, copy), ());
//TEST(!RenameFileX(name, copy), ());
// TEST(!RenameFileX(name, copy), ());
// Delete copy file and rename name -> copy.
TEST(DeleteFileX(copy), ());
@@ -252,7 +251,7 @@ UNIT_TEST(File_StdGetLine)
{
std::string const fName = "test.txt";
for (char const * buffer : { "x\nxy\nxyz\nxyzk", "x\nxy\nxyz\nxyzk\n" })
for (char const * buffer : {"x\nxy\nxyz\nxyzk", "x\nxy\nxyz\nxyzk\n"})
{
{
base::FileData f(fName, base::FileData::Op::WRITE_TRUNCATE);
@@ -276,4 +275,4 @@ UNIT_TEST(File_StdGetLine)
}
}
} // namespace file_data_test
} // namespace file_data_test

View File

@@ -1,8 +1,8 @@
#include "testing/testing.hpp"
#include "coding/file_sort.hpp"
#include "coding/write_to_sink.hpp"
#include "coding/reader.hpp"
#include "coding/write_to_sink.hpp"
#include <algorithm>
#include <cstddef>
@@ -14,27 +14,27 @@ using namespace std;
namespace
{
void TestFileSorter(vector<uint32_t> & data, char const * tmpFileName, size_t bufferSize)
{
vector<char> serial;
typedef MemWriter<vector<char> > MemWriterType;
MemWriterType writer(serial);
typedef WriterFunctor<MemWriterType> OutT;
OutT out(writer);
FileSorter<uint32_t, OutT> sorter(bufferSize, tmpFileName, out);
for (size_t i = 0; i < data.size(); ++i)
sorter.Add(data[i]);
sorter.SortAndFinish();
void TestFileSorter(vector<uint32_t> & data, char const * tmpFileName, size_t bufferSize)
{
vector<char> serial;
typedef MemWriter<vector<char>> MemWriterType;
MemWriterType writer(serial);
typedef WriterFunctor<MemWriterType> OutT;
OutT out(writer);
FileSorter<uint32_t, OutT> sorter(bufferSize, tmpFileName, out);
for (size_t i = 0; i < data.size(); ++i)
sorter.Add(data[i]);
sorter.SortAndFinish();
TEST_EQUAL(serial.size(), data.size() * sizeof(data[0]), ());
sort(data.begin(), data.end());
MemReader reader(&serial[0], serial.size());
TEST_EQUAL(reader.Size(), data.size() * sizeof(data[0]), ());
vector<uint32_t> result(data.size());
reader.Read(0, &result[0], reader.Size());
TEST_EQUAL(result, data, ());
}
TEST_EQUAL(serial.size(), data.size() * sizeof(data[0]), ());
sort(data.begin(), data.end());
MemReader reader(&serial[0], serial.size());
TEST_EQUAL(reader.Size(), data.size() * sizeof(data[0]), ());
vector<uint32_t> result(data.size());
reader.Read(0, &result[0], reader.Size());
TEST_EQUAL(result, data, ());
}
} // namespace
UNIT_TEST(FileSorter_Smoke)
{

View File

@@ -4,8 +4,8 @@
#include "coding/varint.hpp"
#include "base/logging.hpp"
#include "base/string_utils.hpp"
#include "base/scope_guard.hpp"
#include "base/string_utils.hpp"
#include "std/target_os.hpp"
@@ -56,7 +56,7 @@ UNIT_TEST(FilesContainer_Smoke)
}
// append to container
uint32_t const arrAppend[] = { 888, 777, 666 };
uint32_t const arrAppend[] = {888, 777, 666};
for (size_t i = 0; i < ARRAY_SIZE(arrAppend); ++i)
{
{
@@ -82,12 +82,12 @@ UNIT_TEST(FilesContainer_Smoke)
namespace
{
void CheckInvariant(FilesContainerR & reader, string const & tag, int64_t test)
{
FilesContainerR::TReader r = reader.GetReader(tag);
TEST_EQUAL(test, ReadPrimitiveFromPos<int64_t>(r, 0), ());
}
void CheckInvariant(FilesContainerR & reader, string const & tag, int64_t test)
{
FilesContainerR::TReader r = reader.GetReader(tag);
TEST_EQUAL(test, ReadPrimitiveFromPos<int64_t>(r, 0), ());
}
} // namespace
UNIT_TEST(FilesContainer_Shared)
{
@@ -147,43 +147,41 @@ UNIT_TEST(FilesContainer_Shared)
namespace
{
void ReplaceInContainer(string const & fName,
char const * key, char const * value)
void ReplaceInContainer(string const & fName, char const * key, char const * value)
{
FilesContainerW writer(fName, FileWriter::OP_WRITE_EXISTING);
auto w = writer.GetWriter(key);
w->Write(value, strlen(value));
}
void CheckContainer(string const & fName, char const * key[], char const * value[], size_t count)
{
FilesContainerR reader(fName);
LOG(LINFO, ("Size=", reader.GetFileSize()));
for (size_t i = 0; i < count; ++i)
{
FilesContainerW writer(fName, FileWriter::OP_WRITE_EXISTING);
auto w = writer.GetWriter(key);
w->Write(value, strlen(value));
}
FilesContainerR::TReader r = reader.GetReader(key[i]);
void CheckContainer(string const & fName,
char const * key[], char const * value[], size_t count)
{
FilesContainerR reader(fName);
LOG(LINFO, ("Size=", reader.GetFileSize()));
size_t const szBuffer = 100;
size_t const szS = strlen(value[i]);
for (size_t i = 0; i < count; ++i)
{
FilesContainerR::TReader r = reader.GetReader(key[i]);
char s[szBuffer] = {0};
ASSERT_LESS(szS, szBuffer, ());
r.Read(0, s, szS);
size_t const szBuffer = 100;
size_t const szS = strlen(value[i]);
char s[szBuffer] = { 0 };
ASSERT_LESS ( szS, szBuffer, () );
r.Read(0, s, szS);
TEST(strcmp(value[i], s) == 0, (s));
}
TEST(strcmp(value[i], s) == 0, (s));
}
}
} // namespace
UNIT_TEST(FilesContainer_RewriteExisting)
{
string const fName = "files_container.tmp";
FileWriter::DeleteFileX(fName);
char const * key[] = { "3", "2", "1" };
char const * value[] = { "prolog", "data", "epilog" };
char const * key[] = {"3", "2", "1"};
char const * value[] = {"prolog", "data", "epilog"};
// fill container
{
@@ -199,19 +197,19 @@ UNIT_TEST(FilesContainer_RewriteExisting)
// re-write middle file in container
char const * buffer1 = "xxxxxxx";
ReplaceInContainer(fName, key[1], buffer1);
char const * value1[] = { value[0], buffer1, value[2] };
char const * value1[] = {value[0], buffer1, value[2]};
CheckContainer(fName, key, value1, 3);
// re-write end file in container
char const * buffer2 = "yyyyyyyyyyyyyy";
ReplaceInContainer(fName, key[2], buffer2);
char const * value2[] = { value[0], buffer1, buffer2 };
char const * value2[] = {value[0], buffer1, buffer2};
CheckContainer(fName, key, value2, 3);
// re-write end file in container once again
char const * buffer3 = "zzz";
ReplaceInContainer(fName, key[2], buffer3);
char const * value3[] = { value[0], buffer1, buffer3 };
char const * value3[] = {value[0], buffer1, buffer3};
CheckContainer(fName, key, value3, 3);
FileWriter::DeleteFileX(fName);
@@ -334,7 +332,7 @@ UNIT_TEST(FilesMappingContainer_MoveHandle)
UNIT_TEST(FilesMappingContainer_Smoke)
{
string const fName = "files_container.tmp";
char const * key[] = { "3", "2", "1" };
char const * key[] = {"3", "2", "1"};
uint32_t const count = 1000000;
// fill container
@@ -385,9 +383,9 @@ UNIT_TEST(FilesMappingContainer_PageSize)
#endif
LOG(LINFO, ("Page size:", pageSize));
char const * key[] = { "3", "2", "1" };
char const byte[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
size_t count[] = { pageSize-1, pageSize, pageSize+1 };
char const * key[] = {"3", "2", "1"};
char const byte[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g'};
size_t count[] = {pageSize - 1, pageSize, pageSize + 1};
size_t const sz = ARRAY_SIZE(key);
{

View File

@@ -12,7 +12,8 @@ using namespace std;
namespace
{
template <size_t Bits> void TestWithData(vector<uint32_t> const & lst)
template <size_t Bits>
void TestWithData(vector<uint32_t> const & lst)
{
using TVector = FixedBitsDDVector<Bits, MemReader>;
using TBuffer = vector<uint8_t>;
@@ -50,7 +51,7 @@ template <size_t Bits> void TestWithData(vector<uint32_t> const & lst)
++i;
}
}
} // namespace
} // namespace
UNIT_TEST(FixedBitsDDVector_Smoke)
{

View File

@@ -26,12 +26,17 @@ using PD = m2::PointD;
namespace
{
m2::PointU D2U(m2::PointD const & p) { return PointDToPointU(p, kPointCoordBits); }
m2::PointU D2U(m2::PointD const & p)
{
return PointDToPointU(p, kPointCoordBits);
}
m2::PointU GetMaxPoint() { return D2U(m2::PointD(mercator::Bounds::kMaxX, mercator::Bounds::kMaxY)); }
m2::PointU GetMaxPoint()
{
return D2U(m2::PointD(mercator::Bounds::kMaxX, mercator::Bounds::kMaxY));
}
void TestPolylineEncode(string testName, vector<m2::PointU> const & points,
m2::PointU const & maxPoint,
void TestPolylineEncode(string testName, vector<m2::PointU> const & points, m2::PointU const & maxPoint,
void (*fnEncode)(InPointsT const & points, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutDeltasT & deltas),
void (*fnDecode)(InDeltasT const & deltas, m2::PointU const & basePoint,
@@ -161,9 +166,8 @@ UNIT_TEST(EncodePolyline)
vector<m2::PointU> points;
points.reserve(polygonSize);
for (size_t i = 0; i < polygonSize; ++i)
points.push_back(
m2::PointU(static_cast<uint32_t>(LargePolygon::kLargePolygon[i].x * 10000),
static_cast<uint32_t>((LargePolygon::kLargePolygon[i].y + 200) * 10000)));
points.push_back(m2::PointU(static_cast<uint32_t>(LargePolygon::kLargePolygon[i].x * 10000),
static_cast<uint32_t>((LargePolygon::kLargePolygon[i].y + 200) * 10000)));
TestEncodePolyline("Unsimp", maxPoint, points);
TestEncodePolyline("1simp", maxPoint, SimplifyPoints(points, 1));

View File

@@ -29,8 +29,8 @@ bool IsEqual(m2::PointD const & p1, m2::PointD const & p2)
bool IsEqual(m2::RectD const & r1, m2::RectD const & r2)
{
return (IsEqual(r1.minX(), r2.minX()) && IsEqual(r1.minY(), r2.minY()) &&
IsEqual(r1.maxX(), r2.maxX()) && IsEqual(r1.maxY(), r2.maxY()));
return (IsEqual(r1.minX(), r2.minX()) && IsEqual(r1.minY(), r2.minY()) && IsEqual(r1.maxX(), r2.maxX()) &&
IsEqual(r1.maxY(), r2.maxY()));
}
} // namespace

View File

@@ -32,8 +32,7 @@ UNIT_TEST(RandomRecode)
UNIT_TEST(EncodeNumber)
{
TEST_EQUAL(NumToHex(uint64_t(0x0123456789ABCDEFULL)),
"0123456789ABCDEF", ());
TEST_EQUAL(NumToHex(uint64_t(0x0123456789ABCDEFULL)), "0123456789ABCDEF", ());
}
UNIT_TEST(DecodeLowerCaseHex)

View File

@@ -85,8 +85,7 @@ UNIT_TEST(Huffman_Init)
UNIT_TEST(Huffman_Serialization_Encoding)
{
HuffmanCoder hW;
hW.Init(MakeUniStringVector(
vector<string>{"aaaaaaaaaa", "bbbbbbbbbb", "ccccc", "ddddd"})); // 10, 10, 5, 5
hW.Init(MakeUniStringVector(vector<string>{"aaaaaaaaaa", "bbbbbbbbbb", "ccccc", "ddddd"})); // 10, 10, 5, 5
vector<uint8_t> buf;
MemWriter<vector<uint8_t>> writer(buf);
hW.WriteEncoding(writer);
@@ -112,8 +111,7 @@ UNIT_TEST(Huffman_Serialization_Encoding)
UNIT_TEST(Huffman_Serialization_Data)
{
HuffmanCoder hW;
hW.Init(MakeUniStringVector(
vector<string>{"aaaaaaaaaa", "bbbbbbbbbb", "ccccc", "ddddd"})); // 10, 10, 5, 5
hW.Init(MakeUniStringVector(vector<string>{"aaaaaaaaaa", "bbbbbbbbbb", "ccccc", "ddddd"})); // 10, 10, 5, 5
vector<uint8_t> buf;
string const data = "abacabaddddaaabbcabacabadbabd";

View File

@@ -86,8 +86,8 @@ UNIT_TEST(MapUint32Val_Smoke)
{
MemReader reader(buffer.data(), buffer.size());
auto table = MapUint32ToValue<uint32_t>::Load(reader, [](NonOwningReaderSource & source, uint32_t blockSize,
ValuesT & values)
auto table = MapUint32ToValue<uint32_t>::Load(
reader, [](NonOwningReaderSource & source, uint32_t blockSize, ValuesT & values)
{
values.reserve(blockSize);
while (source.Size() > 0)
@@ -105,4 +105,4 @@ UNIT_TEST(MapUint32Val_Smoke)
}
}
}
} // namespace map_uint32_tests
} // namespace map_uint32_tests

View File

@@ -1,7 +1,7 @@
#include "testing/testing.hpp"
#include "coding/reader.hpp"
#include "base/macros.hpp"
#include "coding/reader.hpp"
UNIT_TEST(MemReaderSimple)
{

View File

@@ -1,7 +1,7 @@
#include "testing/testing.hpp"
#include "coding/writer.hpp"
#include "coding/file_writer.hpp"
#include "coding/writer.hpp"
#include "base/macros.hpp"
@@ -25,6 +25,6 @@ UNIT_TEST(MemWriterSimple)
writer.Write("world!", 6);
char const expected[] = "Hello,world!";
TEST_EQUAL(data.size(), ARRAY_SIZE(expected)-1, ());
TEST_EQUAL(data.size(), ARRAY_SIZE(expected) - 1, ());
TEST(equal(data.begin(), data.end(), &expected[0]), (data));
}

View File

@@ -6,7 +6,8 @@
using namespace std;
void loadFile(vector<unsigned char> & buffer, string const & filename) //designed for loading files from hard disk in an std::vector
void loadFile(vector<unsigned char> & buffer,
string const & filename) // designed for loading files from hard disk in an std::vector
{
ifstream file(filename.c_str(), ios::in | ios::binary | ios::ate);
@@ -21,7 +22,7 @@ void loadFile(vector<unsigned char> & buffer, string const & filename) //designe
if (size > 0)
{
buffer.resize((size_t)size);
file.read((char*)(&buffer[0]), size);
file.read((char *)(&buffer[0]), size);
}
else
buffer.clear();
@@ -29,16 +30,16 @@ void loadFile(vector<unsigned char> & buffer, string const & filename) //designe
UNIT_TEST(PngDecode)
{
// // load and decode
// vector<unsigned char> buffer, image;
// loadFile(buffer, "../../data/font_0.png");
// unsigned long w, h;
// int error = DecodePNG(image, w, h, buffer.empty() ? 0 : &buffer[0], (unsigned long)buffer.size());
//
// // if there's an error, display it
// TEST_EQUAL(error, 0, ());
// // the pixels are now in the vector "image", use it as texture, draw it, ...
// TEST_GREATER(image.size(), 4, ("Image is empty???"));
// TEST_EQUAL(w, 1024, ());
// TEST_EQUAL(h, 1024, ());
// // load and decode
// vector<unsigned char> buffer, image;
// loadFile(buffer, "../../data/font_0.png");
// unsigned long w, h;
// int error = DecodePNG(image, w, h, buffer.empty() ? 0 : &buffer[0], (unsigned long)buffer.size());
//
// // if there's an error, display it
// TEST_EQUAL(error, 0, ());
// // the pixels are now in the vector "image", use it as texture, draw it, ...
// TEST_GREATER(image.size(), 4, ("Image is empty???"));
// TEST_EQUAL(w, 1024, ());
// TEST_EQUAL(h, 1024, ());
}

View File

@@ -51,9 +51,7 @@ UNIT_TEST(PointDToPointU_Epsilons)
for (; i < count; ++i)
{
m2::PointU p0 = PointDToPointU(arrPt[i].x, arrPt[i].y, kCoordBits);
m2::PointU p1 = PointDToPointU(arrPt[i].x + arrD[i].x * eps,
arrPt[i].y + arrD[i].y * eps,
kCoordBits);
m2::PointU p1 = PointDToPointU(arrPt[i].x + arrD[i].x * eps, arrPt[i].y + arrD[i].y * eps, kCoordBits);
if (p0 != p1)
break;
@@ -114,8 +112,7 @@ UNIT_TEST(PointToInt64Obsolete_Smoke)
m2::PointD const arr[] = {{1.25, 1.3}, {180, 90}, {-180, -90}, {0, 0}};
for (size_t i = 0; i < ARRAY_SIZE(arr); ++i)
CheckEqualPoints(arr[i],
Int64ToPointObsolete(PointToInt64Obsolete(arr[i], kCoordBits), kCoordBits));
CheckEqualPoints(arr[i], Int64ToPointObsolete(PointToInt64Obsolete(arr[i], kCoordBits), kCoordBits));
}
UNIT_TEST(PointToInt64Obsolete_Grid)
@@ -151,11 +148,9 @@ UNIT_TEST(PointToInt64Obsolete_Bounds)
for (size_t iY = 0; iY < ARRAY_SIZE(arrEps); ++iY)
{
m2::PointD const pt(arrPt[iP].x + arrEps[iX], arrPt[iP].y + arrEps[iY]);
m2::PointD const pt1 =
Int64ToPointObsolete(PointToInt64Obsolete(pt, kCoordBits), kCoordBits);
m2::PointD const pt1 = Int64ToPointObsolete(PointToInt64Obsolete(pt, kCoordBits), kCoordBits);
TEST(fabs(pt.x - pt1.x) <= (fabs(arrEps[iX]) + kEps) &&
fabs(pt.y - pt1.y) <= (fabs(arrEps[iY]) + kEps),
TEST(fabs(pt.x - pt1.x) <= (fabs(arrEps[iX]) + kEps) && fabs(pt.y - pt1.y) <= (fabs(arrEps[iY]) + kEps),
(pt, pt1));
}
}

View File

@@ -1,7 +1,7 @@
#include "testing/testing.hpp"
#include "coding/reader_cache.hpp"
#include "coding/reader.hpp"
#include "coding/reader_cache.hpp"
#include <algorithm>
#include <random>
@@ -12,21 +12,22 @@ using namespace std;
namespace
{
template <class ReaderT> class CacheReader
{
public:
CacheReader(ReaderT const & reader, uint32_t logPageSize, uint32_t logPageCount)
: m_Reader(reader), m_Cache(logPageSize, logPageCount) {}
template <class ReaderT>
class CacheReader
{
public:
CacheReader(ReaderT const & reader, uint32_t logPageSize, uint32_t logPageCount)
: m_Reader(reader)
, m_Cache(logPageSize, logPageCount)
{}
void Read(uint64_t pos, void * p, size_t size) const
{
m_Cache.Read(m_Reader, pos, p, size);
}
private:
ReaderT m_Reader;
ReaderCache<ReaderT const> mutable m_Cache;
};
}
void Read(uint64_t pos, void * p, size_t size) const { m_Cache.Read(m_Reader, pos, p, size); }
private:
ReaderT m_Reader;
ReaderCache<ReaderT const> mutable m_Cache;
};
} // namespace
UNIT_TEST(CacheReaderRandomTest)
{

View File

@@ -2,9 +2,9 @@
#include "coding/coding_tests/reader_test.hpp"
#include "coding/buffer_reader.hpp"
#include "coding/file_reader.hpp"
#include "coding/file_writer.hpp"
#include "coding/buffer_reader.hpp"
#include "coding/reader_streambuf.hpp"
#include <cstring>
@@ -16,7 +16,7 @@ using namespace std;
namespace
{
string const kData("Quick brown fox jumps over a lazy dog...");
string const kData("Quick brown fox jumps over a lazy dog...");
}
UNIT_TEST(MemReaderSmokeTest)
@@ -70,8 +70,7 @@ UNIT_TEST(FileReaderNonExistentFileTest)
TEST(false, ("Exception should be thrown!"));
}
catch (FileReader::OpenException &)
{
}
{}
}
UNIT_TEST(FileReaderReadAsText)

View File

@@ -8,21 +8,21 @@
namespace
{
template <class ReaderT>
void ReadToStringFromPos(ReaderT const & reader, std::string & str, uint64_t pos, size_t size)
{
str.resize(size);
reader.Read(pos, &str[0], str.size());
}
template <class SourceT>
void ReadToStringFromSource(SourceT & source, std::string & str, size_t size)
{
str.resize(size);
source.Read(&str[0], str.size());
}
template <class ReaderT>
void ReadToStringFromPos(ReaderT const & reader, std::string & str, uint64_t pos, size_t size)
{
str.resize(size);
reader.Read(pos, &str[0], str.size());
}
template <class SourceT>
void ReadToStringFromSource(SourceT & source, std::string & str, size_t size)
{
str.resize(size);
source.Read(&str[0], str.size());
}
} // namespace
template <typename ReaderT>
void TestReader(ReaderT const & reader)
{
@@ -49,4 +49,3 @@ void TestReader(ReaderT const & reader)
ReadToStringFromSource(subReaderSource, d1, 6);
TEST_EQUAL(d1, "fox ju", ());
}

View File

@@ -1,10 +1,10 @@
#include "testing/testing.hpp"
#include "coding/reader_writer_ops.hpp"
#include "coding/byte_stream.hpp"
#include "coding/file_reader.hpp"
#include "coding/file_writer.hpp"
#include "coding/read_write_utils.hpp"
#include "coding/byte_stream.hpp"
#include "coding/reader_writer_ops.hpp"
#include "base/random.hpp"
@@ -17,43 +17,43 @@ using namespace std;
namespace
{
void GetReverseForReaderAndTmpFile(Reader const & src, vector<char> & buffer)
void GetReverseForReaderAndTmpFile(Reader const & src, vector<char> & buffer)
{
char const * tmpFile = "reversed_file.tmp";
{
char const * tmpFile = "reversed_file.tmp";
{
FileWriter writer(tmpFile);
rw_ops::Reverse(src, writer);
}
{
FileReader reader(tmpFile);
buffer.clear();
MemWriter<vector<char> > writer(buffer);
rw_ops::Reverse(reader, writer);
}
FileWriter::DeleteFileX(tmpFile);
FileWriter writer(tmpFile);
rw_ops::Reverse(src, writer);
}
void FillRandFile(string const & fName, size_t count)
{
FileWriter writer(fName);
FileReader reader(tmpFile);
buffer.clear();
MemWriter<vector<char>> writer(buffer);
rw_ops::Reverse(reader, writer);
}
base::UniformRandom<int8_t> rand;
FileWriter::DeleteFileX(tmpFile);
}
while (count-- > 0)
{
int8_t const c = rand();
writer.Write(&c, 1);
}
void FillRandFile(string const & fName, size_t count)
{
FileWriter writer(fName);
base::UniformRandom<int8_t> rand;
while (count-- > 0)
{
int8_t const c = rand();
writer.Write(&c, 1);
}
}
} // namespace
UNIT_TEST(Reverse_Smoke)
{
{
char arr[] = { 0xA, 0xB, 0xC, 0xD, 0xF };
char arr[] = {0xA, 0xB, 0xC, 0xD, 0xF};
size_t const sz = ARRAY_SIZE(arr);
MemReader reader(&arr[0], sz);
@@ -86,17 +86,17 @@ UNIT_TEST(Reverse_Smoke)
namespace
{
struct ThePOD
{
uint32_t m_i;
double m_d;
};
struct ThePOD
{
uint32_t m_i;
double m_d;
};
bool operator==(ThePOD const & r1, ThePOD const & r2)
{
return (r1.m_i == r2.m_i && r1.m_d == r2.m_d);
}
bool operator==(ThePOD const & r1, ThePOD const & r2)
{
return (r1.m_i == r2.m_i && r1.m_d == r2.m_d);
}
} // namespace
UNIT_TEST(ReadWrite_POD)
{
@@ -111,7 +111,7 @@ UNIT_TEST(ReadWrite_POD)
}
vector<char> buffer;
PushBackByteSink<vector<char> > sink(buffer);
PushBackByteSink<vector<char>> sink(buffer);
rw::WriteVectorOfPOD(sink, src);
buffer_vector<ThePOD, 128> dest;
@@ -123,12 +123,11 @@ UNIT_TEST(ReadWrite_POD)
namespace
{
template <class T> void TestIntegral()
template <class T>
void TestIntegral()
{
std::vector<T> ethalon{ static_cast<T>(-1), 0, 1,
static_cast<T>(-2), 2,
std::numeric_limits<T>::min(), std::numeric_limits<T>::max()
};
std::vector<T> ethalon{static_cast<T>(-1), 0, 1, static_cast<T>(-2), 2, std::numeric_limits<T>::min(),
std::numeric_limits<T>::max()};
std::string buffer;
MemWriter writer(buffer);
@@ -141,7 +140,7 @@ template <class T> void TestIntegral()
TEST_EQUAL(ethalon, expected, ());
}
}
} // namespace
UNIT_TEST(ReadWrite_Integral)
{
@@ -151,4 +150,4 @@ UNIT_TEST(ReadWrite_Integral)
TestIntegral<int64_t>();
}
} // namespace rw_ops_tests
} // namespace rw_ops_tests

View File

@@ -44,8 +44,7 @@ bool TestSerDes(T const & value)
}
catch (base::Json::Exception const & exception)
{
LOG(LWARNING, ("Exception while parsing json string, reason:", exception.what(),
"json:", jsonStr));
LOG(LWARNING, ("Exception while parsing json string, reason:", exception.what(), "json:", jsonStr));
return false;
}
return deserializedValue == value;
@@ -61,16 +60,11 @@ enum class TestEnum
struct ValueTypes
{
DECLARE_VISITOR(visitor(m_boolValue, "boolValue"),
visitor(m_uint8Value, "uint8Value"),
visitor(m_uint32Value, "uint32Value"),
visitor(m_uint64Value, "uint64Value"),
visitor(m_int8Value, "int8Value"),
visitor(m_int32Value, "int32Value"),
visitor(m_int64Value, "int64Value"),
visitor(m_doubleValue, "doubleValue"),
visitor(m_stringValue, "stringValue"),
visitor(m_enumValue, "enumValue"),
DECLARE_VISITOR(visitor(m_boolValue, "boolValue"), visitor(m_uint8Value, "uint8Value"),
visitor(m_uint32Value, "uint32Value"), visitor(m_uint64Value, "uint64Value"),
visitor(m_int8Value, "int8Value"), visitor(m_int32Value, "int32Value"),
visitor(m_int64Value, "int64Value"), visitor(m_doubleValue, "doubleValue"),
visitor(m_stringValue, "stringValue"), visitor(m_enumValue, "enumValue"),
visitor(m_timePointValue, "timePointValue"))
ValueTypes() = default;
@@ -90,12 +84,11 @@ struct ValueTypes
bool operator==(ValueTypes const & rhs) const
{
return m_boolValue == rhs.m_boolValue && m_uint8Value == rhs.m_uint8Value &&
m_uint32Value == rhs.m_uint32Value && m_uint64Value == rhs.m_uint64Value &&
m_int8Value == rhs.m_int8Value && m_int32Value == rhs.m_int32Value &&
m_int64Value == rhs.m_int64Value && m_doubleValue == rhs.m_doubleValue &&
m_stringValue == rhs.m_stringValue && m_enumValue == rhs.m_enumValue &&
m_timePointValue == rhs.m_timePointValue;
return m_boolValue == rhs.m_boolValue && m_uint8Value == rhs.m_uint8Value && m_uint32Value == rhs.m_uint32Value &&
m_uint64Value == rhs.m_uint64Value && m_int8Value == rhs.m_int8Value && m_int32Value == rhs.m_int32Value &&
m_int64Value == rhs.m_int64Value && m_doubleValue == rhs.m_doubleValue &&
m_stringValue == rhs.m_stringValue && m_enumValue == rhs.m_enumValue &&
m_timePointValue == rhs.m_timePointValue;
}
bool m_boolValue;
@@ -113,8 +106,7 @@ struct ValueTypes
struct ObjectTypes
{
DECLARE_VISITOR(visitor(m_pointValue, "pointValue"),
visitor(m_latLonValue, "latLonValue"),
DECLARE_VISITOR(visitor(m_pointValue, "pointValue"), visitor(m_latLonValue, "latLonValue"),
visitor(m_pairValue, "pairValue"))
ObjectTypes() = default;
@@ -126,8 +118,7 @@ struct ObjectTypes
bool operator==(ObjectTypes const & rhs) const
{
return m_pointValue == rhs.m_pointValue && m_latLonValue == rhs.m_latLonValue &&
m_pairValue == rhs.m_pairValue;
return m_pointValue == rhs.m_pointValue && m_latLonValue == rhs.m_latLonValue && m_pairValue == rhs.m_pairValue;
}
m2::PointD m_pointValue;
@@ -137,8 +128,7 @@ struct ObjectTypes
struct PointerTypes
{
DECLARE_VISITOR(visitor(m_uniquePtrValue, "uniquePtrValue"),
visitor(m_sharedPtrValue, "sharedPtrValue"))
DECLARE_VISITOR(visitor(m_uniquePtrValue, "uniquePtrValue"), visitor(m_sharedPtrValue, "sharedPtrValue"))
PointerTypes() = default;
PointerTypes(uint32_t testCounter)
@@ -149,8 +139,7 @@ struct PointerTypes
bool operator==(PointerTypes const & rhs) const
{
return SamePtrValue(m_uniquePtrValue, rhs.m_uniquePtrValue) &&
SamePtrValue(m_sharedPtrValue, rhs.m_sharedPtrValue);
return SamePtrValue(m_uniquePtrValue, rhs.m_uniquePtrValue) && SamePtrValue(m_sharedPtrValue, rhs.m_sharedPtrValue);
}
unique_ptr<ValueTypes> m_uniquePtrValue;
@@ -159,10 +148,8 @@ struct PointerTypes
struct ArrayTypes
{
DECLARE_VISITOR(visitor(m_arrayValue, "arrayValue"),
visitor(m_dequeValue, "dequeValue"),
visitor(m_vectorValue, "vectorValue"),
visitor(m_mapValue, "mapValue"),
DECLARE_VISITOR(visitor(m_arrayValue, "arrayValue"), visitor(m_dequeValue, "dequeValue"),
visitor(m_vectorValue, "vectorValue"), visitor(m_mapValue, "mapValue"),
visitor(m_unorderedSetValue, "unorderedSetValue"))
ArrayTypes() = default;
@@ -176,9 +163,8 @@ struct ArrayTypes
bool operator==(ArrayTypes const & rhs) const
{
return m_arrayValue == rhs.m_arrayValue && m_dequeValue == rhs.m_dequeValue &&
m_vectorValue == rhs.m_vectorValue && m_mapValue == rhs.m_mapValue &&
m_unorderedSetValue == rhs.m_unorderedSetValue;
return m_arrayValue == rhs.m_arrayValue && m_dequeValue == rhs.m_dequeValue && m_vectorValue == rhs.m_vectorValue &&
m_mapValue == rhs.m_mapValue && m_unorderedSetValue == rhs.m_unorderedSetValue;
}
array<uint32_t, 3> m_arrayValue;
@@ -233,16 +219,12 @@ UNIT_TEST(SerdesJsonTest)
{
struct Hasher
{
size_t operator()(pair<string, string> const & item) const
{
return m_hasher(item.first + item.second);
}
size_t operator()(pair<string, string> const & item) const { return m_hasher(item.first + item.second); }
hash<string> m_hasher;
};
unordered_set<pair<string, string>, Hasher> testValue = {{"ab", "ab"}, {"ef", "ef"},
{"cd", "cd"}};
unordered_set<pair<string, string>, Hasher> testValue = {{"ab", "ab"}, {"ef", "ef"}, {"cd", "cd"}};
TEST(TestSerDes(testValue), ());
}

View File

@@ -2,37 +2,43 @@
#include "coding/sha1.hpp"
namespace sha1_test
{
using namespace coding;
UNIT_TEST(SHA1_Smoke)
{
char const * bytes[] =
{
"H",
"He",
"Hel",
"Hell",
"Hello",
"Hello,",
"Hello, ",
"Hello, World!",
"Organic Maps is the ultimate companion app for travellers, tourists, hikers, and cyclists!",
char const * bytes[] = {
"H",
"He",
"Hel",
"Hell",
"Hello",
"Hello,",
"Hello, ",
"Hello, World!",
"Organic Maps is the ultimate companion app for travellers, tourists, hikers, and cyclists!",
};
SHA1::Hash encoded[] =
{
{0x7C, 0xF1, 0x84, 0xF4, 0xC6, 0x7A, 0xD5, 0x82, 0x83, 0xEC, 0xB1, 0x93, 0x49, 0x72, 0x0B, 0x0C, 0xAE, 0x75, 0x68, 0x29},
{0x53, 0xA4, 0x17, 0x79, 0x6C, 0x77, 0x78, 0x51, 0x00, 0x3B, 0x3F, 0x24, 0x31, 0xE8, 0xEE, 0xF5, 0x62, 0x5E, 0xC1, 0x5B},
{0xDB, 0xC2, 0xD1, 0xFE, 0xD0, 0xDC, 0x37, 0xA7, 0x0A, 0xEA, 0x0F, 0x37, 0x69, 0x58, 0xC8, 0x02, 0xED, 0xDC, 0x05, 0x59},
{0xED, 0x10, 0xFE, 0x11, 0x3D, 0xE1, 0xC0, 0xBD, 0xAA, 0xAA, 0xF0, 0x9B, 0x88, 0xCD, 0x34, 0x1E, 0xA0, 0xF4, 0x44, 0x28},
{0xF7, 0xFF, 0x9E, 0x8B, 0x7B, 0xB2, 0xE0, 0x9B, 0x70, 0x93, 0x5A, 0x5D, 0x78, 0x5E, 0x0C, 0xC5, 0xD9, 0xD0, 0xAB, 0xF0},
{0x65, 0x61, 0x1E, 0x95, 0x20, 0xE7, 0x68, 0x14, 0x5D, 0xAD, 0xAA, 0x1D, 0x10, 0x7F, 0xDD, 0x52, 0x07, 0xE6, 0x30, 0x57},
{0xF5, 0x2A, 0xB5, 0x7F, 0xA5, 0x1D, 0xFA, 0x71, 0x45, 0x05, 0x29, 0x44, 0x44, 0x46, 0x3A, 0xE5, 0xA0, 0x09, 0xAE, 0x34},
{0x0A, 0x0A, 0x9F, 0x2A, 0x67, 0x72, 0x94, 0x25, 0x57, 0xAB, 0x53, 0x55, 0xD7, 0x6A, 0xF4, 0x42, 0xF8, 0xF6, 0x5E, 0x01},
{0x48, 0xF5, 0x4D, 0x3D, 0x08, 0xD5, 0xC0, 0x57, 0x6B, 0x3A, 0xC5, 0x3E, 0xEF, 0x22, 0x4A, 0xB8, 0x46, 0x7B, 0xA2, 0xFC},
SHA1::Hash encoded[] = {
{0x7C, 0xF1, 0x84, 0xF4, 0xC6, 0x7A, 0xD5, 0x82, 0x83, 0xEC,
0xB1, 0x93, 0x49, 0x72, 0x0B, 0x0C, 0xAE, 0x75, 0x68, 0x29},
{0x53, 0xA4, 0x17, 0x79, 0x6C, 0x77, 0x78, 0x51, 0x00, 0x3B,
0x3F, 0x24, 0x31, 0xE8, 0xEE, 0xF5, 0x62, 0x5E, 0xC1, 0x5B},
{0xDB, 0xC2, 0xD1, 0xFE, 0xD0, 0xDC, 0x37, 0xA7, 0x0A, 0xEA,
0x0F, 0x37, 0x69, 0x58, 0xC8, 0x02, 0xED, 0xDC, 0x05, 0x59},
{0xED, 0x10, 0xFE, 0x11, 0x3D, 0xE1, 0xC0, 0xBD, 0xAA, 0xAA,
0xF0, 0x9B, 0x88, 0xCD, 0x34, 0x1E, 0xA0, 0xF4, 0x44, 0x28},
{0xF7, 0xFF, 0x9E, 0x8B, 0x7B, 0xB2, 0xE0, 0x9B, 0x70, 0x93,
0x5A, 0x5D, 0x78, 0x5E, 0x0C, 0xC5, 0xD9, 0xD0, 0xAB, 0xF0},
{0x65, 0x61, 0x1E, 0x95, 0x20, 0xE7, 0x68, 0x14, 0x5D, 0xAD,
0xAA, 0x1D, 0x10, 0x7F, 0xDD, 0x52, 0x07, 0xE6, 0x30, 0x57},
{0xF5, 0x2A, 0xB5, 0x7F, 0xA5, 0x1D, 0xFA, 0x71, 0x45, 0x05,
0x29, 0x44, 0x44, 0x46, 0x3A, 0xE5, 0xA0, 0x09, 0xAE, 0x34},
{0x0A, 0x0A, 0x9F, 0x2A, 0x67, 0x72, 0x94, 0x25, 0x57, 0xAB,
0x53, 0x55, 0xD7, 0x6A, 0xF4, 0x42, 0xF8, 0xF6, 0x5E, 0x01},
{0x48, 0xF5, 0x4D, 0x3D, 0x08, 0xD5, 0xC0, 0x57, 0x6B, 0x3A,
0xC5, 0x3E, 0xEF, 0x22, 0x4A, 0xB8, 0x46, 0x7B, 0xA2, 0xFC},
};
static_assert(std::size(bytes) == std::size(encoded));
@@ -40,4 +46,4 @@ UNIT_TEST(SHA1_Smoke)
for (size_t i = 0; i < std::size(bytes); ++i)
TEST_EQUAL(SHA1::CalculateForString(bytes[i]), encoded[i], ());
}
}
} // namespace sha1_test

View File

@@ -86,4 +86,4 @@ UNIT_TEST(SimpleDenseCoding_Ratio)
TEST_GREATER(ratio, 1.8, ());
}
}
} // namespace simple_dense_coding_test
} // namespace simple_dense_coding_test

View File

@@ -4,17 +4,15 @@
UNIT_TEST(SparseVector_Smoke)
{
uint32_t const arr[] = { 0, 0, 5, 0, 7, 1000, 0, 0, 1, 0 };
uint32_t const arr[] = {0, 0, 5, 0, 7, 1000, 0, 0, 1, 0};
uint64_t const count = std::size(arr);
coding::SparseVectorBuilder<uint32_t> builder(count);
for (uint32_t v : arr)
{
if (v == 0)
builder.PushEmpty();
else
builder.PushValue(v);
}
auto vec = builder.Build();

View File

@@ -123,14 +123,12 @@ UNIT_TEST(MultilangString_Unique)
UNIT_TEST(MultilangString_LangNames)
{
// It is important to compare the contents of the strings, and not just pointers
TEST_EQUAL(string("Беларуская"),
StringUtf8Multilang::GetLangNameByCode(StringUtf8Multilang::GetLangIndex("be")), ());
TEST_EQUAL(string("Беларуская"), StringUtf8Multilang::GetLangNameByCode(StringUtf8Multilang::GetLangIndex("be")), ());
auto const & langs = StringUtf8Multilang::GetSupportedLanguages();
// Using size_t workaround, because our logging/testing macroses do not support passing POD types
// by value, only by reference. And our constant is a constexpr.
TEST_LESS_OR_EQUAL(langs.size(), static_cast<size_t>(StringUtf8Multilang::kMaxSupportedLanguages),
());
TEST_LESS_OR_EQUAL(langs.size(), static_cast<size_t>(StringUtf8Multilang::kMaxSupportedLanguages), ());
auto const international = StringUtf8Multilang::GetLangIndex("int_name");
TEST_EQUAL(langs[international].m_code, string("int_name"), ());
}
@@ -201,8 +199,8 @@ UNIT_TEST(MultilangString_ForEachLanguage)
UNIT_TEST(MultilangString_RemoveString)
{
auto testRemove = [](vector<pair<uint8_t, string>> const & strings,
set<uint8_t> const & codesToRemove) {
auto testRemove = [](vector<pair<uint8_t, string>> const & strings, set<uint8_t> const & codesToRemove)
{
StringUtf8Multilang str;
for (auto const & s : strings)
str.AddString(s.first, s.second);
@@ -233,21 +231,15 @@ UNIT_TEST(MultilangString_RemoveString)
}
// No extra languages or other data damage.
str.ForEach([&](uint8_t lang, auto const &) {
TEST(base::FindIf(strings, [&lang](auto const & s) { return s.first == lang; }) !=
strings.end(),
());
str.ForEach([&](uint8_t lang, auto const &)
{
TEST(base::FindIf(strings, [&lang](auto const & s) { return s.first == lang; }) != strings.end(), ());
TEST(codesToRemove.find(lang) == codesToRemove.end(), ());
});
};
vector<pair<uint8_t, string>> strings = {{0, "aaa"},
{1, "bbb"},
{2, "ccc"},
{9, "ddd"},
{17, "eee"},
{27, "fff"},
{37, "ggg"}};
vector<pair<uint8_t, string>> strings = {{0, "aaa"}, {1, "bbb"}, {2, "ccc"}, {9, "ddd"},
{17, "eee"}, {27, "fff"}, {37, "ggg"}};
testRemove(strings, {0});
testRemove(strings, {1});

View File

@@ -12,7 +12,8 @@ namespace succinct_ef_test
{
using namespace std;
template <class T> vector<T> GetUniformValues(size_t count)
template <class T>
vector<T> GetUniformValues(size_t count)
{
// Use max - 1 because succinct makes val + 1 encoding internals.
uniform_int_distribution<T> randDist(0, numeric_limits<T>::max() - 1);
@@ -25,7 +26,8 @@ template <class T> vector<T> GetUniformValues(size_t count)
return data;
}
template <class T> vector<T> GetNormalValues(size_t count, T mean)
template <class T>
vector<T> GetNormalValues(size_t count, T mean)
{
normal_distribution<> randDist(mean, 2);
random_device randDevice;
@@ -46,7 +48,8 @@ template <class T> vector<T> GetNormalValues(size_t count, T mean)
return data;
}
template <class T> double GetCompressionRatio(vector<T> const & data)
template <class T>
double GetCompressionRatio(vector<T> const & data)
{
succinct::elias_fano_compressed_list efList(data);
@@ -84,4 +87,4 @@ UNIT_TEST(SuccinctEFList_Ratio)
}
}
} // namespace succinct_ef_test
} // namespace succinct_ef_test

View File

@@ -2,380 +2,192 @@
namespace geometry_coding_tests
{
P arr1[376] = {P(25.624035299999999182, 72.26346513007850092),
P(25.624273200000001083, 72.263461698303601111),
P(25.624488899999999347, 72.26341365347376211),
P(25.624979400000000851, 72.263304218156179104),
P(25.626030799999998777, 72.263025101705878228),
P(25.629390999999998257, 72.261676817778678128),
P(25.630162399999999678, 72.26138836631159279),
P(25.631299500000000791, 72.260963603282490908),
P(25.63236829999999955, 72.26051310574631259),
P(25.63325580000000059, 72.260190152533994024),
P(25.633720499999999021, 72.260019906865807116),
P(25.634314799999998513, 72.259865485075735592),
P(25.634578999999998672, 72.259830215951140531),
P(25.635424199999999217, 72.259772832171691448),
P(25.635776400000001018, 72.259834791404088605),
P(25.638406499999998545, 72.260604806439260983),
P(25.639231599999998679, 72.260931765228107793),
P(25.639867699999999928, 72.261237563690428942),
P(25.640699399999999031, 72.261850499331046649),
P(25.643624299999999039, 72.264447578158552687),
P(25.644772700000000754, 72.265904403664706024),
P(25.645413800000000037, 72.267106341816230497),
P(25.646751600000001758, 72.270404536824941033),
P(25.64890219999999843, 72.275985791150915816),
P(25.649064599999999103, 72.276404165523842948),
P(25.650549500000000336, 72.279974564589863917),
P(25.651433600000000723, 72.281545386607334081),
P(25.652029899999998719, 72.282193025251160634),
P(25.652814700000000414, 72.282915237415323872),
P(25.654197199999998702, 72.283799562153532747),
P(25.656540400000000801, 72.285055792411071707),
P(25.658162999999998277, 72.286263412818769325),
P(25.661959599999999426, 72.289916920742129491),
P(25.663380199999998865, 72.291039561736027963),
P(25.665810499999999195, 72.292780588759853799),
P(25.6700361000000008, 72.29585629709197292),
P(25.670962599999999298, 72.296655718166547899),
P(25.672222699999998952, 72.297961211704517837),
P(25.673103499999999855, 72.29896171301187735),
P(25.674837499999998869, 72.300952077677095531),
P(25.676358000000000459, 72.302732468128681376),
P(25.678018200000000348, 72.304444228347662715),
P(25.680309600000001069, 72.306619426588397914),
P(25.682252600000001763, 72.308208994982337003),
P(25.685880300000000886, 72.310749482551628375),
P(25.6871223999999998, 72.311619291531712861),
P(25.689502399999998516, 72.313337574126506979),
P(25.689994200000001001, 72.313685586072296019),
P(25.691337099999998372, 72.314639003020189989),
P(25.694014100000000411, 72.316465930359882464),
P(25.696650399999999337, 72.318133963117716689),
P(25.697924300000000386, 72.31863598381848135),
P(25.699229800000001234, 72.31891418618496914),
P(25.700213699999999051, 72.319045273707061483),
P(25.703616300000000194, 72.319271576784373678),
P(25.707311499999999427, 72.319273484907995453),
P(25.715181600000001083, 72.318046763400587906),
P(25.72608460000000008, 72.315978426880036523),
P(25.728649600000000675, 72.31539857900408208),
P(25.730824299999998317, 72.315156452495600092),
P(25.732753200000001215, 72.314945427265811873),
P(25.736661200000000349, 72.315042353781024076),
P(25.74480259999999987, 72.315568583243575063),
P(25.747831600000001373, 72.315649864883624787),
P(25.749809599999998966, 72.315866807206518274),
P(25.752535200000000515, 72.316023647210727177),
P(25.755610000000000781, 72.315910501039496694),
P(25.760463999999998919, 72.315272459413776573),
P(25.762314700000001011, 72.315021747344800929),
P(25.763456399999999036, 72.314812630534717641),
P(25.763716200000001066, 72.31478954377344337),
P(25.771413500000001306, 72.314102668549878672),
P(25.779617200000000565, 72.313375160856324442),
P(25.784148800000000534, 72.313357035273327256),
P(25.790238899999998523, 72.313577786126856495),
P(25.793676300000001334, 72.313716876708198811),
P(25.796280599999999339, 72.314048100429985766),
P(25.798680499999999682, 72.31463614103191162),
P(25.800190700000001698, 72.315239260045032665),
P(25.803071100000000371, 72.316310615756250968),
P(25.806439499999999754, 72.316835901112042961),
P(25.809219599999998707, 72.316657116642062419),
P(25.813906700000000427, 72.315918133153061831),
P(25.817769800000000657, 72.31543750249576874),
P(25.819804099999998925, 72.315482531661231747),
P(25.823219200000000484, 72.315995217547779816),
P(25.824360999999999677, 72.316092908788874638),
P(25.825752500000000111, 72.316000750836963107),
P(25.833053499999998337, 72.315183355397863352),
P(25.835087900000001326, 72.314863574077250519),
P(25.836477299999998536, 72.314986830897922232),
P(25.838510800000001666, 72.315843910886087542),
P(25.84021669999999915, 72.316586137240363996),
P(25.845591399999999993, 72.318366369042564656),
P(25.847287900000001315, 72.318912278071522337),
P(25.852937300000000675, 72.321233538069833457),
P(25.857534099999998745, 72.324114950429262194),
P(25.858493899999999144, 72.324638770105451613),
P(25.859516599999999187, 72.325101910243901671),
P(25.860960299999998568, 72.325309341574609334),
P(25.864481800000000078, 72.325170990340012622),
P(25.866295099999998541, 72.325066225249685203),
P(25.871619400000000155, 72.324758609934391984),
P(25.873917800000000966, 72.324524655307570242),
P(25.875719000000000136, 72.324229064532204347),
P(25.882352300000000866, 72.322516991669758113),
P(25.886094899999999797, 72.321551632301222412),
P(25.891463999999999146, 72.320154280548763381),
P(25.892594599999998906, 72.32000410941930113),
P(25.893775399999999109, 72.320041127430243932),
P(25.895055100000000436, 72.320205228136387632),
P(25.901716900000000265, 72.321479884460799781),
P(25.905201399999999268, 72.322148897878847151),
P(25.906758400000001075, 72.322300409542663147),
P(25.908453200000000294, 72.322276366107203671),
P(25.910453700000001476, 72.322039939449879853),
P(25.912611200000000622, 72.321379323121732341),
P(25.914446699999999169, 72.320507670602822259),
P(25.915890699999998503, 72.319578403757603269),
P(25.916971199999998987, 72.318721085380474278),
P(25.923277999999999821, 72.312682767056259081),
P(25.924315100000001166, 72.311643903530907096),
P(25.925479700000000349, 72.310661910829537646),
P(25.926380200000000542, 72.31012846985993292),
P(25.927288000000000778, 72.309673827336439444),
P(25.929170299999999116, 72.308742039167825055),
P(25.931695000000001272, 72.307558244187632113),
P(25.935542200000000435, 72.305689970006980616),
P(25.936291600000000557, 72.305420216334297834),
P(25.937011699999999337, 72.3052109385934898),
P(25.937444899999999137, 72.305171830245583919),
P(25.938065999999999178, 72.305126426436075349),
P(25.939194700000001603, 72.305346959512363014),
P(25.941637199999998842, 72.306187700803491225),
P(25.951531899999999098, 72.309363611414866568),
P(25.958591599999998323, 72.311600021678131611),
P(25.961859900000000323, 72.312588133461261464),
P(25.9623209000000017, 72.312845323461488078),
P(25.962808800000001241, 72.313126745396871797),
P(25.963783500000001681, 72.313929806056449934),
P(25.964454100000001091, 72.315054565005411291),
P(25.966293799999998981, 72.319575350745964215),
P(25.966609900000001687, 72.320173934482440359),
P(25.966938999999999993, 72.320628647970096381),
P(25.968776200000000642, 72.322731857094510133),
P(25.969766299999999859, 72.323772036806516894),
P(25.97039970000000153, 72.324406914991570261),
P(25.971057800000000526, 72.324904784282267656),
P(25.972805199999999815, 72.325716763759459127),
P(25.973508700000000005, 72.326106631888762877),
P(25.974174900000001287, 72.326699167072590058),
P(25.974623600000001034, 72.327462886785923502),
P(25.97499170000000035, 72.32822527930542833),
P(25.975826399999998984, 72.329784823533856297),
P(25.976481499999998448, 72.330935420885211329),
P(25.977230399999999833, 72.332212952428704966),
P(25.978115400000000079, 72.333512265445278899),
P(25.9789551000000003, 72.33474671239962106),
P(25.980276700000001, 72.336402410819303554),
P(25.98169719999999927, 72.337880836033434662),
P(25.983172299999999666, 72.33911288186702393),
P(25.984414600000000917, 72.340068567971513858),
P(25.985398499999998734, 72.340636603533639004),
P(25.986058100000001048, 72.340908025445514795),
P(25.987230000000000274, 72.341316496490946975),
P(25.988157300000001015, 72.341676869267246275),
P(25.991148400000000152, 72.342299318530393748),
P(25.997876999999999015, 72.343701138883602653),
P(25.999752600000000768, 72.344154484369809666),
P(26.001479700000000861, 72.344723890629211382),
P(26.003023999999999916, 72.345420432028205937),
P(26.005314899999998346, 72.346859159309715892),
P(26.007066099999999409, 72.348322733682408625),
P(26.008686999999998335, 72.35014618535842601),
P(26.012360000000001037, 72.354910262506038521),
P(26.013286199999999582, 72.355943685106993257),
P(26.013858500000001328, 72.35652369166834319),
P(26.014633599999999802, 72.357135968669368253),
P(26.015746700000001113, 72.357673410043958029),
P(26.017126499999999822, 72.358212001250265644),
P(26.020520199999999988, 72.359278695677289761),
P(26.021437599999998724, 72.359644892510004865),
P(26.022532699999999295, 72.360275718006846546),
P(26.028545999999998628, 72.365263533617877556),
P(26.029226600000001213, 72.365797602942478761),
P(26.030111600000001459, 72.366317546512846093),
P(26.032004199999999372, 72.367306080501194288),
P(26.033209299999999331, 72.367834246590078351),
P(26.034265699999998844, 72.368067397148493569),
P(26.035592099999998794, 72.368224167962054594),
P(26.03677019999999942, 72.368129074294643033),
P(26.043432299999999202, 72.366408627750374194),
P(26.045431499999999403, 72.365842856777021552),
P(26.048415399999999664, 72.36504242213915461),
P(26.052753299999999115, 72.363920454888528866),
P(26.05556269999999941, 72.363008918012667436),
P(26.060303699999998628, 72.360393712052541559),
P(26.065962500000001256, 72.35698705139280662),
P(26.067612400000001571, 72.356026924714299753),
P(26.069255399999999412, 72.355021374242639354),
P(26.070335599999999943, 72.354163985856629893),
P(26.071483900000000489, 72.353231772141796796),
P(26.073087300000000965, 72.351530224288538307),
P(26.07495580000000146, 72.349052146600300262),
P(26.077375199999998756, 72.345412414793742073),
P(26.079008800000000434, 72.34322240936705839),
P(26.080636800000000619, 72.341554327036718064),
P(26.081818800000000635, 72.340620379333103074),
P(26.083176200000000478, 72.339615440891947173),
P(26.085581000000001239, 72.338285853103528211),
P(26.092078799999999461, 72.335142167729841844),
P(26.099516500000000008, 72.332061609286498083),
P(26.102282500000001164, 72.330882175026999903),
P(26.105014700000001682, 72.329521843521945357),
P(26.108211900000000583, 72.327720133658942814),
P(26.116759299999998234, 72.322424061632020198),
P(26.118289900000000614, 72.321345929920937579),
P(26.124188000000000187, 72.316306990481081129),
P(26.126093300000000852, 72.314456217615472156),
P(26.13131840000000139, 72.308768748722727082),
P(26.133807300000000851, 72.305896196846916268),
P(26.135103199999999646, 72.304208818196542552),
P(26.13615610000000089, 72.3027141546473473),
P(26.136958199999998698, 72.301545345164157652),
P(26.137658200000000619, 72.300474224549915903),
P(26.140487000000000251, 72.29551524417688313),
P(26.146685800000000199, 72.285760107870132174),
P(26.151274499999999534, 72.277504651282583836),
P(26.151979099999998368, 72.276113553331668982),
P(26.152562700000000717, 72.274582520714972134),
P(26.152978600000000853, 72.272986691312326002),
P(26.154697899999998612, 72.264608683472175699),
P(26.155105599999998844, 72.263003939235275652),
P(26.155811400000001044, 72.261258344309723611),
P(26.156706599999999696, 72.259655777039213831),
P(26.158511799999999425, 72.257073180827120495),
P(26.163497199999998344, 72.251147710512896083),
P(26.164152500000000146, 72.250452144382251163),
P(26.165397099999999853, 72.249370018656591697),
P(26.171159400000000517, 72.245101348184562084),
P(26.171824600000000771, 72.244502288299599968),
P(26.172791700000001214, 72.243464858038208831),
P(26.173422299999998586, 72.24251111483852128),
P(26.174280599999999453, 72.240982180618559028),
P(26.174924399999998315, 72.239409446329290176),
P(26.175138900000000319, 72.238550480576279256),
P(26.177894599999998348, 72.222417606854094174),
P(26.178249600000000896, 72.220799387733251251),
P(26.178700899999999052, 72.219414415122045625),
P(26.179689899999999625, 72.217234222262234766),
P(26.182073200000001378, 72.213506738076645775),
P(26.18310470000000123, 72.211533626956168064),
P(26.183614800000000855, 72.210338776927230242),
P(26.18428000000000111, 72.208417574177602205),
P(26.185804499999999706, 72.203266316303412964),
P(26.186153000000000901, 72.202346286216979365),
P(26.186549599999999316, 72.201465316811109574),
P(26.187059699999998941, 72.200685882789031211),
P(26.187643699999998859, 72.200064170625580573),
P(26.188815999999999207, 72.199110470754774838),
P(26.189986799999999789, 72.198491439723213148),
P(26.190943999999998226, 72.198205925482497491),
P(26.192045499999998981, 72.198064597333782899),
P(26.201502200000000187, 72.19749033573828001),
P(26.204289599999999183, 72.197194731015855496),
P(26.212046699999998367, 72.196023752898682346),
P(26.217400099999998986, 72.195033541852339454),
P(26.220660899999998605, 72.194099530393685882),
P(26.223864100000000121, 72.193042117073559893),
P(26.227025699999998665, 72.192404096537160285),
P(26.229406099999998503, 72.192154413131575552),
P(26.23379059999999896, 72.191934250652863625),
P(26.241092200000000645, 72.191652763688111349),
P(26.247795599999999894, 72.191305763109099303),
P(26.259740499999999486, 72.190710990755292187),
P(26.262441899999998896, 72.190662426481935654),
P(26.26396259999999927, 72.190803739092231694),
P(26.265582200000000768, 72.19108065172507338),
P(26.271514700000000886, 72.192273445913514252),
P(26.275603900000000124, 72.192994312937273094),
P(26.278289999999998372, 72.193506828374651718),
P(26.280647800000000558, 72.193799369593079973),
P(26.284991699999999071, 72.194193426147350579),
P(26.295021899999998283, 72.194996021158502231),
P(26.296629599999999272, 72.195353135208762296),
P(26.298219400000000689, 72.195936520796209379),
P(26.299353599999999886, 72.196573622487093758),
P(26.300700500000001369, 72.19746290844136638),
P(26.301440499999998224, 72.198127833072547332),
P(26.302059899999999715, 72.198747051231549676),
P(26.302597999999999701, 72.199118470577644757),
P(26.30326700000000173, 72.200164931796578571),
P(26.304018299999999186, 72.201524555689601925),
P(26.305375600000001413, 72.20513574950004454),
P(26.306215500000000418, 72.206942181028665573),
P(26.307179600000001329, 72.208595118825385839),
P(26.307805599999998236, 72.209443034325843769),
P(26.308593200000000678, 72.210334966852684602),
P(26.309511400000001657, 72.211171854914510959),
P(26.310345000000001647, 72.211829485157878139),
P(26.313103999999999161, 72.213550746524816759),
P(26.313808999999999116, 72.214105903186023738),
P(26.315858999999999668, 72.21616368063173752),
P(26.316473599999998356, 72.216713905276705532),
P(26.317261800000000704, 72.217105619191144683),
P(26.318279199999999207, 72.217451609641841515),
P(26.31951039999999864, 72.217778930438797147),
P(26.319995200000001034, 72.217883719155963718),
P(26.322028199999998321, 72.21814340535271981),
P(26.323134799999998279, 72.218219615725388394),
P(26.324022500000001656, 72.218280774611798734),
P(26.32581220000000144, 72.218525220186265301),
P(26.327261700000001099, 72.218861882068196678),
P(26.330273800000000506, 72.219715642811124212),
P(26.337171999999998917, 72.221928497785057743),
P(26.339137900000000769, 72.222394361231621929),
P(26.341438799999998821, 72.222689314479467271),
P(26.343669200000000785, 72.222811640430336411),
P(26.346788899999999956, 72.222677310542948703),
P(26.356923500000000615, 72.222042438730937874),
P(26.359536099999999692, 72.2221015051835451),
P(26.36183730000000125, 72.222299854521224916),
P(26.366428899999998947, 72.222842507761527031),
P(26.374883000000000521, 72.223912965077033732),
P(26.380090800000001394, 72.224542709845593436),
P(26.39073850000000121, 72.225869670908153353),
P(26.393878699999998361, 72.226187124115313054),
P(26.400813700000000495, 72.226887965488728582),
P(26.405969100000000083, 72.227408932782296347),
P(26.434136200000001082, 72.23031015029567925),
P(26.437651200000001239, 72.230672215773722655),
P(26.439650799999999009, 72.230860300030158783),
P(26.442400500000001529, 72.230918230849241013),
P(26.444426599999999894, 72.230815518016711962),
P(26.454957100000001446, 72.229639190945519545),
P(26.455386699999998257, 72.229609273288744475),
P(26.470600499999999755, 72.227804710557407475),
P(26.485397899999998828, 72.226080035891357056),
P(26.487313600000000235, 72.226084418502168205),
P(26.488673999999999609, 72.226209799401686951),
P(26.489974300000000085, 72.226456941463752059),
P(26.493316499999998825, 72.227405883949458598),
P(26.497907399999999001, 72.228727947008763977),
P(26.507186099999998419, 72.231355762593423719),
P(26.521764000000001005, 72.235531322949142918),
P(26.522283200000000392, 72.235663963313356817),
P(26.52274799999999999, 72.235808991367022713),
P(26.523495799999999178, 72.236006428221017472),
P(26.537509100000001183, 72.239985971537208798),
P(26.540924100000001573, 72.240959309764491536),
P(26.544420699999999869, 72.241674408812258434),
P(26.546888100000000321, 72.242183101965366632),
P(26.5518616999999999, 72.242874580127462991),
P(26.562219100000000083, 72.244128903051048951),
P(26.564274399999998622, 72.244315309516480283),
P(26.576127799999998302, 72.245028538203385438),
P(26.58263820000000166, 72.244424904560787581),
P(26.591367999999999228, 72.243389190867901561),
P(26.598972199999998622, 72.242452221067154028),
P(26.600826200000000199, 72.242522931717928714),
P(26.603627199999998254, 72.242683603364909573),
P(26.606756300000000692, 72.243241096929352807),
P(26.612569100000001754, 72.244800578667096147),
P(26.615042299999998932, 72.246052459623328446),
P(26.621848599999999863, 72.249011664844303482),
P(26.627471299999999843, 72.250195383365820589),
P(26.641823800000000944, 72.252710806698729584),
P(26.648778100000001245, 72.254338371527666141),
P(26.655288500000001051, 72.25700169234383452),
P(26.660515000000000185, 72.259171735257126556),
P(26.662390800000000723, 72.25996099777080417),
P(26.670629300000001649, 72.263625851730935779),
P(26.671595899999999801, 72.264267979553508781),
P(26.676856199999999575, 72.267335711577246116),
P(26.677412499999999085, 72.267929636079472289),
P(26.676856199999999575, 72.267335711577246116)};
P arr1[376] = {P(25.624035299999999182, 72.26346513007850092), P(25.624273200000001083, 72.263461698303601111),
P(25.624488899999999347, 72.26341365347376211), P(25.624979400000000851, 72.263304218156179104),
P(25.626030799999998777, 72.263025101705878228), P(25.629390999999998257, 72.261676817778678128),
P(25.630162399999999678, 72.26138836631159279), P(25.631299500000000791, 72.260963603282490908),
P(25.63236829999999955, 72.26051310574631259), P(25.63325580000000059, 72.260190152533994024),
P(25.633720499999999021, 72.260019906865807116), P(25.634314799999998513, 72.259865485075735592),
P(25.634578999999998672, 72.259830215951140531), P(25.635424199999999217, 72.259772832171691448),
P(25.635776400000001018, 72.259834791404088605), P(25.638406499999998545, 72.260604806439260983),
P(25.639231599999998679, 72.260931765228107793), P(25.639867699999999928, 72.261237563690428942),
P(25.640699399999999031, 72.261850499331046649), P(25.643624299999999039, 72.264447578158552687),
P(25.644772700000000754, 72.265904403664706024), P(25.645413800000000037, 72.267106341816230497),
P(25.646751600000001758, 72.270404536824941033), P(25.64890219999999843, 72.275985791150915816),
P(25.649064599999999103, 72.276404165523842948), P(25.650549500000000336, 72.279974564589863917),
P(25.651433600000000723, 72.281545386607334081), P(25.652029899999998719, 72.282193025251160634),
P(25.652814700000000414, 72.282915237415323872), P(25.654197199999998702, 72.283799562153532747),
P(25.656540400000000801, 72.285055792411071707), P(25.658162999999998277, 72.286263412818769325),
P(25.661959599999999426, 72.289916920742129491), P(25.663380199999998865, 72.291039561736027963),
P(25.665810499999999195, 72.292780588759853799), P(25.6700361000000008, 72.29585629709197292),
P(25.670962599999999298, 72.296655718166547899), P(25.672222699999998952, 72.297961211704517837),
P(25.673103499999999855, 72.29896171301187735), P(25.674837499999998869, 72.300952077677095531),
P(25.676358000000000459, 72.302732468128681376), P(25.678018200000000348, 72.304444228347662715),
P(25.680309600000001069, 72.306619426588397914), P(25.682252600000001763, 72.308208994982337003),
P(25.685880300000000886, 72.310749482551628375), P(25.6871223999999998, 72.311619291531712861),
P(25.689502399999998516, 72.313337574126506979), P(25.689994200000001001, 72.313685586072296019),
P(25.691337099999998372, 72.314639003020189989), P(25.694014100000000411, 72.316465930359882464),
P(25.696650399999999337, 72.318133963117716689), P(25.697924300000000386, 72.31863598381848135),
P(25.699229800000001234, 72.31891418618496914), P(25.700213699999999051, 72.319045273707061483),
P(25.703616300000000194, 72.319271576784373678), P(25.707311499999999427, 72.319273484907995453),
P(25.715181600000001083, 72.318046763400587906), P(25.72608460000000008, 72.315978426880036523),
P(25.728649600000000675, 72.31539857900408208), P(25.730824299999998317, 72.315156452495600092),
P(25.732753200000001215, 72.314945427265811873), P(25.736661200000000349, 72.315042353781024076),
P(25.74480259999999987, 72.315568583243575063), P(25.747831600000001373, 72.315649864883624787),
P(25.749809599999998966, 72.315866807206518274), P(25.752535200000000515, 72.316023647210727177),
P(25.755610000000000781, 72.315910501039496694), P(25.760463999999998919, 72.315272459413776573),
P(25.762314700000001011, 72.315021747344800929), P(25.763456399999999036, 72.314812630534717641),
P(25.763716200000001066, 72.31478954377344337), P(25.771413500000001306, 72.314102668549878672),
P(25.779617200000000565, 72.313375160856324442), P(25.784148800000000534, 72.313357035273327256),
P(25.790238899999998523, 72.313577786126856495), P(25.793676300000001334, 72.313716876708198811),
P(25.796280599999999339, 72.314048100429985766), P(25.798680499999999682, 72.31463614103191162),
P(25.800190700000001698, 72.315239260045032665), P(25.803071100000000371, 72.316310615756250968),
P(25.806439499999999754, 72.316835901112042961), P(25.809219599999998707, 72.316657116642062419),
P(25.813906700000000427, 72.315918133153061831), P(25.817769800000000657, 72.31543750249576874),
P(25.819804099999998925, 72.315482531661231747), P(25.823219200000000484, 72.315995217547779816),
P(25.824360999999999677, 72.316092908788874638), P(25.825752500000000111, 72.316000750836963107),
P(25.833053499999998337, 72.315183355397863352), P(25.835087900000001326, 72.314863574077250519),
P(25.836477299999998536, 72.314986830897922232), P(25.838510800000001666, 72.315843910886087542),
P(25.84021669999999915, 72.316586137240363996), P(25.845591399999999993, 72.318366369042564656),
P(25.847287900000001315, 72.318912278071522337), P(25.852937300000000675, 72.321233538069833457),
P(25.857534099999998745, 72.324114950429262194), P(25.858493899999999144, 72.324638770105451613),
P(25.859516599999999187, 72.325101910243901671), P(25.860960299999998568, 72.325309341574609334),
P(25.864481800000000078, 72.325170990340012622), P(25.866295099999998541, 72.325066225249685203),
P(25.871619400000000155, 72.324758609934391984), P(25.873917800000000966, 72.324524655307570242),
P(25.875719000000000136, 72.324229064532204347), P(25.882352300000000866, 72.322516991669758113),
P(25.886094899999999797, 72.321551632301222412), P(25.891463999999999146, 72.320154280548763381),
P(25.892594599999998906, 72.32000410941930113), P(25.893775399999999109, 72.320041127430243932),
P(25.895055100000000436, 72.320205228136387632), P(25.901716900000000265, 72.321479884460799781),
P(25.905201399999999268, 72.322148897878847151), P(25.906758400000001075, 72.322300409542663147),
P(25.908453200000000294, 72.322276366107203671), P(25.910453700000001476, 72.322039939449879853),
P(25.912611200000000622, 72.321379323121732341), P(25.914446699999999169, 72.320507670602822259),
P(25.915890699999998503, 72.319578403757603269), P(25.916971199999998987, 72.318721085380474278),
P(25.923277999999999821, 72.312682767056259081), P(25.924315100000001166, 72.311643903530907096),
P(25.925479700000000349, 72.310661910829537646), P(25.926380200000000542, 72.31012846985993292),
P(25.927288000000000778, 72.309673827336439444), P(25.929170299999999116, 72.308742039167825055),
P(25.931695000000001272, 72.307558244187632113), P(25.935542200000000435, 72.305689970006980616),
P(25.936291600000000557, 72.305420216334297834), P(25.937011699999999337, 72.3052109385934898),
P(25.937444899999999137, 72.305171830245583919), P(25.938065999999999178, 72.305126426436075349),
P(25.939194700000001603, 72.305346959512363014), P(25.941637199999998842, 72.306187700803491225),
P(25.951531899999999098, 72.309363611414866568), P(25.958591599999998323, 72.311600021678131611),
P(25.961859900000000323, 72.312588133461261464), P(25.9623209000000017, 72.312845323461488078),
P(25.962808800000001241, 72.313126745396871797), P(25.963783500000001681, 72.313929806056449934),
P(25.964454100000001091, 72.315054565005411291), P(25.966293799999998981, 72.319575350745964215),
P(25.966609900000001687, 72.320173934482440359), P(25.966938999999999993, 72.320628647970096381),
P(25.968776200000000642, 72.322731857094510133), P(25.969766299999999859, 72.323772036806516894),
P(25.97039970000000153, 72.324406914991570261), P(25.971057800000000526, 72.324904784282267656),
P(25.972805199999999815, 72.325716763759459127), P(25.973508700000000005, 72.326106631888762877),
P(25.974174900000001287, 72.326699167072590058), P(25.974623600000001034, 72.327462886785923502),
P(25.97499170000000035, 72.32822527930542833), P(25.975826399999998984, 72.329784823533856297),
P(25.976481499999998448, 72.330935420885211329), P(25.977230399999999833, 72.332212952428704966),
P(25.978115400000000079, 72.333512265445278899), P(25.9789551000000003, 72.33474671239962106),
P(25.980276700000001, 72.336402410819303554), P(25.98169719999999927, 72.337880836033434662),
P(25.983172299999999666, 72.33911288186702393), P(25.984414600000000917, 72.340068567971513858),
P(25.985398499999998734, 72.340636603533639004), P(25.986058100000001048, 72.340908025445514795),
P(25.987230000000000274, 72.341316496490946975), P(25.988157300000001015, 72.341676869267246275),
P(25.991148400000000152, 72.342299318530393748), P(25.997876999999999015, 72.343701138883602653),
P(25.999752600000000768, 72.344154484369809666), P(26.001479700000000861, 72.344723890629211382),
P(26.003023999999999916, 72.345420432028205937), P(26.005314899999998346, 72.346859159309715892),
P(26.007066099999999409, 72.348322733682408625), P(26.008686999999998335, 72.35014618535842601),
P(26.012360000000001037, 72.354910262506038521), P(26.013286199999999582, 72.355943685106993257),
P(26.013858500000001328, 72.35652369166834319), P(26.014633599999999802, 72.357135968669368253),
P(26.015746700000001113, 72.357673410043958029), P(26.017126499999999822, 72.358212001250265644),
P(26.020520199999999988, 72.359278695677289761), P(26.021437599999998724, 72.359644892510004865),
P(26.022532699999999295, 72.360275718006846546), P(26.028545999999998628, 72.365263533617877556),
P(26.029226600000001213, 72.365797602942478761), P(26.030111600000001459, 72.366317546512846093),
P(26.032004199999999372, 72.367306080501194288), P(26.033209299999999331, 72.367834246590078351),
P(26.034265699999998844, 72.368067397148493569), P(26.035592099999998794, 72.368224167962054594),
P(26.03677019999999942, 72.368129074294643033), P(26.043432299999999202, 72.366408627750374194),
P(26.045431499999999403, 72.365842856777021552), P(26.048415399999999664, 72.36504242213915461),
P(26.052753299999999115, 72.363920454888528866), P(26.05556269999999941, 72.363008918012667436),
P(26.060303699999998628, 72.360393712052541559), P(26.065962500000001256, 72.35698705139280662),
P(26.067612400000001571, 72.356026924714299753), P(26.069255399999999412, 72.355021374242639354),
P(26.070335599999999943, 72.354163985856629893), P(26.071483900000000489, 72.353231772141796796),
P(26.073087300000000965, 72.351530224288538307), P(26.07495580000000146, 72.349052146600300262),
P(26.077375199999998756, 72.345412414793742073), P(26.079008800000000434, 72.34322240936705839),
P(26.080636800000000619, 72.341554327036718064), P(26.081818800000000635, 72.340620379333103074),
P(26.083176200000000478, 72.339615440891947173), P(26.085581000000001239, 72.338285853103528211),
P(26.092078799999999461, 72.335142167729841844), P(26.099516500000000008, 72.332061609286498083),
P(26.102282500000001164, 72.330882175026999903), P(26.105014700000001682, 72.329521843521945357),
P(26.108211900000000583, 72.327720133658942814), P(26.116759299999998234, 72.322424061632020198),
P(26.118289900000000614, 72.321345929920937579), P(26.124188000000000187, 72.316306990481081129),
P(26.126093300000000852, 72.314456217615472156), P(26.13131840000000139, 72.308768748722727082),
P(26.133807300000000851, 72.305896196846916268), P(26.135103199999999646, 72.304208818196542552),
P(26.13615610000000089, 72.3027141546473473), P(26.136958199999998698, 72.301545345164157652),
P(26.137658200000000619, 72.300474224549915903), P(26.140487000000000251, 72.29551524417688313),
P(26.146685800000000199, 72.285760107870132174), P(26.151274499999999534, 72.277504651282583836),
P(26.151979099999998368, 72.276113553331668982), P(26.152562700000000717, 72.274582520714972134),
P(26.152978600000000853, 72.272986691312326002), P(26.154697899999998612, 72.264608683472175699),
P(26.155105599999998844, 72.263003939235275652), P(26.155811400000001044, 72.261258344309723611),
P(26.156706599999999696, 72.259655777039213831), P(26.158511799999999425, 72.257073180827120495),
P(26.163497199999998344, 72.251147710512896083), P(26.164152500000000146, 72.250452144382251163),
P(26.165397099999999853, 72.249370018656591697), P(26.171159400000000517, 72.245101348184562084),
P(26.171824600000000771, 72.244502288299599968), P(26.172791700000001214, 72.243464858038208831),
P(26.173422299999998586, 72.24251111483852128), P(26.174280599999999453, 72.240982180618559028),
P(26.174924399999998315, 72.239409446329290176), P(26.175138900000000319, 72.238550480576279256),
P(26.177894599999998348, 72.222417606854094174), P(26.178249600000000896, 72.220799387733251251),
P(26.178700899999999052, 72.219414415122045625), P(26.179689899999999625, 72.217234222262234766),
P(26.182073200000001378, 72.213506738076645775), P(26.18310470000000123, 72.211533626956168064),
P(26.183614800000000855, 72.210338776927230242), P(26.18428000000000111, 72.208417574177602205),
P(26.185804499999999706, 72.203266316303412964), P(26.186153000000000901, 72.202346286216979365),
P(26.186549599999999316, 72.201465316811109574), P(26.187059699999998941, 72.200685882789031211),
P(26.187643699999998859, 72.200064170625580573), P(26.188815999999999207, 72.199110470754774838),
P(26.189986799999999789, 72.198491439723213148), P(26.190943999999998226, 72.198205925482497491),
P(26.192045499999998981, 72.198064597333782899), P(26.201502200000000187, 72.19749033573828001),
P(26.204289599999999183, 72.197194731015855496), P(26.212046699999998367, 72.196023752898682346),
P(26.217400099999998986, 72.195033541852339454), P(26.220660899999998605, 72.194099530393685882),
P(26.223864100000000121, 72.193042117073559893), P(26.227025699999998665, 72.192404096537160285),
P(26.229406099999998503, 72.192154413131575552), P(26.23379059999999896, 72.191934250652863625),
P(26.241092200000000645, 72.191652763688111349), P(26.247795599999999894, 72.191305763109099303),
P(26.259740499999999486, 72.190710990755292187), P(26.262441899999998896, 72.190662426481935654),
P(26.26396259999999927, 72.190803739092231694), P(26.265582200000000768, 72.19108065172507338),
P(26.271514700000000886, 72.192273445913514252), P(26.275603900000000124, 72.192994312937273094),
P(26.278289999999998372, 72.193506828374651718), P(26.280647800000000558, 72.193799369593079973),
P(26.284991699999999071, 72.194193426147350579), P(26.295021899999998283, 72.194996021158502231),
P(26.296629599999999272, 72.195353135208762296), P(26.298219400000000689, 72.195936520796209379),
P(26.299353599999999886, 72.196573622487093758), P(26.300700500000001369, 72.19746290844136638),
P(26.301440499999998224, 72.198127833072547332), P(26.302059899999999715, 72.198747051231549676),
P(26.302597999999999701, 72.199118470577644757), P(26.30326700000000173, 72.200164931796578571),
P(26.304018299999999186, 72.201524555689601925), P(26.305375600000001413, 72.20513574950004454),
P(26.306215500000000418, 72.206942181028665573), P(26.307179600000001329, 72.208595118825385839),
P(26.307805599999998236, 72.209443034325843769), P(26.308593200000000678, 72.210334966852684602),
P(26.309511400000001657, 72.211171854914510959), P(26.310345000000001647, 72.211829485157878139),
P(26.313103999999999161, 72.213550746524816759), P(26.313808999999999116, 72.214105903186023738),
P(26.315858999999999668, 72.21616368063173752), P(26.316473599999998356, 72.216713905276705532),
P(26.317261800000000704, 72.217105619191144683), P(26.318279199999999207, 72.217451609641841515),
P(26.31951039999999864, 72.217778930438797147), P(26.319995200000001034, 72.217883719155963718),
P(26.322028199999998321, 72.21814340535271981), P(26.323134799999998279, 72.218219615725388394),
P(26.324022500000001656, 72.218280774611798734), P(26.32581220000000144, 72.218525220186265301),
P(26.327261700000001099, 72.218861882068196678), P(26.330273800000000506, 72.219715642811124212),
P(26.337171999999998917, 72.221928497785057743), P(26.339137900000000769, 72.222394361231621929),
P(26.341438799999998821, 72.222689314479467271), P(26.343669200000000785, 72.222811640430336411),
P(26.346788899999999956, 72.222677310542948703), P(26.356923500000000615, 72.222042438730937874),
P(26.359536099999999692, 72.2221015051835451), P(26.36183730000000125, 72.222299854521224916),
P(26.366428899999998947, 72.222842507761527031), P(26.374883000000000521, 72.223912965077033732),
P(26.380090800000001394, 72.224542709845593436), P(26.39073850000000121, 72.225869670908153353),
P(26.393878699999998361, 72.226187124115313054), P(26.400813700000000495, 72.226887965488728582),
P(26.405969100000000083, 72.227408932782296347), P(26.434136200000001082, 72.23031015029567925),
P(26.437651200000001239, 72.230672215773722655), P(26.439650799999999009, 72.230860300030158783),
P(26.442400500000001529, 72.230918230849241013), P(26.444426599999999894, 72.230815518016711962),
P(26.454957100000001446, 72.229639190945519545), P(26.455386699999998257, 72.229609273288744475),
P(26.470600499999999755, 72.227804710557407475), P(26.485397899999998828, 72.226080035891357056),
P(26.487313600000000235, 72.226084418502168205), P(26.488673999999999609, 72.226209799401686951),
P(26.489974300000000085, 72.226456941463752059), P(26.493316499999998825, 72.227405883949458598),
P(26.497907399999999001, 72.228727947008763977), P(26.507186099999998419, 72.231355762593423719),
P(26.521764000000001005, 72.235531322949142918), P(26.522283200000000392, 72.235663963313356817),
P(26.52274799999999999, 72.235808991367022713), P(26.523495799999999178, 72.236006428221017472),
P(26.537509100000001183, 72.239985971537208798), P(26.540924100000001573, 72.240959309764491536),
P(26.544420699999999869, 72.241674408812258434), P(26.546888100000000321, 72.242183101965366632),
P(26.5518616999999999, 72.242874580127462991), P(26.562219100000000083, 72.244128903051048951),
P(26.564274399999998622, 72.244315309516480283), P(26.576127799999998302, 72.245028538203385438),
P(26.58263820000000166, 72.244424904560787581), P(26.591367999999999228, 72.243389190867901561),
P(26.598972199999998622, 72.242452221067154028), P(26.600826200000000199, 72.242522931717928714),
P(26.603627199999998254, 72.242683603364909573), P(26.606756300000000692, 72.243241096929352807),
P(26.612569100000001754, 72.244800578667096147), P(26.615042299999998932, 72.246052459623328446),
P(26.621848599999999863, 72.249011664844303482), P(26.627471299999999843, 72.250195383365820589),
P(26.641823800000000944, 72.252710806698729584), P(26.648778100000001245, 72.254338371527666141),
P(26.655288500000001051, 72.25700169234383452), P(26.660515000000000185, 72.259171735257126556),
P(26.662390800000000723, 72.25996099777080417), P(26.670629300000001649, 72.263625851730935779),
P(26.671595899999999801, 72.264267979553508781), P(26.676856199999999575, 72.267335711577246116),
P(26.677412499999999085, 72.267929636079472289), P(26.676856199999999575, 72.267335711577246116)};
} // namespace geometry_coding_tests

View File

@@ -47,8 +47,7 @@ void Test(vector<TrafficGPSEncoder::DataPoint> & points)
TEST_EQUAL(points.size(), result.size(), ());
for (size_t i = 0; i < points.size(); ++i)
{
TEST_EQUAL(points[i].m_timestamp, result[i].m_timestamp,
(points[i].m_timestamp, result[i].m_timestamp));
TEST_EQUAL(points[i].m_timestamp, result[i].m_timestamp, (points[i].m_timestamp, result[i].m_timestamp));
TEST(AlmostEqualAbsOrRel(points[i].m_latLon.m_lat, result[i].m_latLon.m_lat, kEps),
(points[i].m_latLon.m_lat, result[i].m_latLon.m_lat));
TEST(AlmostEqualAbsOrRel(points[i].m_latLon.m_lon, result[i].m_latLon.m_lon, kEps),
@@ -57,8 +56,8 @@ void Test(vector<TrafficGPSEncoder::DataPoint> & points)
if (version == TrafficGPSEncoder::kLatestVersion)
{
LOG(LINFO, ("path length =", CalculateLength(points), "num points =", points.size(),
"compressed size =", buf.size()));
LOG(LINFO,
("path length =", CalculateLength(points), "num points =", points.size(), "compressed size =", buf.size()));
}
}
}
@@ -66,7 +65,8 @@ void Test(vector<TrafficGPSEncoder::DataPoint> & points)
UNIT_TEST(Traffic_Serialization_Smoke)
{
vector<TrafficGPSEncoder::DataPoint> data = {
{0, ms::LatLon(0.0, 1.0), 1}, {0, ms::LatLon(0.0, 2.0), 2},
{0, ms::LatLon(0.0, 1.0), 1},
{0, ms::LatLon(0.0, 2.0), 2},
};
Test(data);
}
@@ -80,7 +80,8 @@ UNIT_TEST(Traffic_Serialization_EmptyPath)
UNIT_TEST(Traffic_Serialization_StraightLine100m)
{
vector<TrafficGPSEncoder::DataPoint> path = {
{0, ms::LatLon(0.0, 0.0), 1}, {0, ms::LatLon(0.0, 1e-3), 2},
{0, ms::LatLon(0.0, 0.0), 1},
{0, ms::LatLon(0.0, 1e-3), 2},
};
Test(path);
}
@@ -88,7 +89,8 @@ UNIT_TEST(Traffic_Serialization_StraightLine100m)
UNIT_TEST(Traffic_Serialization_StraightLine50Km)
{
vector<TrafficGPSEncoder::DataPoint> path = {
{0, ms::LatLon(0.0, 0.0), 1}, {0, ms::LatLon(0.0, 0.5), 2},
{0, ms::LatLon(0.0, 0.0), 1},
{0, ms::LatLon(0.0, 0.5), 2},
};
Test(path);
}
@@ -147,7 +149,8 @@ UNIT_TEST(Traffic_Serialization_Circle20KmRadius)
UNIT_TEST(Traffic_Serialization_ExtremeLatLon)
{
vector<TrafficGPSEncoder::DataPoint> path = {
{0, ms::LatLon(-90, -180), 0}, {0, ms::LatLon(90, 180), 0},
{0, ms::LatLon(-90, -180), 0},
{0, ms::LatLon(90, 180), 0},
};
Test(path);
}

View File

@@ -18,9 +18,21 @@ class TestUrl
public:
explicit TestUrl(string && url) : m_url(std::move(url)) {}
TestUrl & Scheme(string && scheme) { m_scheme = std::move(scheme); return *this; }
TestUrl & Host(string && host) { m_host = std::move(host); return *this; }
TestUrl & Path(string && path) { m_path = std::move(path); return *this; }
TestUrl & Scheme(string && scheme)
{
m_scheme = std::move(scheme);
return *this;
}
TestUrl & Host(string && host)
{
m_host = std::move(host);
return *this;
}
TestUrl & Path(string && path)
{
m_path = std::move(path);
return *this;
}
TestUrl & KV(string && key, string && value)
{
m_keyValuePairs.emplace(std::move(key), std::move(value));
@@ -115,17 +127,9 @@ UNIT_TEST(Url_Valid)
.KV("ll", "10.3,12.3223")
.KV("n", "Hello World");
TestUrl("cm:M&M//path?q=q&w=w")
.Scheme("cm")
.Host("M&M")
.Path("path")
.KV("q", "q")
.KV("w", "w");
TestUrl("cm:M&M//path?q=q&w=w").Scheme("cm").Host("M&M").Path("path").KV("q", "q").KV("w", "w");
TestUrl("http://www.sandwichparlour.com.au/")
.Scheme("http")
.Host("www.sandwichparlour.com.au")
.Path("");
TestUrl("http://www.sandwichparlour.com.au/").Scheme("http").Host("www.sandwichparlour.com.au").Path("");
TestUrl("cm:/&test").Scheme("cm").Host("&test").Path("");
}
@@ -160,21 +164,40 @@ UNIT_TEST(UrlScheme_Comprehensive)
TestUrl("http://host/path/to/something").Scheme("http").Host("host").Path("path/to/something");
TestUrl("http://host?").Scheme("http").Host("host").Path("");
TestUrl("maps://host?&&key=&").Scheme("maps").Host("host").KV("key", "");
TestUrl("mapswithme://map?ll=1.2,3.4&z=15").Scheme("mapswithme").Host("map").Path("")
.KV("ll", "1.2,3.4").KV("z", "15");
TestUrl("nopathnovalues://?key1&key2=val2").Scheme("nopathnovalues").Host("").Path("")
.KV("key1", "").KV("key2", "val2");
TestUrl("mapswithme://map?ll=1.2,3.4&z=15")
.Scheme("mapswithme")
.Host("map")
.Path("")
.KV("ll", "1.2,3.4")
.KV("z", "15");
TestUrl("nopathnovalues://?key1&key2=val2")
.Scheme("nopathnovalues")
.Host("")
.Path("")
.KV("key1", "")
.KV("key2", "val2");
TestUrl("s://?key1&key2").Scheme("s").Host("").Path("").KV("key1", "").KV("key2", "");
TestUrl("g://h/p?key1=val1&key2=").Scheme("g").Host("h").Path("p").KV("key1", "val1").KV("key2", "");
TestUrl("g://h?=val1&key2=").Scheme("g").Host("h").Path("").KV("", "val1").KV("key2", "");
TestUrl("g://?k&key2").Scheme("g").Host("").Path("").KV("k", "").KV("key2", "");
TestUrl("m:?%26Amp%26%3D%26Amp%26&name=%31%20%30").Scheme("m").Host("").Path("")
.KV("&Amp&=&Amp&", "").KV("name", "1 0");
TestUrl("m:?%26Amp%26%3D%26Amp%26&name=%31%20%30")
.Scheme("m")
.Host("")
.Path("")
.KV("&Amp&=&Amp&", "")
.KV("name", "1 0");
TestUrl("s://?key1=value1&key1=value2&key1=value3&key2&key2&key3=value1&key3&key3=value2")
.Scheme("s").Host("").Path("")
.KV("key1", "value1").KV("key1", "value2").KV("key1", "value3")
.KV("key2", "").KV("key2", "")
.KV("key3", "value1").KV("key3", "").KV("key3", "value2");
.Scheme("s")
.Host("")
.Path("")
.KV("key1", "value1")
.KV("key1", "value2")
.KV("key1", "value3")
.KV("key2", "")
.KV("key2", "")
.KV("key3", "value1")
.KV("key3", "")
.KV("key3", "value2");
}
UNIT_TEST(UrlApi_Smoke)

View File

@@ -22,7 +22,7 @@ void TestStringCodingT(T const * arr, size_t count, size_t maxSize)
s.Set(ethalon);
std::vector<char> buffer;
MemWriter<std::vector<char> > w(buffer);
MemWriter<std::vector<char>> w(buffer);
s.Write(w);
@@ -38,7 +38,7 @@ void TestStringCodingT(T const * arr, size_t count, size_t maxSize)
}
}
} // namespace
} // namespace
UNIT_TEST(StringNumericOptimal_Zero)
{
@@ -51,19 +51,19 @@ UNIT_TEST(StringNumericOptimal_Zero)
UNIT_TEST(StringNumericOptimal_IntCoding1)
{
int arr[] = { 0, 1, 2, 666, 0x0FFFFFFF, 0x7FFFFFFF-1, 0x7FFFFFFF };
int arr[] = {0, 1, 2, 666, 0x0FFFFFFF, 0x7FFFFFFF - 1, 0x7FFFFFFF};
TestStringCodingT(arr, ARRAY_SIZE(arr), 5); // should be coded as VarUint
}
UNIT_TEST(StringNumericOptimal_IntCoding2)
{
int arr[] = { -1, -2, -666666, static_cast<int>(0xFFFFFFFE), static_cast<int>(0xFFFFFFFF) };
int arr[] = {-1, -2, -666666, static_cast<int>(0xFFFFFFFE), static_cast<int>(0xFFFFFFFF)};
TestStringCodingT(arr, ARRAY_SIZE(arr), 12); // should be coded as String
}
UNIT_TEST(StringNumericOptimal_StringCoding)
{
char const * arr[] = { "xxx", "yyy", "a", "0xFFFFFF", "123456UL" };
char const * arr[] = {"xxx", "yyy", "a", "0xFFFFFF", "123456UL"};
TestStringCodingT(arr, ARRAY_SIZE(arr), 12); // should be coded as String
}

View File

@@ -17,36 +17,37 @@ using namespace std;
namespace
{
struct SaveForEachParams
struct SaveForEachParams
{
explicit SaveForEachParams(vector<pair<uint64_t, string>> & data) : m_data(data) {}
void operator()(uint64_t pos, vector<uint8_t> && data) const
{
explicit SaveForEachParams(vector<pair<uint64_t, string>> & data) : m_data(data) {}
m_data.emplace_back(pos, string(data.begin(), data.end()));
}
void operator()(uint64_t pos, vector<uint8_t> && data) const
{
m_data.emplace_back(pos, string(data.begin(), data.end()));
}
vector<pair<uint64_t, string>> & m_data;
};
vector<pair<uint64_t, string>> & m_data;
};
}
} // namespace
UNIT_TEST(VarRecordReader_Simple)
{
vector<uint8_t> data;
char const longString[] = "0123456789012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789012345";
char const longString[] =
"0123456789012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789012345";
size_t const longStringSize = sizeof(longString) - 1;
TEST_GREATER(longStringSize, 128, ());
{
MemWriter<vector<uint8_t>> writer(data);
WriteVarUint(writer, 3U); // 0
writer.Write("abc", 3); // 1
WriteVarUint(writer, longStringSize); // 4
writer.Write(longString, longStringSize); // 6
WriteVarUint(writer, 4U); // 6 + longStringSize
writer.Write("defg", 4); // 7 + longStringSize
// 11 + longStringSize
WriteVarUint(writer, 3U); // 0
writer.Write("abc", 3); // 1
WriteVarUint(writer, longStringSize); // 4
writer.Write(longString, longStringSize); // 6
WriteVarUint(writer, 4U); // 6 + longStringSize
writer.Write("defg", 4); // 7 + longStringSize
// 11 + longStringSize
}
MemReader reader(&data[0], data.size());
@@ -63,8 +64,6 @@ UNIT_TEST(VarRecordReader_Simple)
vector<pair<uint64_t, string>> forEachCalls;
recordReader.ForEachRecord(SaveForEachParams(forEachCalls));
vector<pair<uint64_t, string>> expectedForEachCalls = {{0, "abc"},
{4, longString},
{6 + longStringSize, "defg"}};
vector<pair<uint64_t, string>> expectedForEachCalls = {{0, "abc"}, {4, longString}, {6 + longStringSize, "defg"}};
TEST_EQUAL(forEachCalls, expectedForEachCalls, ());
}

View File

@@ -16,7 +16,12 @@
using namespace std;
char const kHexSerial[] = "03000000" "01000000" "04000000" "06000000" "616263646566";
char const kHexSerial[] =
"03000000"
"01000000"
"04000000"
"06000000"
"616263646566";
namespace
{
@@ -45,7 +50,7 @@ void WriteVarSerialVector(ItT begin, ItT end, TDstStream & dst)
}
}
}
} // namespace
UNIT_TEST(WriteSerial)
{
@@ -65,7 +70,7 @@ UNIT_TEST(WriteSerialWithWriter)
{
string output;
MemWriter<string> writer(output);
VarSerialVectorWriter<MemWriter<string> > recordWriter(writer, 3);
VarSerialVectorWriter<MemWriter<string>> recordWriter(writer, 3);
writer.Write("a", 1);
recordWriter.FinishRecord();
writer.Write("bcd", 3);

View File

@@ -12,33 +12,35 @@ using namespace std;
namespace
{
template <typename T> void TestVarUint(T const x)
{
vector<unsigned char> data;
PushBackByteSink<vector<uint8_t>> dst(data);
WriteVarUint(dst, x);
template <typename T>
void TestVarUint(T const x)
{
vector<unsigned char> data;
PushBackByteSink<vector<uint8_t>> dst(data);
WriteVarUint(dst, x);
ArrayByteSource src(&data[0]);
TEST_EQUAL(ReadVarUint<T>(src), x, ());
ArrayByteSource src(&data[0]);
TEST_EQUAL(ReadVarUint<T>(src), x, ());
size_t const bytesRead = src.PtrUint8() - data.data();
TEST_EQUAL(bytesRead, data.size(), (x));
}
template <typename T> void TestVarInt(T const x)
{
vector<uint8_t> data;
PushBackByteSink<vector<uint8_t>> dst(data);
WriteVarInt(dst, x);
ArrayByteSource src(&data[0]);
TEST_EQUAL(ReadVarInt<T>(src), x, ());
size_t const bytesRead = src.PtrUint8() - data.data();
TEST_EQUAL(bytesRead, data.size(), (x));
}
size_t const bytesRead = src.PtrUint8() - data.data();
TEST_EQUAL(bytesRead, data.size(), (x));
}
template <typename T>
void TestVarInt(T const x)
{
vector<uint8_t> data;
PushBackByteSink<vector<uint8_t>> dst(data);
WriteVarInt(dst, x);
ArrayByteSource src(&data[0]);
TEST_EQUAL(ReadVarInt<T>(src), x, ());
size_t const bytesRead = src.PtrUint8() - data.data();
TEST_EQUAL(bytesRead, data.size(), (x));
}
} // namespace
UNIT_TEST(VarUint0)
{
// TestVarUint(static_cast<uint8_t>(0));
@@ -125,11 +127,16 @@ UNIT_TEST(ReadVarInt64Array)
// Fill in values.
{
int64_t const baseValues [] =
{
0, 127, 128, (2 << 28) - 1, (2 << 28), (2LL << 31), (2LL << 31) - 1,
0xFFFFFFFF - 1, 0xFFFFFFFF, 0xFFFFFFFFFFULL
};
int64_t const baseValues[] = {0,
127,
128,
(2 << 28) - 1,
(2 << 28),
(2LL << 31),
(2LL << 31) - 1,
0xFFFFFFFF - 1,
0xFFFFFFFF,
0xFFFFFFFFFFULL};
for (size_t i = 0; i < ARRAY_SIZE(baseValues); ++i)
{
values.push_back(baseValues[i]);
@@ -164,20 +171,17 @@ UNIT_TEST(ReadVarInt64Array)
void const * pDataEnd = &data[0] + data.size();
vector<int64_t> result;
void const * pEnd = ReadVarInt64Array(pDataStart, pDataEnd,
base::MakeBackInsertFunctor(result));
void const * pEnd = ReadVarInt64Array(pDataStart, pDataEnd, base::MakeBackInsertFunctor(result));
TEST_EQUAL(pEnd, pDataEnd, ("UntilBufferEnd", data.size()));
TEST_EQUAL(result, testValues, ("UntilBufferEnd", data.size()));
}
{
vector<int64_t> result;
void const * pEnd = ReadVarInt64Array(&data[0], testValues.size(),
base::MakeBackInsertFunctor(result));
void const * pEnd = ReadVarInt64Array(&data[0], testValues.size(), base::MakeBackInsertFunctor(result));
TEST_EQUAL(pEnd, &data[0] + data.size(), ("GivenSize", data.size()));
TEST_EQUAL(result, testValues, ("GivenSize", data.size()));
}
}
}

View File

@@ -1,8 +1,8 @@
#include "testing/testing.hpp"
#include "coding/buffered_file_writer.hpp"
#include "coding/file_writer.hpp"
#include "coding/file_reader.hpp"
#include "coding/file_writer.hpp"
#include "coding/internal/file_data.hpp"
#include <cstddef>
@@ -14,43 +14,43 @@ using namespace std;
namespace
{
static char const kTestWriteStr [] = "01234567";
static char const kTestWriteStr[] = "01234567";
template <class WriterT>
void TestWrite(WriterT & writer)
{
writer.Write("01", 2); // "01"
TEST_EQUAL(writer.Pos(), 2, ());
writer.Write("x", 1); // "01x"
TEST_EQUAL(writer.Pos(), 3, ());
writer.Write("3", 1); // "01x3"
TEST_EQUAL(writer.Pos(), 4, ());
writer.Seek(2);
TEST_EQUAL(writer.Pos(), 2, ());
writer.Write("2", 1); // "0123"
TEST_EQUAL(writer.Pos(), 3, ());
writer.Seek(7);
TEST_EQUAL(writer.Pos(), 7, ());
writer.Write("7", 1); // "0123???7"
TEST_EQUAL(writer.Pos(), 8, ());
writer.Seek(4);
TEST_EQUAL(writer.Pos(), 4, ());
writer.Write("45", 2); // "012345?7"
writer.Write("6", 1); // "01234567"
}
template <class WriterT>
void TestWrite(WriterT & writer)
{
writer.Write("01", 2); // "01"
TEST_EQUAL(writer.Pos(), 2, ());
writer.Write("x", 1); // "01x"
TEST_EQUAL(writer.Pos(), 3, ());
writer.Write("3", 1); // "01x3"
TEST_EQUAL(writer.Pos(), 4, ());
writer.Seek(2);
TEST_EQUAL(writer.Pos(), 2, ());
writer.Write("2", 1); // "0123"
TEST_EQUAL(writer.Pos(), 3, ());
writer.Seek(7);
TEST_EQUAL(writer.Pos(), 7, ());
writer.Write("7", 1); // "0123???7"
TEST_EQUAL(writer.Pos(), 8, ());
writer.Seek(4);
TEST_EQUAL(writer.Pos(), 4, ());
writer.Write("45", 2); // "012345?7"
writer.Write("6", 1); // "01234567"
}
} // namespace
UNIT_TEST(MemWriter_Smoke)
{
vector<char> s;
MemWriter<vector<char> > writer(s);
MemWriter<vector<char>> writer(s);
TestWrite(writer);
TEST_EQUAL(string(s.begin(), s.end()), kTestWriteStr, ());
}
UNIT_TEST(FileWriter_Smoke)
{
char const fileName [] = "file_writer_smoke_test.tmp";
char const fileName[] = "file_writer_smoke_test.tmp";
{
FileWriter writer(fileName);
TestWrite(writer);
@@ -68,10 +68,10 @@ UNIT_TEST(FileWriter_Smoke)
UNIT_TEST(SubWriter_MemWriter_Smoke)
{
vector<char> s;
MemWriter<vector<char> > writer(s);
MemWriter<vector<char>> writer(s);
writer.Write("aa", 2);
{
SubWriter<MemWriter<vector<char> > > subWriter(writer);
SubWriter<MemWriter<vector<char>>> subWriter(writer);
TestWrite(subWriter);
}
writer.Write("bb", 2);
@@ -80,7 +80,7 @@ UNIT_TEST(SubWriter_MemWriter_Smoke)
UNIT_TEST(SubWriter_FileWriter_Smoke)
{
char const fileName [] = "sub_file_writer_smoke_test.tmp";
char const fileName[] = "sub_file_writer_smoke_test.tmp";
{
FileWriter writer(fileName);
writer.Write("aa", 2);
@@ -102,7 +102,7 @@ UNIT_TEST(SubWriter_FileWriter_Smoke)
UNIT_TEST(FileWriter_DeleteFile)
{
char const fileName [] = "delete_file_test";
char const fileName[] = "delete_file_test";
{
FileWriter writer(fileName);
writer.Write("123", 3);
@@ -117,14 +117,13 @@ UNIT_TEST(FileWriter_DeleteFile)
FileReader reader(fileName);
TEST(false, ("Exception should be thrown!"));
}
catch (FileReader::OpenException & )
{
}
catch (FileReader::OpenException &)
{}
}
UNIT_TEST(FileWriter_AppendAndOpenExisting)
{
char const fileName [] = "append_openexisting_file_test";
char const fileName[] = "append_openexisting_file_test";
{
FileWriter writer(fileName);
}
@@ -187,14 +186,14 @@ void WriteTestData1(Writer & w)
void WriteTestData2(Writer & w)
{
char c[CHUNK_SIZE];
for (size_t i = 1; i < CHUNKS_COUNT; i +=2)
for (size_t i = 1; i < CHUNKS_COUNT; i += 2)
{
for (size_t j = 0; j < ARRAY_SIZE(c); ++j)
c[j] = i;
w.Seek(i * CHUNK_SIZE);
w.Write(&c[0], ARRAY_SIZE(c));
}
for (size_t i = 0; i < CHUNKS_COUNT; i +=2)
for (size_t i = 0; i < CHUNKS_COUNT; i += 2)
{
for (size_t j = 0; j < ARRAY_SIZE(c); ++j)
c[j] = i;

View File

@@ -55,10 +55,7 @@ public:
void CharData(std::string const & ch) {}
void AddAttr(std::string key, std::string value)
{
m_addAttrs.emplace_back(std::move(key), std::move(value));
}
void AddAttr(std::string key, std::string value) { m_addAttrs.emplace_back(std::move(key), std::move(value)); }
bool Push(std::string push)
{
@@ -66,25 +63,13 @@ public:
return true;
}
void Pop(std::string pop)
{
m_pops.emplace_back(std::move(pop));
}
void Pop(std::string pop) { m_pops.emplace_back(std::move(pop)); }
void TestAddAttrs(PairsOfStrings const & addAttrs)
{
TestEquality(m_addAttrs, addAttrs);
}
void TestAddAttrs(PairsOfStrings const & addAttrs) { TestEquality(m_addAttrs, addAttrs); }
void TestPushes(Strings const & pushes)
{
TestEquality(m_pushes, pushes);
}
void TestPushes(Strings const & pushes) { TestEquality(m_pushes, pushes); }
void TestPops(Strings const & pops)
{
TestEquality(m_pops, pops);
}
void TestPops(Strings const & pops) { TestEquality(m_pops, pops); }
private:
template <typename F>
@@ -123,13 +108,12 @@ UNIT_TEST(XmlParser_LongTest)
{
Dispatcher d;
TestXML(longXml, d);
d.TestAddAttrs({std::make_pair("vertical", "bottom"), std::make_pair("horizontal", "left"),
std::make_pair("x", "10"), std::make_pair("vertical", "center"),
std::make_pair("vertical", "top"), std::make_pair("vertical", "top"),
std::make_pair("x", "34"), std::make_pair("y", "48")});
d.TestPushes({"root", "ruler", "portrait", "anchor", "offset", "compass", "portrait", "anchor",
"relative", "landscape", "relative", "offset"});
d.TestPops({"anchor", "offset", "portrait", "ruler", "anchor", "relative", "portrait", "relative",
"offset", "landscape", "compass", "root"});
d.TestAddAttrs({std::make_pair("vertical", "bottom"), std::make_pair("horizontal", "left"), std::make_pair("x", "10"),
std::make_pair("vertical", "center"), std::make_pair("vertical", "top"),
std::make_pair("vertical", "top"), std::make_pair("x", "34"), std::make_pair("y", "48")});
d.TestPushes({"root", "ruler", "portrait", "anchor", "offset", "compass", "portrait", "anchor", "relative",
"landscape", "relative", "offset"});
d.TestPops({"anchor", "offset", "portrait", "ruler", "anchor", "relative", "portrait", "relative", "offset",
"landscape", "compass", "root"});
}
} // namespace

View File

@@ -1,10 +1,10 @@
#include "testing/testing.hpp"
#include "coding/constants.hpp"
#include "coding/file_writer.hpp"
#include "coding/internal/file_data.hpp"
#include "coding/zip_creator.hpp"
#include "coding/zip_reader.hpp"
#include "coding/internal/file_data.hpp"
#include "coding/file_writer.hpp"
#include "coding/constants.hpp"
#include "base/scope_guard.hpp"
@@ -30,8 +30,7 @@ void CreateAndTestZip(std::string const & filePath, std::string const & zipPath)
TEST(base::DeleteFileX(unzippedFile), ());
}
void CreateAndTestZip(std::vector<std::string> const & files, std::string const & zipPath,
CompressionLevel compression)
void CreateAndTestZip(std::vector<std::string> const & files, std::string const & zipPath, CompressionLevel compression)
{
TEST(CreateZipFromFiles(files, zipPath, compression), ());
@@ -50,8 +49,8 @@ void CreateAndTestZip(std::vector<std::string> const & files, std::string const
TEST(base::DeleteFileX(zipPath), ());
}
void CreateAndTestZipWithFolder(std::vector<std::string> const & files, std::vector<std::string> const & filesInArchive, std::string const & zipPath,
CompressionLevel compression)
void CreateAndTestZipWithFolder(std::vector<std::string> const & files, std::vector<std::string> const & filesInArchive,
std::string const & zipPath, CompressionLevel compression)
{
TEST(CreateZipFromFiles(files, filesInArchive, zipPath, compression), ());
@@ -72,10 +71,10 @@ void CreateAndTestZipWithFolder(std::vector<std::string> const & files, std::vec
std::vector<CompressionLevel> GetCompressionLevels()
{
return {CompressionLevel::DefaultCompression, CompressionLevel::BestCompression,
CompressionLevel::BestSpeed, CompressionLevel::NoCompression};
}
return {CompressionLevel::DefaultCompression, CompressionLevel::BestCompression, CompressionLevel::BestSpeed,
CompressionLevel::NoCompression};
}
} // namespace
UNIT_TEST(CreateZip_BigFile)
{
@@ -105,7 +104,8 @@ UNIT_TEST(CreateZip_Smoke)
UNIT_TEST(CreateZip_MultipleFiles)
{
std::vector<std::string> const fileData{"testf1", "testfile2", "testfile3_longname.txt.xml.csv"};
SCOPE_GUARD(deleteFileGuard, [&fileData]() {
SCOPE_GUARD(deleteFileGuard, [&fileData]()
{
for (auto const & file : fileData)
TEST(base::DeleteFileX(file), ());
});
@@ -150,7 +150,5 @@ UNIT_TEST(CreateZip_MultipleFilesSingleEmpty)
}
for (auto compression : GetCompressionLevels())
{
CreateAndTestZip(fileData, "testzip.zip", compression);
}
}

View File

@@ -1,7 +1,7 @@
#include "testing/testing.hpp"
#include "coding/zip_reader.hpp"
#include "coding/file_writer.hpp"
#include "coding/zip_reader.hpp"
#include "base/logging.hpp"
#include "base/macros.hpp"
@@ -11,17 +11,18 @@
using namespace std;
static char const zipBytes[] = "PK\003\004\n\0\0\0\0\0\222\226\342>\302\032"
"x\372\005\0\0\0\005\0\0\0\b\0\034\0te"
"st.txtUT\t\0\003\303>\017N\017"
"?\017Nux\v\0\001\004\365\001\0\0\004P\0"
"\0\0Test\nPK\001\002\036\003\n\0\0"
"\0\0\0\222\226\342>\302\032x\372\005\0\0\0\005"
"\0\0\0\b\0\030\0\0\0\0\0\0\0\0\0\244"
"\201\0\0\0\0test.txtUT\005"
"\0\003\303>\017Nux\v\0\001\004\365\001\0\0"
"\004P\0\0\0PK\005\006\0\0\0\0\001\0\001"
"\0N\0\0\0G\0\0\0\0\0";
static char const zipBytes[] =
"PK\003\004\n\0\0\0\0\0\222\226\342>\302\032"
"x\372\005\0\0\0\005\0\0\0\b\0\034\0te"
"st.txtUT\t\0\003\303>\017N\017"
"?\017Nux\v\0\001\004\365\001\0\0\004P\0"
"\0\0Test\nPK\001\002\036\003\n\0\0"
"\0\0\0\222\226\342>\302\032x\372\005\0\0\0\005"
"\0\0\0\b\0\030\0\0\0\0\0\0\0\0\0\244"
"\201\0\0\0\0test.txtUT\005"
"\0\003\303>\017Nux\v\0\001\004\365\001\0\0"
"\004P\0\0\0PK\005\006\0\0\0\0\001\0\001"
"\0N\0\0\0G\0\0\0\0\0";
UNIT_TEST(ZipReaderSmoke)
{
@@ -74,21 +75,22 @@ UNIT_TEST(ZipReaderSmoke)
}
/// zip file with 3 files inside: 1.txt, 2.txt, 3.ttt
static char const zipBytes2[] = "\x50\x4b\x3\x4\xa\x0\x0\x0\x0\x0\x92\x6b\xf6\x3e\x53\xfc\x51\x67\x2\x0\x0"
"\x0\x2\x0\x0\x0\x5\x0\x1c\x0\x31\x2e\x74\x78\x74\x55\x54\x9\x0\x3\xd3\x50\x29\x4e\xd4\x50\x29\x4e\x75\x78"
"\xb\x0\x1\x4\xf5\x1\x0\x0\x4\x14\x0\x0\x0\x31\xa\x50\x4b\x3\x4\xa\x0\x0\x0\x0\x0\x95\x6b\xf6\x3e\x90\xaf"
"\x7c\x4c\x2\x0\x0\x0\x2\x0\x0\x0\x5\x0\x1c\x0\x32\x2e\x74\x78\x74\x55\x54\x9\x0\x3\xd9\x50\x29\x4e\xd9\x50"
"\x29\x4e\x75\x78\xb\x0\x1\x4\xf5\x1\x0\x0\x4\x14\x0\x0\x0\x32\xa\x50\x4b\x3\x4\xa\x0\x0\x0\x0\x0\x9c\x6b"
"\xf6\x3e\xd1\x9e\x67\x55\x2\x0\x0\x0\x2\x0\x0\x0\x5\x0\x1c\x0\x33\x2e\x74\x74\x74\x55\x54\x9\x0\x3\xe8\x50"
"\x29\x4e\xe9\x50\x29\x4e\x75\x78\xb\x0\x1\x4\xf5\x1\x0\x0\x4\x14\x0\x0\x0\x33\xa\x50\x4b\x1\x2\x1e\x3\xa"
"\x0\x0\x0\x0\x0\x92\x6b\xf6\x3e\x53\xfc\x51\x67\x2\x0\x0\x0\x2\x0\x0\x0\x5\x0\x18\x0\x0\x0\x0\x0\x1\x0\x0"
"\x0\xa4\x81\x0\x0\x0\x0\x31\x2e\x74\x78\x74\x55\x54\x5\x0\x3\xd3\x50\x29\x4e\x75\x78\xb\x0\x1\x4\xf5\x1\x0"
"\x0\x4\x14\x0\x0\x0\x50\x4b\x1\x2\x1e\x3\xa\x0\x0\x0\x0\x0\x95\x6b\xf6\x3e\x90\xaf\x7c\x4c\x2\x0\x0\x0\x2"
"\x0\x0\x0\x5\x0\x18\x0\x0\x0\x0\x0\x1\x0\x0\x0\xa4\x81\x41\x0\x0\x0\x32\x2e\x74\x78\x74\x55\x54\x5\x0\x3"
"\xd9\x50\x29\x4e\x75\x78\xb\x0\x1\x4\xf5\x1\x0\x0\x4\x14\x0\x0\x0\x50\x4b\x1\x2\x1e\x3\xa\x0\x0\x0\x0\x0"
"\x9c\x6b\xf6\x3e\xd1\x9e\x67\x55\x2\x0\x0\x0\x2\x0\x0\x0\x5\x0\x18\x0\x0\x0\x0\x0\x1\x0\x0\x0\xa4\x81\x82"
"\x0\x0\x0\x33\x2e\x74\x74\x74\x55\x54\x5\x0\x3\xe8\x50\x29\x4e\x75\x78\xb\x0\x1\x4\xf5\x1\x0\x0\x4\x14\x0"
"\x0\x0\x50\x4b\x5\x6\x0\x0\x0\x0\x3\x0\x3\x0\xe1\x0\x0\x0\xc3\x0\x0\x0\x0\x0";
static char const zipBytes2[] =
"\x50\x4b\x3\x4\xa\x0\x0\x0\x0\x0\x92\x6b\xf6\x3e\x53\xfc\x51\x67\x2\x0\x0"
"\x0\x2\x0\x0\x0\x5\x0\x1c\x0\x31\x2e\x74\x78\x74\x55\x54\x9\x0\x3\xd3\x50\x29\x4e\xd4\x50\x29\x4e\x75\x78"
"\xb\x0\x1\x4\xf5\x1\x0\x0\x4\x14\x0\x0\x0\x31\xa\x50\x4b\x3\x4\xa\x0\x0\x0\x0\x0\x95\x6b\xf6\x3e\x90\xaf"
"\x7c\x4c\x2\x0\x0\x0\x2\x0\x0\x0\x5\x0\x1c\x0\x32\x2e\x74\x78\x74\x55\x54\x9\x0\x3\xd9\x50\x29\x4e\xd9\x50"
"\x29\x4e\x75\x78\xb\x0\x1\x4\xf5\x1\x0\x0\x4\x14\x0\x0\x0\x32\xa\x50\x4b\x3\x4\xa\x0\x0\x0\x0\x0\x9c\x6b"
"\xf6\x3e\xd1\x9e\x67\x55\x2\x0\x0\x0\x2\x0\x0\x0\x5\x0\x1c\x0\x33\x2e\x74\x74\x74\x55\x54\x9\x0\x3\xe8\x50"
"\x29\x4e\xe9\x50\x29\x4e\x75\x78\xb\x0\x1\x4\xf5\x1\x0\x0\x4\x14\x0\x0\x0\x33\xa\x50\x4b\x1\x2\x1e\x3\xa"
"\x0\x0\x0\x0\x0\x92\x6b\xf6\x3e\x53\xfc\x51\x67\x2\x0\x0\x0\x2\x0\x0\x0\x5\x0\x18\x0\x0\x0\x0\x0\x1\x0\x0"
"\x0\xa4\x81\x0\x0\x0\x0\x31\x2e\x74\x78\x74\x55\x54\x5\x0\x3\xd3\x50\x29\x4e\x75\x78\xb\x0\x1\x4\xf5\x1\x0"
"\x0\x4\x14\x0\x0\x0\x50\x4b\x1\x2\x1e\x3\xa\x0\x0\x0\x0\x0\x95\x6b\xf6\x3e\x90\xaf\x7c\x4c\x2\x0\x0\x0\x2"
"\x0\x0\x0\x5\x0\x18\x0\x0\x0\x0\x0\x1\x0\x0\x0\xa4\x81\x41\x0\x0\x0\x32\x2e\x74\x78\x74\x55\x54\x5\x0\x3"
"\xd9\x50\x29\x4e\x75\x78\xb\x0\x1\x4\xf5\x1\x0\x0\x4\x14\x0\x0\x0\x50\x4b\x1\x2\x1e\x3\xa\x0\x0\x0\x0\x0"
"\x9c\x6b\xf6\x3e\xd1\x9e\x67\x55\x2\x0\x0\x0\x2\x0\x0\x0\x5\x0\x18\x0\x0\x0\x0\x0\x1\x0\x0\x0\xa4\x81\x82"
"\x0\x0\x0\x33\x2e\x74\x74\x74\x55\x54\x5\x0\x3\xe8\x50\x29\x4e\x75\x78\xb\x0\x1\x4\xf5\x1\x0\x0\x4\x14\x0"
"\x0\x0\x50\x4b\x5\x6\x0\x0\x0\x0\x3\x0\x3\x0\xe1\x0\x0\x0\xc3\x0\x0\x0\x0\x0";
static char const invalidZip[] = "1234567890asdqwetwezxvcbdhg322353tgfsd";
@@ -132,8 +134,7 @@ UNIT_TEST(ZipFilesList)
TEST(false, ("This test shouldn't be reached - exception should be thrown"));
}
catch (exception const &)
{
}
{}
FileWriter::DeleteFileX(ZIPFILE_INVALID);
FileWriter::DeleteFileX(ZIPFILE);
@@ -142,26 +143,26 @@ UNIT_TEST(ZipFilesList)
/// Compressed zip file with 2 files in assets folder:
/// assets/aaaaaaaaaa.txt (contains text "aaaaaaaaaa\x0A")
/// assets/holalala.txt (contains text "Holalala\x0A")
static char const zipBytes3[] = \
"\x50\x4B\x03\x04\x14\x00\x02\x00\x08\x00\xAF\x96\x56\x40\x42\xE5\x26\x8F\x06\x00" \
"\x00\x00\x0B\x00\x00\x00\x15\x00\x1C\x00\x61\x73\x73\x65\x74\x73\x2F\x61\x61\x61" \
"\x61\x61\x61\x61\x61\x61\x61\x2E\x74\x78\x74\x55\x54\x09\x00\x03\x7A\x0F\x45\x4F" \
"\xD8\x0F\x45\x4F\x75\x78\x0B\x00\x01\x04\xF5\x01\x00\x00\x04\x14\x00\x00\x00\x4B" \
"\x4C\x84\x01\x2E\x00\x50\x4B\x03\x04\x14\x00\x02\x00\x08\x00\xE6\x96\x56\x40\x5E" \
"\x76\x90\x07\x08\x00\x00\x00\x09\x00\x00\x00\x13\x00\x1C\x00\x61\x73\x73\x65\x74" \
"\x73\x2F\x68\x6F\x6C\x61\x6C\x61\x6C\x61\x2E\x74\x78\x74\x55\x54\x09\x00\x03\xDF" \
"\x0F\x45\x4F\xDC\x0F\x45\x4F\x75\x78\x0B\x00\x01\x04\xF5\x01\x00\x00\x04\x14\x00" \
"\x00\x00\xF3\xC8\xCF\x49\x04\x41\x2E\x00\x50\x4B\x01\x02\x1E\x03\x14\x00\x02\x00" \
"\x08\x00\xAF\x96\x56\x40\x42\xE5\x26\x8F\x06\x00\x00\x00\x0B\x00\x00\x00\x15\x00" \
"\x18\x00\x00\x00\x00\x00\x01\x00\x00\x00\xA4\x81\x00\x00\x00\x00\x61\x73\x73\x65" \
"\x74\x73\x2F\x61\x61\x61\x61\x61\x61\x61\x61\x61\x61\x2E\x74\x78\x74\x55\x54\x05" \
"\x00\x03\x7A\x0F\x45\x4F\x75\x78\x0B\x00\x01\x04\xF5\x01\x00\x00\x04\x14\x00\x00" \
"\x00\x50\x4B\x01\x02\x1E\x03\x14\x00\x02\x00\x08\x00\xE6\x96\x56\x40\x5E\x76\x90" \
"\x07\x08\x00\x00\x00\x09\x00\x00\x00\x13\x00\x18\x00\x00\x00\x00\x00\x01\x00\x00" \
"\x00\xA4\x81\x55\x00\x00\x00\x61\x73\x73\x65\x74\x73\x2F\x68\x6F\x6C\x61\x6C\x61" \
"\x6C\x61\x2E\x74\x78\x74\x55\x54\x05\x00\x03\xDF\x0F\x45\x4F\x75\x78\x0B\x00\x01" \
"\x04\xF5\x01\x00\x00\x04\x14\x00\x00\x00\x50\x4B\x05\x06\x00\x00\x00\x00\x02\x00" \
"\x02\x00\xB4\x00\x00\x00\xAA\x00\x00\x00\x00\x00";
static char const zipBytes3[] =
"\x50\x4B\x03\x04\x14\x00\x02\x00\x08\x00\xAF\x96\x56\x40\x42\xE5\x26\x8F\x06\x00"
"\x00\x00\x0B\x00\x00\x00\x15\x00\x1C\x00\x61\x73\x73\x65\x74\x73\x2F\x61\x61\x61"
"\x61\x61\x61\x61\x61\x61\x61\x2E\x74\x78\x74\x55\x54\x09\x00\x03\x7A\x0F\x45\x4F"
"\xD8\x0F\x45\x4F\x75\x78\x0B\x00\x01\x04\xF5\x01\x00\x00\x04\x14\x00\x00\x00\x4B"
"\x4C\x84\x01\x2E\x00\x50\x4B\x03\x04\x14\x00\x02\x00\x08\x00\xE6\x96\x56\x40\x5E"
"\x76\x90\x07\x08\x00\x00\x00\x09\x00\x00\x00\x13\x00\x1C\x00\x61\x73\x73\x65\x74"
"\x73\x2F\x68\x6F\x6C\x61\x6C\x61\x6C\x61\x2E\x74\x78\x74\x55\x54\x09\x00\x03\xDF"
"\x0F\x45\x4F\xDC\x0F\x45\x4F\x75\x78\x0B\x00\x01\x04\xF5\x01\x00\x00\x04\x14\x00"
"\x00\x00\xF3\xC8\xCF\x49\x04\x41\x2E\x00\x50\x4B\x01\x02\x1E\x03\x14\x00\x02\x00"
"\x08\x00\xAF\x96\x56\x40\x42\xE5\x26\x8F\x06\x00\x00\x00\x0B\x00\x00\x00\x15\x00"
"\x18\x00\x00\x00\x00\x00\x01\x00\x00\x00\xA4\x81\x00\x00\x00\x00\x61\x73\x73\x65"
"\x74\x73\x2F\x61\x61\x61\x61\x61\x61\x61\x61\x61\x61\x2E\x74\x78\x74\x55\x54\x05"
"\x00\x03\x7A\x0F\x45\x4F\x75\x78\x0B\x00\x01\x04\xF5\x01\x00\x00\x04\x14\x00\x00"
"\x00\x50\x4B\x01\x02\x1E\x03\x14\x00\x02\x00\x08\x00\xE6\x96\x56\x40\x5E\x76\x90"
"\x07\x08\x00\x00\x00\x09\x00\x00\x00\x13\x00\x18\x00\x00\x00\x00\x00\x01\x00\x00"
"\x00\xA4\x81\x55\x00\x00\x00\x61\x73\x73\x65\x74\x73\x2F\x68\x6F\x6C\x61\x6C\x61"
"\x6C\x61\x2E\x74\x78\x74\x55\x54\x05\x00\x03\xDF\x0F\x45\x4F\x75\x78\x0B\x00\x01"
"\x04\xF5\x01\x00\x00\x04\x14\x00\x00\x00\x50\x4B\x05\x06\x00\x00\x00\x00\x02\x00"
"\x02\x00\xB4\x00\x00\x00\xAA\x00\x00\x00\x00\x00";
UNIT_TEST(ZipExtract)
{

View File

@@ -19,11 +19,10 @@ using namespace std;
using Deflate = ZLib::Deflate;
using Inflate = ZLib::Inflate;
pair<Deflate::Format, Inflate::Format> const g_combinations[] = {
{Deflate::Format::ZLib, Inflate::Format::ZLib},
{Deflate::Format::ZLib, Inflate::Format::Both},
{Deflate::Format::GZip, Inflate::Format::GZip},
{Deflate::Format::GZip, Inflate::Format::Both}};
pair<Deflate::Format, Inflate::Format> const g_combinations[] = {{Deflate::Format::ZLib, Inflate::Format::ZLib},
{Deflate::Format::ZLib, Inflate::Format::Both},
{Deflate::Format::GZip, Inflate::Format::GZip},
{Deflate::Format::GZip, Inflate::Format::Both}};
namespace
{
@@ -75,10 +74,9 @@ UNIT_TEST(GZip_ForeignData)
// To get this array of bytes, type following:
//
// echo -n 'Hello World!' | gzip -c | od -t x1
uint8_t const data[] = {0x1f, 0x8b, 0x08, 0x08, 0x6d, 0x55, 0x08, 0x59, 0x00, 0x03, 0x73,
0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x74, 0x78, 0x74, 0x00, 0xf3,
0x48, 0xcd, 0xc9, 0xc9, 0xd7, 0x51, 0x08, 0xcf, 0x2f, 0xca, 0x49,
0x51, 0x04, 0x00, 0xd0, 0xc3, 0x4a, 0xec, 0x0d, 0x00, 0x00, 0x00};
uint8_t const data[] = {0x1f, 0x8b, 0x08, 0x08, 0x6d, 0x55, 0x08, 0x59, 0x00, 0x03, 0x73, 0x61, 0x6d, 0x70, 0x6c,
0x65, 0x2e, 0x74, 0x78, 0x74, 0x00, 0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0xd7, 0x51, 0x08, 0xcf,
0x2f, 0xca, 0x49, 0x51, 0x04, 0x00, 0xd0, 0xc3, 0x4a, 0xec, 0x0d, 0x00, 0x00, 0x00};
string s;
@@ -90,11 +88,9 @@ UNIT_TEST(GZip_ForeignData)
UNIT_TEST(GZip_ExtraDataInBuffer)
{
// Data from GZip_ForeignData + extra \n at the end of the buffer.
uint8_t const data[] = {0x1f, 0x8b, 0x08, 0x08, 0x6d, 0x55, 0x08, 0x59, 0x00, 0x03, 0x73,
0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x74, 0x78, 0x74, 0x00, 0xf3,
0x48, 0xcd, 0xc9, 0xc9, 0xd7, 0x51, 0x08, 0xcf, 0x2f, 0xca, 0x49,
0x51, 0x04, 0x00, 0xd0, 0xc3, 0x4a, 0xec, 0x0d, 0x00, 0x00, 0x00,
0x0a};
uint8_t const data[] = {0x1f, 0x8b, 0x08, 0x08, 0x6d, 0x55, 0x08, 0x59, 0x00, 0x03, 0x73, 0x61, 0x6d, 0x70, 0x6c,
0x65, 0x2e, 0x74, 0x78, 0x74, 0x00, 0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0xd7, 0x51, 0x08, 0xcf,
0x2f, 0xca, 0x49, 0x51, 0x04, 0x00, 0xd0, 0xc3, 0x4a, 0xec, 0x0d, 0x00, 0x00, 0x00, 0x0a};
string s;

View File

@@ -17,8 +17,7 @@ struct IntersectOp
{
IntersectOp() {}
unique_ptr<coding::CompressedBitVector> operator()(coding::DenseCBV const & a,
coding::DenseCBV const & b) const
unique_ptr<coding::CompressedBitVector> operator()(coding::DenseCBV const & a, coding::DenseCBV const & b) const
{
size_t const sizeA = a.NumBitGroups();
size_t const sizeB = b.NumBitGroups();
@@ -29,8 +28,7 @@ struct IntersectOp
}
// The intersection of dense and sparse is always sparse.
unique_ptr<coding::CompressedBitVector> operator()(coding::DenseCBV const & a,
coding::SparseCBV const & b) const
unique_ptr<coding::CompressedBitVector> operator()(coding::DenseCBV const & a, coding::SparseCBV const & b) const
{
vector<uint64_t> resPos;
for (size_t i = 0; i < b.PopCount(); ++i)
@@ -42,14 +40,12 @@ struct IntersectOp
return make_unique<coding::SparseCBV>(std::move(resPos));
}
unique_ptr<coding::CompressedBitVector> operator()(coding::SparseCBV const & a,
coding::DenseCBV const & b) const
unique_ptr<coding::CompressedBitVector> operator()(coding::SparseCBV const & a, coding::DenseCBV const & b) const
{
return operator()(b, a);
}
unique_ptr<coding::CompressedBitVector> operator()(coding::SparseCBV const & a,
coding::SparseCBV const & b) const
unique_ptr<coding::CompressedBitVector> operator()(coding::SparseCBV const & a, coding::SparseCBV const & b) const
{
vector<uint64_t> resPos;
set_intersection(a.Begin(), a.End(), b.Begin(), b.End(), back_inserter(resPos));
@@ -61,8 +57,7 @@ struct SubtractOp
{
SubtractOp() {}
unique_ptr<coding::CompressedBitVector> operator()(coding::DenseCBV const & a,
coding::DenseCBV const & b) const
unique_ptr<coding::CompressedBitVector> operator()(coding::DenseCBV const & a, coding::DenseCBV const & b) const
{
size_t const sizeA = a.NumBitGroups();
size_t const sizeB = b.NumBitGroups();
@@ -72,8 +67,7 @@ struct SubtractOp
return CompressedBitVectorBuilder::FromBitGroups(std::move(resGroups));
}
unique_ptr<coding::CompressedBitVector> operator()(coding::DenseCBV const & a,
coding::SparseCBV const & b) const
unique_ptr<coding::CompressedBitVector> operator()(coding::DenseCBV const & a, coding::SparseCBV const & b) const
{
vector<uint64_t> resGroups(a.NumBitGroups());
@@ -100,19 +94,14 @@ struct SubtractOp
return CompressedBitVectorBuilder::FromBitGroups(std::move(resGroups));
}
unique_ptr<coding::CompressedBitVector> operator()(coding::SparseCBV const & a,
coding::DenseCBV const & b) const
unique_ptr<coding::CompressedBitVector> operator()(coding::SparseCBV const & a, coding::DenseCBV const & b) const
{
vector<uint64_t> resPos;
copy_if(a.Begin(), a.End(), back_inserter(resPos), [&](uint64_t bit)
{
return !b.GetBit(bit);
});
copy_if(a.Begin(), a.End(), back_inserter(resPos), [&](uint64_t bit) { return !b.GetBit(bit); });
return CompressedBitVectorBuilder::FromBitPositions(std::move(resPos));
}
unique_ptr<coding::CompressedBitVector> operator()(coding::SparseCBV const & a,
coding::SparseCBV const & b) const
unique_ptr<coding::CompressedBitVector> operator()(coding::SparseCBV const & a, coding::SparseCBV const & b) const
{
vector<uint64_t> resPos;
set_difference(a.Begin(), a.End(), b.Begin(), b.End(), back_inserter(resPos));
@@ -124,8 +113,7 @@ struct UnionOp
{
UnionOp() {}
unique_ptr<coding::CompressedBitVector> operator()(coding::DenseCBV const & a,
coding::DenseCBV const & b) const
unique_ptr<coding::CompressedBitVector> operator()(coding::DenseCBV const & a, coding::DenseCBV const & b) const
{
size_t const sizeA = a.NumBitGroups();
size_t const sizeB = b.NumBitGroups();
@@ -136,27 +124,22 @@ struct UnionOp
for (size_t i = 0; i < commonSize; ++i)
resGroups[i] = a.GetBitGroup(i) | b.GetBitGroup(i);
if (a.NumBitGroups() == resultSize)
{
for (size_t i = commonSize; i < resultSize; ++i)
resGroups[i] = a.GetBitGroup(i);
}
else
{
for (size_t i = commonSize; i < resultSize; ++i)
resGroups[i] = b.GetBitGroup(i);
}
return CompressedBitVectorBuilder::FromBitGroups(std::move(resGroups));
}
unique_ptr<coding::CompressedBitVector> operator()(coding::DenseCBV const & a,
coding::SparseCBV const & b) const
unique_ptr<coding::CompressedBitVector> operator()(coding::DenseCBV const & a, coding::SparseCBV const & b) const
{
size_t const sizeA = a.NumBitGroups();
size_t const sizeB =
b.PopCount() == 0 ? 0
: static_cast<size_t>((b.Select(static_cast<size_t>(b.PopCount() - 1)) +
DenseCBV::kBlockSize - 1) /
DenseCBV::kBlockSize);
b.PopCount() == 0
? 0
: static_cast<size_t>((b.Select(static_cast<size_t>(b.PopCount() - 1)) + DenseCBV::kBlockSize - 1) /
DenseCBV::kBlockSize);
if (sizeB > sizeA)
{
vector<uint64_t> resPos;
@@ -198,14 +181,12 @@ struct UnionOp
return CompressedBitVectorBuilder::FromBitGroups(std::move(resGroups));
}
unique_ptr<coding::CompressedBitVector> operator()(coding::SparseCBV const & a,
coding::DenseCBV const & b) const
unique_ptr<coding::CompressedBitVector> operator()(coding::SparseCBV const & a, coding::DenseCBV const & b) const
{
return operator()(b, a);
}
unique_ptr<coding::CompressedBitVector> operator()(coding::SparseCBV const & a,
coding::SparseCBV const & b) const
unique_ptr<coding::CompressedBitVector> operator()(coding::SparseCBV const & a, coding::SparseCBV const & b) const
{
vector<uint64_t> resPos;
set_union(a.Begin(), a.End(), b.Begin(), b.End(), back_inserter(resPos));
@@ -279,18 +260,13 @@ uint64_t const DenseCBV::kBlockSize;
DenseCBV::DenseCBV(vector<uint64_t> const & setBits)
{
if (setBits.empty())
{
return;
}
uint64_t const maxBit = *max_element(setBits.begin(), setBits.end());
size_t const sz = 1 + static_cast<size_t>(maxBit / kBlockSize);
m_bitGroups.resize(sz);
m_popCount = static_cast<uint64_t>(setBits.size());
for (uint64_t pos : setBits)
{
m_bitGroups[static_cast<size_t>(pos / kBlockSize)] |= static_cast<uint64_t>(1)
<< (pos % kBlockSize);
}
m_bitGroups[static_cast<size_t>(pos / kBlockSize)] |= static_cast<uint64_t>(1) << (pos % kBlockSize);
}
// static
@@ -309,7 +285,10 @@ uint64_t DenseCBV::GetBitGroup(size_t i) const
return i < m_bitGroups.size() ? m_bitGroups[i] : 0;
}
uint64_t DenseCBV::PopCount() const { return m_popCount; }
uint64_t DenseCBV::PopCount() const
{
return m_popCount;
}
bool DenseCBV::GetBit(uint64_t pos) const
{
@@ -383,7 +362,10 @@ uint64_t SparseCBV::Select(size_t i) const
return m_positions[i];
}
uint64_t SparseCBV::PopCount() const { return m_positions.size(); }
uint64_t SparseCBV::PopCount() const
{
return m_positions.size();
}
bool SparseCBV::GetBit(uint64_t pos) const
{
@@ -418,22 +400,19 @@ unique_ptr<CompressedBitVector> SparseCBV::Clone() const
}
// static
unique_ptr<CompressedBitVector> CompressedBitVectorBuilder::FromBitPositions(
vector<uint64_t> const & setBits)
unique_ptr<CompressedBitVector> CompressedBitVectorBuilder::FromBitPositions(vector<uint64_t> const & setBits)
{
return BuildFromBitPositions(setBits);
}
// static
unique_ptr<CompressedBitVector> CompressedBitVectorBuilder::FromBitPositions(
vector<uint64_t> && setBits)
unique_ptr<CompressedBitVector> CompressedBitVectorBuilder::FromBitPositions(vector<uint64_t> && setBits)
{
return BuildFromBitPositions(std::move(setBits));
}
// static
unique_ptr<CompressedBitVector> CompressedBitVectorBuilder::FromBitGroups(
vector<uint64_t> && bitGroups)
unique_ptr<CompressedBitVector> CompressedBitVectorBuilder::FromBitGroups(vector<uint64_t> && bitGroups)
{
static uint64_t const kBlockSize = DenseCBV::kBlockSize;
@@ -454,10 +433,8 @@ unique_ptr<CompressedBitVector> CompressedBitVectorBuilder::FromBitGroups(
for (size_t i = 0; i < bitGroups.size(); ++i)
{
for (size_t j = 0; j < kBlockSize; ++j)
{
if (((bitGroups[i] >> j) & 1) > 0)
setBits.push_back(kBlockSize * i + j);
}
}
return make_unique<SparseCBV>(setBits);
}

View File

@@ -48,8 +48,7 @@ public:
CompressedBitVector const & rhs);
// Unites two bit vectors.
static std::unique_ptr<CompressedBitVector> Union(CompressedBitVector const & lhs,
CompressedBitVector const & rhs);
static std::unique_ptr<CompressedBitVector> Union(CompressedBitVector const & lhs, CompressedBitVector const & rhs);
static bool IsEmpty(std::unique_ptr<CompressedBitVector> const & cbv);
@@ -156,10 +155,8 @@ public:
{
base::ControlFlowWrapper<Fn> wrapper(std::forward<Fn>(f));
for (auto const & position : m_positions)
{
if (wrapper(position) == base::ControlFlow::Break)
return;
}
}
// CompressedBitVector overrides:
@@ -183,8 +180,7 @@ class CompressedBitVectorBuilder
public:
// Chooses a strategy to store the bit vector with bits from setBits set to one
// and returns a pointer to a class that fits best.
static std::unique_ptr<CompressedBitVector> FromBitPositions(
std::vector<uint64_t> const & setBits);
static std::unique_ptr<CompressedBitVector> FromBitPositions(std::vector<uint64_t> const & setBits);
static std::unique_ptr<CompressedBitVector> FromBitPositions(std::vector<uint64_t> && setBits);
// Chooses a strategy to store the bit vector with bits from a bitmap obtained
@@ -207,8 +203,7 @@ public:
static std::unique_ptr<CompressedBitVector> DeserializeFromSource(TSource & src)
{
uint8_t header = ReadPrimitiveFromSource<uint8_t>(src);
CompressedBitVector::StorageStrategy strat =
static_cast<CompressedBitVector::StorageStrategy>(header);
CompressedBitVector::StorageStrategy strat = static_cast<CompressedBitVector::StorageStrategy>(header);
switch (strat)
{
case CompressedBitVector::StorageStrategy::Dense:
@@ -263,10 +258,7 @@ public:
{
static constexpr uint64_t kBase = 127;
uint64_t hash = 0;
CompressedBitVectorEnumerator::ForEach(cbv, [&hash](uint64_t i)
{
hash = hash * kBase + i + 1;
});
CompressedBitVectorEnumerator::ForEach(cbv, [&hash](uint64_t i) { hash = hash * kBase + i + 1; });
return hash;
}
};

View File

@@ -1,4 +1,4 @@
#pragma once
static const size_t READ_FILE_BUFFER_SIZE = 512 * 1024;
static const unsigned int ZIP_FILE_BUFFER_SIZE = 64 * 1024;
static size_t const READ_FILE_BUFFER_SIZE = 512 * 1024;
static unsigned int const ZIP_FILE_BUFFER_SIZE = 64 * 1024;

View File

@@ -6,7 +6,9 @@
namespace coding
{
CSVReader::CSVReader(std::unique_ptr<ReaderInterface> reader, bool hasHeader, char delimiter)
: m_reader(std::move(reader)), m_hasHeader(hasHeader), m_delimiter(delimiter)
: m_reader(std::move(reader))
, m_hasHeader(hasHeader)
, m_delimiter(delimiter)
{
if (!HasHeader())
return;
@@ -18,31 +20,35 @@ CSVReader::CSVReader(std::unique_ptr<ReaderInterface> reader, bool hasHeader, ch
CSVReader::CSVReader(std::string const & filename, bool hasHeader, char delimiter)
: CSVReader(std::make_unique<DefaultReader>(filename), hasHeader, delimiter)
{
}
{}
CSVReader::CSVReader(std::istream & stream, bool hasHeader, char delimiter)
: CSVReader(std::make_unique<IstreamWrapper>(stream), hasHeader, delimiter)
{
}
{}
CSVReader::CSVReader(Reader const & reader, bool hasHeader, char delimiter)
: CSVReader(std::make_unique<ReaderWrapper>(reader), hasHeader, delimiter)
{}
bool CSVReader::HasHeader() const
{
return m_hasHeader;
}
bool CSVReader::HasHeader() const { return m_hasHeader; }
char CSVReader::GetDelimiter() const
{
return m_delimiter;
}
char CSVReader::GetDelimiter() const { return m_delimiter; }
CSVReader::Row const & CSVReader::GetHeader() const { return m_header; }
CSVReader::Row const & CSVReader::GetHeader() const
{
return m_header;
}
CSVReader::Rows CSVReader::ReadAll()
{
Rows file;
ForEachRow([&](auto const & row) {
file.emplace_back(row);
});
ForEachRow([&](auto const & row) { file.emplace_back(row); });
return file;
}
@@ -58,7 +64,10 @@ std::optional<CSVReader::Row> CSVReader::ReadRow()
return row;
}
size_t CSVReader::GetCurrentLineNumber() const { return m_currentLine; }
size_t CSVReader::GetCurrentLineNumber() const
{
return m_currentLine;
}
CSVReader::IstreamWrapper::IstreamWrapper(std::istream & stream) : m_stream(stream) {}
@@ -91,8 +100,7 @@ std::optional<std::string> CSVReader::ReaderWrapper::ReadLine()
return std::string(std::begin(line), end);
}
CSVReader::DefaultReader::DefaultReader(std::string const & filename)
: m_stream(filename)
CSVReader::DefaultReader::DefaultReader(std::string const & filename) : m_stream(filename)
{
if (!m_stream)
LOG(LERROR, ("Can't open file ", filename));
@@ -111,10 +119,7 @@ CSVRunner::Iterator::Iterator(CSVReader & reader, bool isEnd) : m_reader(reader)
m_current = m_reader.ReadRow();
}
CSVRunner::Iterator::Iterator(Iterator const & other)
: m_reader(other.m_reader), m_current(other.m_current)
{
}
CSVRunner::Iterator::Iterator(Iterator const & other) : m_reader(other.m_reader), m_current(other.m_current) {}
CSVRunner::Iterator & CSVRunner::Iterator::operator++()
{
@@ -131,17 +136,28 @@ CSVRunner::Iterator CSVRunner::Iterator::operator++(int)
bool CSVRunner::Iterator::operator==(Iterator const & other) const
{
return &m_reader == &other.m_reader &&
static_cast<bool>(m_current) == static_cast<bool>(other.m_current);
return &m_reader == &other.m_reader && static_cast<bool>(m_current) == static_cast<bool>(other.m_current);
}
bool CSVRunner::Iterator::operator!=(Iterator const & other) const { return !(*this == other); }
bool CSVRunner::Iterator::operator!=(Iterator const & other) const
{
return !(*this == other);
}
CSVReader::Row & CSVRunner::Iterator::operator*() { return *m_current; }
CSVReader::Row & CSVRunner::Iterator::operator*()
{
return *m_current;
}
CSVRunner::CSVRunner(CSVReader && reader) : m_reader(std::move(reader)) {}
CSVRunner::Iterator CSVRunner::begin() { return Iterator(m_reader); }
CSVRunner::Iterator CSVRunner::begin()
{
return Iterator(m_reader);
}
CSVRunner::Iterator CSVRunner::end() { return Iterator(m_reader, true /* isEnd */); }
CSVRunner::Iterator CSVRunner::end()
{
return Iterator(m_reader, true /* isEnd */);
}
} // namespace coding

View File

@@ -23,10 +23,7 @@ public:
DDVector() : m_Size(0) {}
explicit DDVector(TReader const & reader) : m_reader(reader)
{
InitSize();
}
explicit DDVector(TReader const & reader) : m_reader(reader) { InitSize(); }
void Init(TReader const & reader)
{
@@ -34,35 +31,29 @@ public:
InitSize();
}
size_type size() const
{
return m_Size;
}
size_type size() const { return m_Size; }
T const operator [] (size_type i) const
T const operator[](size_type i) const
{
return ReadPrimitiveFromPos<T>(m_reader, static_cast<uint64_t>(i) * sizeof(T));
}
class const_iterator : public boost::iterator_facade<
const_iterator,
value_type const,
boost::random_access_traversal_tag,
value_type const &,
difference_type>
class const_iterator
: public boost::iterator_facade<const_iterator, value_type const, boost::random_access_traversal_tag,
value_type const &, difference_type>
{
public:
#ifdef DEBUG
const_iterator(ReaderType const * pReader, size_type i, size_type size)
: m_pReader(pReader), m_I(i), m_bValueRead(false), m_Size(size)
: m_pReader(pReader)
, m_I(i)
, m_bValueRead(false)
, m_Size(size)
{
ASSERT(static_cast<difference_type>(m_Size) >= 0, ());
}
#else
const_iterator(ReaderType const * pReader, size_type i)
: m_pReader(pReader), m_I(i), m_bValueRead(false)
{
}
const_iterator(ReaderType const * pReader, size_type i) : m_pReader(pReader), m_I(i), m_bValueRead(false) {}
#endif
T const & dereference() const
@@ -90,8 +81,7 @@ public:
ASSERT_LESS_OR_EQUAL(it.m_I, it.m_Size, (it.m_bValueRead));
ASSERT_EQUAL(m_Size, it.m_Size, (m_I, it.m_I, m_bValueRead, it.m_bValueRead));
ASSERT(m_pReader == it.m_pReader, (m_I, m_Size, it.m_I, it.m_Size));
return (static_cast<difference_type>(it.m_I) -
static_cast<difference_type>(m_I));
return (static_cast<difference_type>(it.m_I) - static_cast<difference_type>(m_I));
}
void increment()

View File

@@ -19,15 +19,17 @@ enum Operation
OPERATION_INSERT = 2,
};
template <class PatchWriterT, typename SizeT = uint64_t> class PatchCoder
template <class PatchWriterT, typename SizeT = uint64_t>
class PatchCoder
{
public:
typedef SizeT size_type;
explicit PatchCoder(PatchWriterT & patchWriter)
: m_LastOperation(OPERATION_COPY), m_LastOpCode(0), m_PatchWriter(patchWriter)
{
}
: m_LastOperation(OPERATION_COPY)
, m_LastOpCode(0)
, m_PatchWriter(patchWriter)
{}
void Delete(size_type n)
{
@@ -41,7 +43,8 @@ public:
Op(OPERATION_COPY, n);
}
template <typename TIter> void Insert(TIter it, size_type n)
template <typename TIter>
void Insert(TIter it, size_type n)
{
if (n != 0)
{
@@ -50,10 +53,7 @@ public:
}
}
void Finalize()
{
WriteLasOp();
}
void Finalize() { WriteLasOp(); }
private:
void Op(Operation op, size_type n)
@@ -85,15 +85,12 @@ private:
// Returns the length of the minimal patch, or -1 if no such patch found.
// Intermediate information is saved into tmpSink and can be used later to restore
// the resulting patch.
template <
typename TSignedWord, // Signed word, capable of storing position in text.
class TSrcVector, // Source data (A).
class TDstVector, // Destination data (B).
class TTmpFileSink // Sink to store temporary information.
>
TSignedWord DiffMyersSimple(TSrcVector const & A,
TDstVector const & B,
TSignedWord maxPatchSize,
template <typename TSignedWord, // Signed word, capable of storing position in text.
class TSrcVector, // Source data (A).
class TDstVector, // Destination data (B).
class TTmpFileSink // Sink to store temporary information.
>
TSignedWord DiffMyersSimple(TSrcVector const & A, TDstVector const & B, TSignedWord maxPatchSize,
TTmpFileSink & tmpSink)
{
ASSERT_GREATER(maxPatchSize, 0, ());
@@ -107,9 +104,7 @@ TSignedWord DiffMyersSimple(TSrcVector const & A,
x = V[maxPatchSize + k + 1];
else
x = V[maxPatchSize + k - 1] + 1;
while (x < static_cast<TSignedWord>(A.size()) &&
x - k < static_cast<TSignedWord>(B.size()) &&
A[x] == B[x - k])
while (x < static_cast<TSignedWord>(A.size()) && x - k < static_cast<TSignedWord>(B.size()) && A[x] == B[x - k])
++x;
V[maxPatchSize + k] = x;
if (x == static_cast<TSignedWord>(A.size()) && x - k == static_cast<TSignedWord>(B.size()))
@@ -126,16 +121,14 @@ class SimpleReplaceDiffer
{
public:
template <typename SrcIterT, typename DstIterT, class PatchCoderT>
void Diff(SrcIterT srcBeg, SrcIterT srcEnd,
DstIterT dstBeg, DstIterT dstEnd,
PatchCoderT & patchCoder)
void Diff(SrcIterT srcBeg, SrcIterT srcEnd, DstIterT dstBeg, DstIterT dstEnd, PatchCoderT & patchCoder)
{
typename PatchCoderT::size_type begCopy = 0;
for (; srcBeg != srcEnd && dstBeg != dstEnd && *srcBeg == *dstBeg; ++srcBeg, ++dstBeg)
++begCopy;
patchCoder.Copy(begCopy);
typename PatchCoderT::size_type endCopy = 0;
for (; srcBeg != srcEnd && dstBeg != dstEnd && *(srcEnd-1) == *(dstEnd-1); --srcEnd, --dstEnd)
for (; srcBeg != srcEnd && dstBeg != dstEnd && *(srcEnd - 1) == *(dstEnd - 1); --srcEnd, --dstEnd)
++endCopy;
patchCoder.Delete(srcEnd - srcBeg);
patchCoder.Insert(dstBeg, dstEnd - dstBeg);
@@ -152,13 +145,13 @@ template <class FineGrainedDiffT, class HasherT,
class RollingHashDiffer
{
public:
explicit RollingHashDiffer(size_t blockSize,
FineGrainedDiffT const & fineGrainedDiff = FineGrainedDiffT())
: m_FineGrainedDiff(fineGrainedDiff), m_BlockSize(blockSize) {}
explicit RollingHashDiffer(size_t blockSize, FineGrainedDiffT const & fineGrainedDiff = FineGrainedDiffT())
: m_FineGrainedDiff(fineGrainedDiff)
, m_BlockSize(blockSize)
{}
template <typename SrcIterT, typename DstIterT, class PatchCoderT>
void Diff(SrcIterT const srcBeg, SrcIterT const srcEnd,
DstIterT const dstBeg, DstIterT const dstEnd,
void Diff(SrcIterT const srcBeg, SrcIterT const srcEnd, DstIterT const dstBeg, DstIterT const dstEnd,
PatchCoderT & patchCoder)
{
if (srcEnd - srcBeg < static_cast<decltype(srcEnd - srcBeg)>(m_BlockSize) ||
@@ -169,8 +162,7 @@ public:
}
HasherT hasher;
HashPosMultiMapT srcHashes;
for (SrcIterT src = srcBeg; srcEnd - src >= static_cast<decltype(srcEnd - src)>(m_BlockSize);
src += m_BlockSize)
for (SrcIterT src = srcBeg; srcEnd - src >= static_cast<decltype(srcEnd - src)>(m_BlockSize); src += m_BlockSize)
srcHashes.insert(HashPosMultiMapValue(hasher.Init(src, m_BlockSize), src - srcBeg));
SrcIterT srcLastDiff = srcBeg;
DstIterT dst = dstBeg, dstNext = dstBeg + m_BlockSize, dstLastDiff = dstBeg;
@@ -183,15 +175,12 @@ public:
pos_type const srcLastDiffPos = srcLastDiff - srcBeg;
HashPosMultiMapIterator it = srcHashes.end();
for (HashPosMultiMapIterator i = iters.first; i != iters.second; ++i)
if (i->second >= srcLastDiffPos &&
(it == srcHashes.end() || i->second < it->second))
if (i->second >= srcLastDiffPos && (it == srcHashes.end() || i->second < it->second))
it = i;
if (it != srcHashes.end() &&
std::equal(srcBeg + it->second, srcBeg + it->second + m_BlockSize, dst))
if (it != srcHashes.end() && std::equal(srcBeg + it->second, srcBeg + it->second + m_BlockSize, dst))
{
pos_type srcBlockEqualPos = it->second;
m_FineGrainedDiff.Diff(srcLastDiff, srcBeg + srcBlockEqualPos,
dstLastDiff, dst, patchCoder);
m_FineGrainedDiff.Diff(srcLastDiff, srcBeg + srcBlockEqualPos, dstLastDiff, dst, patchCoder);
patchCoder.Copy(m_BlockSize);
srcLastDiff = srcBeg + srcBlockEqualPos + m_BlockSize;
dst = dstLastDiff = dstNext;
@@ -207,6 +196,7 @@ public:
if (srcLastDiff != srcEnd || dstLastDiff != dstEnd)
m_FineGrainedDiff.Diff(srcLastDiff, srcEnd, dstLastDiff, dstEnd, patchCoder);
}
private:
typedef typename HasherT::hash_type hash_type;
typedef typename HashPosMultiMapT::value_type::second_type pos_type;

View File

@@ -1,28 +1,29 @@
#include "coding/file_reader.hpp"
#include "coding/reader_cache.hpp"
#include "coding/internal/file_data.hpp"
#include "coding/reader_cache.hpp"
#include "base/logging.hpp"
#ifndef LOG_FILE_READER_STATS
#define LOG_FILE_READER_STATS 0
#endif // LOG_FILE_READER_STATS
#endif // LOG_FILE_READER_STATS
#if LOG_FILE_READER_STATS && !defined(LOG_FILE_READER_EVERY_N_READS_MASK)
#define LOG_FILE_READER_EVERY_N_READS_MASK 0xFFFFFFFF
#endif
// static
uint32_t const FileReader::kDefaultLogPageSize = 10; // page size is 2^10 = 1024 = 1kb
uint32_t const FileReader::kDefaultLogPageSize = 10; // page size is 2^10 = 1024 = 1kb
// static
uint32_t const FileReader::kDefaultLogPageCount = 4; // page count is 2^4 = 16, i.e. 16 pages are cached
uint32_t const FileReader::kDefaultLogPageCount = 4; // page count is 2^4 = 16, i.e. 16 pages are cached
class FileReader::FileReaderData
{
public:
FileReaderData(std::string const & fileName, uint32_t logPageSize, uint32_t logPageCount)
: m_fileData(fileName), m_readerCache(logPageSize, logPageCount)
: m_fileData(fileName)
, m_readerCache(logPageSize, logPageCount)
{
#if LOG_FILE_READER_STATS
m_readCallCount = 0;
@@ -42,9 +43,7 @@ public:
{
#if LOG_FILE_READER_STATS
if (((++m_readCallCount) & LOG_FILE_READER_EVERY_N_READS_MASK) == 0)
{
LOG(LINFO, ("FileReader", m_fileData.GetName(), m_readerCache.GetStatsStr()));
}
#endif
return m_readerCache.Read(m_fileData, pos, p, size);
@@ -55,9 +54,9 @@ private:
{
public:
explicit FileDataWithCachedSize(std::string const & fileName)
: base::FileData(fileName, Op::READ), m_Size(FileData::Size())
{
}
: base::FileData(fileName, Op::READ)
, m_Size(FileData::Size())
{}
uint64_t Size() const { return m_Size; }
@@ -73,10 +72,8 @@ private:
#endif
};
FileReader::FileReader(std::string const & fileName)
: FileReader(fileName, kDefaultLogPageSize, kDefaultLogPageCount)
{
}
FileReader::FileReader(std::string const & fileName) : FileReader(fileName, kDefaultLogPageSize, kDefaultLogPageCount)
{}
FileReader::FileReader(std::string const & fileName, uint32_t logPageSize, uint32_t logPageCount)
: ModelReader(fileName)
@@ -85,19 +82,17 @@ FileReader::FileReader(std::string const & fileName, uint32_t logPageSize, uint3
, m_fileData(std::make_shared<FileReaderData>(fileName, logPageSize, logPageCount))
, m_offset(0)
, m_size(m_fileData->Size())
{
}
{}
FileReader::FileReader(FileReader const & reader, uint64_t offset, uint64_t size,
uint32_t logPageSize, uint32_t logPageCount)
FileReader::FileReader(FileReader const & reader, uint64_t offset, uint64_t size, uint32_t logPageSize,
uint32_t logPageCount)
: ModelReader(reader.GetName())
, m_logPageSize(logPageSize)
, m_logPageCount(logPageCount)
, m_fileData(reader.m_fileData)
, m_offset(offset)
, m_size(size)
{
}
{}
void FileReader::Read(uint64_t pos, void * p, size_t size) const
{
@@ -115,8 +110,7 @@ std::unique_ptr<Reader> FileReader::CreateSubReader(uint64_t pos, uint64_t size)
{
CheckPosAndSize(pos, size);
// Can't use make_unique with private constructor.
return std::unique_ptr<Reader>(
new FileReader(*this, m_offset + pos, size, m_logPageSize, m_logPageCount));
return std::unique_ptr<Reader>(new FileReader(*this, m_offset + pos, size, m_logPageSize, m_logPageCount));
}
void FileReader::CheckPosAndSize(uint64_t pos, uint64_t size) const

View File

@@ -36,8 +36,7 @@ protected:
private:
class FileReaderData;
FileReader(FileReader const & reader, uint64_t offset, uint64_t size, uint32_t logPageSize,
uint32_t logPageCount);
FileReader(FileReader const & reader, uint64_t offset, uint64_t size, uint32_t logPageSize, uint32_t logPageCount);
// Throws an exception if a (pos, size) read would result in an out-of-bounds access.
void CheckPosAndSize(uint64_t pos, uint64_t size) const;

View File

@@ -4,8 +4,8 @@
#include "coding/file_writer.hpp"
#include "base/base.hpp"
#include "base/logging.hpp"
#include "base/exception.hpp"
#include "base/logging.hpp"
#include <algorithm>
#include <cstdlib>
@@ -22,7 +22,8 @@ struct Sorter
{
LessT m_Less;
Sorter(LessT lessF) : m_Less(lessF) {}
template <typename IterT> void operator() (IterT beg, IterT end) const
template <typename IterT>
void operator()(IterT beg, IterT end) const
{
std::sort(beg, end, m_Less);
}
@@ -36,8 +37,7 @@ template <typename T, // Item type.
class FileSorter
{
public:
FileSorter(size_t bufferBytes, std::string const & tmpFileName, OutputSinkT & outputSink,
LessT fLess = LessT())
FileSorter(size_t bufferBytes, std::string const & tmpFileName, OutputSinkT & outputSink, LessT fLess = LessT())
: m_TmpFileName(tmpFileName)
, m_BufferCapacity(std::max(size_t(16), bufferBytes / sizeof(T)))
, m_OutputSink(outputSink)
@@ -90,11 +90,11 @@ public:
{
SortAndFinish();
}
catch(RootException const & e)
catch (RootException const & e)
{
LOG(LERROR, (e.Msg()));
}
catch(std::exception const & e)
catch (std::exception const & e)
{
LOG(LERROR, (e.what()));
}
@@ -113,8 +113,7 @@ private:
};
using PriorityQueue =
std::priority_queue<std::pair<T, uint32_t>, std::vector<std::pair<T, uint32_t>>,
ItemIndexPairGreater>;
std::priority_queue<std::pair<T, uint32_t>, std::vector<std::pair<T, uint32_t>>, ItemIndexPairGreater>;
void FlushToTmpFile()
{

View File

@@ -5,8 +5,7 @@
FileWriter::FileWriter(std::string const & fileName, FileWriter::Op op)
: m_pFileData(std::make_unique<base::FileData>(fileName, static_cast<base::FileData::Op>(op)))
{
}
{}
FileWriter::~FileWriter() noexcept(false)
{

View File

@@ -1,8 +1,8 @@
#pragma once
#include "coding/writer.hpp"
#include "coding/internal/file_data.hpp"
#include "coding/write_to_sink.hpp"
#include "coding/writer.hpp"
#include "base/assert.hpp"
#include "base/macros.hpp"
@@ -34,8 +34,7 @@ public:
OP_APPEND = 3
};
explicit FileWriter(std::string const & fileName,
Op operation = OP_WRITE_TRUNCATE);
explicit FileWriter(std::string const & fileName, Op operation = OP_WRITE_TRUNCATE);
FileWriter(FileWriter && rhs) = default;
virtual ~FileWriter() noexcept(false);
@@ -59,10 +58,7 @@ protected:
class FilesContainerWriter : public FileWriter
{
public:
FilesContainerWriter(std::string const & fileName, Op operation)
: FileWriter(fileName, operation)
{
}
FilesContainerWriter(std::string const & fileName, Op operation) : FileWriter(fileName, operation) {}
void WritePaddingByEnd(size_t factor) { WritePadding(Size(), factor); }
void WritePaddingByPos(size_t factor) { WritePadding(Pos(), factor); }
@@ -83,8 +79,7 @@ class TruncatingFileWriter : public FilesContainerWriter
public:
explicit TruncatingFileWriter(std::string const & fileName)
: FilesContainerWriter(fileName, FileWriter::OP_WRITE_EXISTING)
{
}
{}
TruncatingFileWriter(TruncatingFileWriter && rhs) = default;

View File

@@ -9,17 +9,17 @@
#include <sstream>
#ifndef OMIM_OS_WINDOWS
#include <stdio.h>
#include <unistd.h> // _SC_PAGESIZE
#include <sys/mman.h>
#include <sys/stat.h>
#ifdef OMIM_OS_ANDROID
#include <fcntl.h>
#else
#include <sys/fcntl.h>
#endif
#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h> // _SC_PAGESIZE
#ifdef OMIM_OS_ANDROID
#include <fcntl.h>
#else
#include <windows.h>
#include <sys/fcntl.h>
#endif
#else
#include <windows.h>
#endif
#include <errno.h>
@@ -68,16 +68,13 @@ void FilesContainerBase::ReadInfo(Reader & reader)
// FilesContainerR
/////////////////////////////////////////////////////////////////////////////
FilesContainerR::FilesContainerR(std::string const & filePath,
uint32_t logPageSize,
uint32_t logPageCount)
FilesContainerR::FilesContainerR(std::string const & filePath, uint32_t logPageSize, uint32_t logPageCount)
: m_source(std::make_unique<FileReader>(filePath, logPageSize, logPageCount))
{
ReadInfo(m_source);
}
FilesContainerR::FilesContainerR(TReader const & file)
: m_source(file)
FilesContainerR::FilesContainerR(TReader const & file) : m_source(file)
{
ReadInfo(m_source);
}
@@ -120,7 +117,8 @@ void MappedFile::Open(std::string const & fName)
Close();
#ifdef OMIM_OS_WINDOWS
m_hFile = CreateFileA(fName.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
m_hFile = CreateFileA(fName.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
if (m_hFile == INVALID_HANDLE_VALUE)
MYTHROW(Reader::OpenException, ("Can't open file:", fName, "win last error:", GetLastError()));
m_hMapping = CreateFileMappingA(m_hFile, NULL, PAGE_READONLY, 0, 0, NULL);
@@ -131,14 +129,9 @@ void MappedFile::Open(std::string const & fName)
if (m_fd == -1)
{
if (errno == EMFILE || errno == ENFILE)
{
MYTHROW(Reader::TooManyFilesException,
("Can't open file:", fName, ", reason:", strerror(errno)));
}
MYTHROW(Reader::TooManyFilesException, ("Can't open file:", fName, ", reason:", strerror(errno)));
else
{
MYTHROW(Reader::OpenException, ("Can't open file:", fName, ", reason:", strerror(errno)));
}
}
#endif
}
@@ -182,14 +175,16 @@ MappedFile::Handle MappedFile::Map(uint64_t offset, uint64_t size, std::string c
ASSERT_GREATER_OR_EQUAL(length, size, ());
#ifdef OMIM_OS_WINDOWS
void * pMap = MapViewOfFile(m_hMapping, FILE_MAP_READ, alignedOffset >> (sizeof(DWORD) * 8), DWORD(alignedOffset), length);
void * pMap =
MapViewOfFile(m_hMapping, FILE_MAP_READ, alignedOffset >> (sizeof(DWORD) * 8), DWORD(alignedOffset), length);
if (pMap == NULL)
MYTHROW(Reader::OpenException, ("Can't map section:", tag, "with [offset, size]:", offset, size, "win last error:", GetLastError()));
MYTHROW(Reader::OpenException,
("Can't map section:", tag, "with [offset, size]:", offset, size, "win last error:", GetLastError()));
#else
void * pMap = mmap(0, static_cast<size_t>(length), PROT_READ, MAP_SHARED, m_fd,
static_cast<off_t>(alignedOffset));
void * pMap = mmap(0, static_cast<size_t>(length), PROT_READ, MAP_SHARED, m_fd, static_cast<off_t>(alignedOffset));
if (pMap == MAP_FAILED)
MYTHROW(Reader::OpenException, ("Can't map section:", tag, "with [offset, size]:", offset, size, "errno:", strerror(errno)));
MYTHROW(Reader::OpenException,
("Can't map section:", tag, "with [offset, size]:", offset, size, "errno:", strerror(errno)));
#endif
char const * data = reinterpret_cast<char const *>(pMap);
@@ -197,7 +192,7 @@ MappedFile::Handle MappedFile::Map(uint64_t offset, uint64_t size, std::string c
return Handle(d, data, size, length);
}
} // namespace detail
} // namespace detail
/////////////////////////////////////////////////////////////////////////////
// FilesMappingContainer
@@ -275,11 +270,11 @@ void FilesMappingContainer::Handle::Unmap()
{
if (IsValid())
{
#ifdef OMIM_OS_WINDOWS
VERIFY(UnmapViewOfFile(m_origBase), ());
#else
VERIFY(0 == munmap((void *)m_origBase, static_cast<size_t>(m_origSize)), ());
#endif
#ifdef OMIM_OS_WINDOWS
VERIFY(UnmapViewOfFile(m_origBase), ());
#else
VERIFY(0 == munmap((void *)m_origBase, static_cast<size_t>(m_origSize)), ());
#endif
Reset();
}
}
@@ -294,8 +289,7 @@ void FilesMappingContainer::Handle::Reset()
// FilesContainerW
/////////////////////////////////////////////////////////////////////////////
FilesContainerW::FilesContainerW(std::string const & fName, FileWriter::Op op)
: m_name(fName), m_finished(false)
FilesContainerW::FilesContainerW(std::string const & fName, FileWriter::Op op) : m_name(fName), m_finished(false)
{
Open(op);
}
@@ -306,15 +300,14 @@ void FilesContainerW::Open(FileWriter::Op op)
switch (op)
{
case FileWriter::OP_WRITE_TRUNCATE:
break;
case FileWriter::OP_WRITE_TRUNCATE: break;
case FileWriter::OP_WRITE_EXISTING:
{
// read an existing service info
FileReader reader(m_name);
ReadInfo(reader);
}
{
// read an existing service info
FileReader reader(m_name);
ReadInfo(reader);
}
// Important: in append mode we should sort info-vector by offsets
sort(m_info.begin(), m_info.end(), LessOffset());
@@ -322,15 +315,11 @@ void FilesContainerW::Open(FileWriter::Op op)
// Check that all offsets are unique
#ifdef DEBUG
for (size_t i = 1; i < m_info.size(); ++i)
ASSERT(m_info[i-1].m_offset < m_info[i].m_offset ||
m_info[i-1].m_size == 0 ||
m_info[i].m_size == 0, ());
ASSERT(m_info[i - 1].m_offset < m_info[i].m_offset || m_info[i - 1].m_size == 0 || m_info[i].m_size == 0, ());
#endif
break;
default:
ASSERT ( false, ("Unsupported options") );
break;
default: ASSERT(false, ("Unsupported options")); break;
}
if (m_info.empty())
@@ -369,10 +358,8 @@ void FilesContainerW::DeleteSection(Tag const & tag)
FilesContainerW contW(m_name + ".tmp");
for (size_t i = 0; i < m_info.size(); ++i)
{
if (m_info[i].m_tag != tag)
contW.Write(contR.GetReader(m_info[i].m_tag), m_info[i].m_tag);
}
}
// swap files
@@ -390,7 +377,7 @@ std::unique_ptr<FilesContainerWriter> FilesContainerW::GetWriter(Tag const & tag
InfoContainer::const_iterator it = find_if(m_info.begin(), m_info.end(), EqualTag(tag));
if (it != m_info.end())
{
if (it+1 == m_info.end())
if (it + 1 == m_info.end())
{
m_info.pop_back();

View File

@@ -36,10 +36,7 @@ public:
/// WARNING! Existing sections may not be properly aligned.
static uint64_t const kSectionAlignment = 8;
bool IsExist(Tag const & tag) const
{
return GetInfo(tag) != 0;
}
bool IsExist(Tag const & tag) const { return GetInfo(tag) != 0; }
template <typename ToDo>
void ForEachTagInfo(ToDo && toDo) const
@@ -50,23 +47,14 @@ public:
protected:
struct LessInfo
{
bool operator() (TagInfo const & t1, TagInfo const & t2) const
{
return (t1.m_tag < t2.m_tag);
}
bool operator() (TagInfo const & t1, Tag const & t2) const
{
return (t1.m_tag < t2);
}
bool operator() (Tag const & t1, TagInfo const & t2) const
{
return (t1 < t2.m_tag);
}
bool operator()(TagInfo const & t1, TagInfo const & t2) const { return (t1.m_tag < t2.m_tag); }
bool operator()(TagInfo const & t1, Tag const & t2) const { return (t1.m_tag < t2); }
bool operator()(Tag const & t1, TagInfo const & t2) const { return (t1 < t2.m_tag); }
};
struct LessOffset
{
bool operator() (TagInfo const & t1, TagInfo const & t2) const
bool operator()(TagInfo const & t1, TagInfo const & t2) const
{
if (t1.m_offset == t2.m_offset)
{
@@ -77,24 +65,15 @@ protected:
else
return (t1.m_offset < t2.m_offset);
}
bool operator() (TagInfo const & t1, uint64_t const & t2) const
{
return (t1.m_offset < t2);
}
bool operator() (uint64_t const & t1, TagInfo const & t2) const
{
return (t1 < t2.m_offset);
}
bool operator()(TagInfo const & t1, uint64_t const & t2) const { return (t1.m_offset < t2); }
bool operator()(uint64_t const & t1, TagInfo const & t2) const { return (t1 < t2.m_offset); }
};
class EqualTag
{
public:
EqualTag(Tag const & tag) : m_tag(tag) {}
bool operator() (TagInfo const & t) const
{
return (t.m_tag == m_tag);
}
bool operator()(TagInfo const & t) const { return (t.m_tag == m_tag); }
private:
Tag const & m_tag;
@@ -116,9 +95,7 @@ class FilesContainerR : public FilesContainerBase
public:
using TReader = ModelReaderPtr;
explicit FilesContainerR(std::string const & filePath,
uint32_t logPageSize = 10,
uint32_t logPageCount = 10);
explicit FilesContainerR(std::string const & filePath, uint32_t logPageSize = 10, uint32_t logPageCount = 10);
explicit FilesContainerR(TReader const & file);
TReader GetReader(Tag const & tag) const;
@@ -156,13 +133,19 @@ public:
Handle() = default;
Handle(char const * base, char const * alignBase, uint64_t size, uint64_t origSize)
: m_base(base), m_origBase(alignBase), m_size(size), m_origSize(origSize)
{
}
: m_base(base)
, m_origBase(alignBase)
, m_size(size)
, m_origSize(origSize)
{}
Handle(Handle && h) { Assign(std::move(h)); }
Handle & operator=(Handle && h) { Assign(std::move(h)); return *this; }
Handle & operator=(Handle && h)
{
Assign(std::move(h));
return *this;
}
~Handle();
@@ -210,7 +193,7 @@ private:
DISALLOW_COPY(MappedFile);
};
} // namespace detail
} // namespace detail
class FilesMappingContainer : public FilesContainerBase
{
@@ -239,8 +222,7 @@ private:
class FilesContainerW : public FilesContainerBase
{
public:
FilesContainerW(std::string const & fName,
FileWriter::Op op = FileWriter::OP_WRITE_TRUNCATE);
FilesContainerW(std::string const & fName, FileWriter::Op op = FileWriter::OP_WRITE_TRUNCATE);
~FilesContainerW();
std::unique_ptr<FilesContainerWriter> GetWriter(Tag const & tag);

View File

@@ -23,13 +23,11 @@
/// sorted by index parameter.
/// Component is stored and used in host's endianness, without any conversions.
template
<
size_t Bits, /// number of fixed bits
class TReader, /// reader with random offset read functions
typename TSize = uint32_t, /// vector index type (platform independent)
typename TValue = uint32_t /// vector value type (platform independent)
>
template <size_t Bits, /// number of fixed bits
class TReader, /// reader with random offset read functions
typename TSize = uint32_t, /// vector index type (platform independent)
typename TValue = uint32_t /// vector value type (platform independent)
>
class FixedBitsDDVector
{
static_assert(std::is_unsigned<TSize>::value, "");
@@ -56,10 +54,7 @@ class FixedBitsDDVector
using TBlock = uint32_t;
static uint64_t AlignBytesCount(uint64_t count)
{
return std::max(count, static_cast<uint64_t>(sizeof(TBlock)));
}
static uint64_t AlignBytesCount(uint64_t count) { return std::max(count, static_cast<uint64_t>(sizeof(TBlock))); }
static TBlock constexpr kMask = (1 << Bits) - 1;
static TBlock constexpr kLargeValue = kMask - 1;
@@ -75,11 +70,10 @@ class FixedBitsDDVector
FixedBitsDDVector(TReader const & bitsReader, TReader const & vecReader, TSize size)
: m_bits(bitsReader)
, m_vector(vecReader)
#ifdef DEBUG
#ifdef DEBUG
, m_size(size)
#endif
{
}
#endif
{}
public:
static std::unique_ptr<TSelf> Create(TReader const & reader)
@@ -90,8 +84,8 @@ public:
uint64_t const off2 = AlignBytesCount((size * Bits + CHAR_BIT - 1) / CHAR_BIT) + off1;
// We cannot use make_unique here because contsructor is private.
return std::unique_ptr<TSelf>(new TSelf(reader.SubReader(off1, off2 - off1),
reader.SubReader(off2, reader.Size() - off2), size));
return std::unique_ptr<TSelf>(
new TSelf(reader.SubReader(off1, off2 - off1), reader.SubReader(off2, reader.Size() - off2), size));
}
bool Get(TSize index, TValue & value) const
@@ -114,7 +108,8 @@ public:
return true;
}
template <class TWriter> class Builder
template <class TWriter>
class Builder
{
using TData = std::vector<uint8_t>;
using TempWriter = PushBackByteSink<TData>;
@@ -133,10 +128,7 @@ public:
public:
using ValueType = TValue;
explicit Builder(TWriter & writer)
: m_writer(m_data), m_bits(new TBits(m_writer)), m_finalWriter(writer)
{
}
explicit Builder(TWriter & writer) : m_writer(m_data), m_bits(new TBits(m_writer)), m_finalWriter(writer) {}
~Builder()
{

View File

@@ -14,8 +14,8 @@ namespace
inline m2::PointU ClampPoint(m2::PointD const & maxPoint, m2::PointD const & point)
{
using uvalue_t = m2::PointU::value_type;
return { static_cast<uvalue_t>(math::Clamp(point.x, 0.0, maxPoint.x)),
static_cast<uvalue_t>(math::Clamp(point.y, 0.0, maxPoint.y)) };
return {static_cast<uvalue_t>(math::Clamp(point.x, 0.0, maxPoint.x)),
static_cast<uvalue_t>(math::Clamp(point.y, 0.0, maxPoint.y))};
}
struct edge_less_p0
@@ -33,10 +33,10 @@ struct edge_less_p0
namespace coding
{
bool TestDecoding(InPointsT const & points, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutDeltasT const & deltas,
void (*fnDecode)(InDeltasT const & deltas, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutPointsT & points))
bool TestDecoding(InPointsT const & points, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutDeltasT const & deltas,
void (*fnDecode)(InDeltasT const & deltas, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutPointsT & points))
{
size_t const count = points.size();
@@ -51,17 +51,15 @@ bool TestDecoding(InPointsT const & points, m2::PointU const & basePoint,
return true;
}
m2::PointU PredictPointInPolyline(m2::PointD const & maxPoint, m2::PointU const & p1,
m2::PointU const & p2)
m2::PointU PredictPointInPolyline(m2::PointD const & maxPoint, m2::PointU const & p1, m2::PointU const & p2)
{
return ClampPoint(maxPoint, m2::PointD(p1) + (m2::PointD(p1) - m2::PointD(p2)) / 2.0);
}
uint64_t EncodePointDeltaAsUint(m2::PointU const & actual, m2::PointU const & prediction)
{
return bits::BitwiseMerge(
bits::ZigZagEncode(static_cast<int32_t>(actual.x) - static_cast<int32_t>(prediction.x)),
bits::ZigZagEncode(static_cast<int32_t>(actual.y) - static_cast<int32_t>(prediction.y)));
return bits::BitwiseMerge(bits::ZigZagEncode(static_cast<int32_t>(actual.x) - static_cast<int32_t>(prediction.x)),
bits::ZigZagEncode(static_cast<int32_t>(actual.y) - static_cast<int32_t>(prediction.y)));
}
m2::PointU DecodePointDeltaFromUint(uint64_t delta, m2::PointU const & prediction)
@@ -71,8 +69,8 @@ m2::PointU DecodePointDeltaFromUint(uint64_t delta, m2::PointU const & predictio
return m2::PointU(prediction.x + bits::ZigZagDecode(x), prediction.y + bits::ZigZagDecode(y));
}
m2::PointU PredictPointInPolyline(m2::PointD const & maxPoint, m2::PointU const & p1,
m2::PointU const & p2, m2::PointU const & p3)
m2::PointU PredictPointInPolyline(m2::PointD const & maxPoint, m2::PointU const & p1, m2::PointU const & p2,
m2::PointU const & p3)
{
CHECK_NOT_EQUAL(p2, p3, ());
@@ -93,18 +91,18 @@ m2::PointU PredictPointInPolyline(m2::PointD const & maxPoint, m2::PointU const
complex<double> const c0 = (c01 + c02) * complex<double>(0.5, 0.0);
*/
return ClampPoint(maxPoint, { c0.real(), c0.imag() });
return ClampPoint(maxPoint, {c0.real(), c0.imag()});
}
m2::PointU PredictPointInTriangle(m2::PointD const & maxPoint, m2::PointU const & p1,
m2::PointU const & p2, m2::PointU const & p3)
m2::PointU PredictPointInTriangle(m2::PointD const & maxPoint, m2::PointU const & p1, m2::PointU const & p2,
m2::PointU const & p3)
{
// parallelogram prediction
return ClampPoint(maxPoint, m2::PointD(p1 + p2) - m2::PointD(p3));
}
void EncodePolylinePrev1(InPointsT const & points, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutDeltasT & deltas)
void EncodePolylinePrev1(InPointsT const & points, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutDeltasT & deltas)
{
size_t const count = points.size();
if (count > 0)
@@ -117,8 +115,8 @@ void EncodePolylinePrev1(InPointsT const & points, m2::PointU const & basePoint,
ASSERT(TestDecoding(points, basePoint, maxPoint, deltas, &DecodePolylinePrev1), ());
}
void DecodePolylinePrev1(InDeltasT const & deltas, m2::PointU const & basePoint,
m2::PointU const & /*maxPoint*/, OutPointsT & points)
void DecodePolylinePrev1(InDeltasT const & deltas, m2::PointU const & basePoint, m2::PointU const & /*maxPoint*/,
OutPointsT & points)
{
size_t const count = deltas.size();
if (count > 0)
@@ -129,8 +127,8 @@ void DecodePolylinePrev1(InDeltasT const & deltas, m2::PointU const & basePoint,
}
}
void EncodePolylinePrev2(InPointsT const & points, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutDeltasT & deltas)
void EncodePolylinePrev2(InPointsT const & points, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutDeltasT & deltas)
{
size_t const count = points.size();
if (count > 0)
@@ -141,16 +139,16 @@ void EncodePolylinePrev2(InPointsT const & points, m2::PointU const & basePoint,
m2::PointD const maxPointD(maxPoint);
deltas.push_back(EncodePointDeltaAsUint(points[1], points[0]));
for (size_t i = 2; i < count; ++i)
deltas.push_back(EncodePointDeltaAsUint(
points[i], PredictPointInPolyline(maxPointD, points[i - 1], points[i - 2])));
deltas.push_back(
EncodePointDeltaAsUint(points[i], PredictPointInPolyline(maxPointD, points[i - 1], points[i - 2])));
}
}
ASSERT(TestDecoding(points, basePoint, maxPoint, deltas, &DecodePolylinePrev2), ());
}
void DecodePolylinePrev2(InDeltasT const & deltas, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutPointsT & points)
void DecodePolylinePrev2(InDeltasT const & deltas, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutPointsT & points)
{
size_t const count = deltas.size();
if (count > 0)
@@ -163,15 +161,15 @@ void DecodePolylinePrev2(InDeltasT const & deltas, m2::PointU const & basePoint,
for (size_t i = 2; i < count; ++i)
{
size_t const n = points.size();
points.push_back(DecodePointDeltaFromUint(
deltas[i], PredictPointInPolyline(maxPointD, points[n - 1], points[n - 2])));
points.push_back(
DecodePointDeltaFromUint(deltas[i], PredictPointInPolyline(maxPointD, points[n - 1], points[n - 2])));
}
}
}
}
void EncodePolylinePrev3(InPointsT const & points, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutDeltasT & deltas)
void EncodePolylinePrev3(InPointsT const & points, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutDeltasT & deltas)
{
ASSERT_LESS_OR_EQUAL(basePoint.x, maxPoint.x, (basePoint, maxPoint));
ASSERT_LESS_OR_EQUAL(basePoint.y, maxPoint.y, (basePoint, maxPoint));
@@ -190,8 +188,7 @@ void EncodePolylinePrev3(InPointsT const & points, m2::PointU const & basePoint,
deltas.push_back(EncodePointDeltaAsUint(points[2], prediction));
for (size_t i = 3; i < count; ++i)
{
m2::PointU const prediction = PredictPointInPolyline(
maxPointD, points[i - 1], points[i - 2], points[i - 3]);
m2::PointU const prediction = PredictPointInPolyline(maxPointD, points[i - 1], points[i - 2], points[i - 3]);
deltas.push_back(EncodePointDeltaAsUint(points[i], prediction));
}
}
@@ -201,8 +198,8 @@ void EncodePolylinePrev3(InPointsT const & points, m2::PointU const & basePoint,
ASSERT(TestDecoding(points, basePoint, maxPoint, deltas, &DecodePolylinePrev3), ());
}
void DecodePolylinePrev3(InDeltasT const & deltas, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutPointsT & points)
void DecodePolylinePrev3(InDeltasT const & deltas, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutPointsT & points)
{
ASSERT_LESS_OR_EQUAL(basePoint.x, maxPoint.x, (basePoint, maxPoint));
ASSERT_LESS_OR_EQUAL(basePoint.y, maxPoint.y, (basePoint, maxPoint));
@@ -218,13 +215,11 @@ void DecodePolylinePrev3(InDeltasT const & deltas, m2::PointU const & basePoint,
if (count > 2)
{
m2::PointD const maxPointD(maxPoint);
points.push_back(DecodePointDeltaFromUint(
deltas[2], PredictPointInPolyline(maxPointD, points.back(), pt0)));
points.push_back(DecodePointDeltaFromUint(deltas[2], PredictPointInPolyline(maxPointD, points.back(), pt0)));
for (size_t i = 3; i < count; ++i)
{
size_t const n = points.size();
m2::PointU const prediction = PredictPointInPolyline(
maxPointD, points[n - 1], points[n - 2], points[n - 3]);
m2::PointU const prediction = PredictPointInPolyline(maxPointD, points[n - 1], points[n - 2], points[n - 3]);
points.push_back(DecodePointDeltaFromUint(deltas[i], prediction));
}
}
@@ -232,20 +227,20 @@ void DecodePolylinePrev3(InDeltasT const & deltas, m2::PointU const & basePoint,
}
}
void EncodePolyline(InPointsT const & points, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutDeltasT & deltas)
void EncodePolyline(InPointsT const & points, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutDeltasT & deltas)
{
EncodePolylinePrev2(points, basePoint, maxPoint, deltas);
}
void DecodePolyline(InDeltasT const & deltas, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutPointsT & points)
void DecodePolyline(InDeltasT const & deltas, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutPointsT & points)
{
DecodePolylinePrev2(deltas, basePoint, maxPoint, points);
}
void EncodeTriangleStrip(InPointsT const & points, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutDeltasT & deltas)
void EncodeTriangleStrip(InPointsT const & points, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutDeltasT & deltas)
{
size_t const count = points.size();
if (count > 0)
@@ -259,15 +254,14 @@ void EncodeTriangleStrip(InPointsT const & points, m2::PointU const & basePoint,
m2::PointD const maxPointD(maxPoint);
for (size_t i = 3; i < count; ++i)
{
m2::PointU const prediction = PredictPointInTriangle(
maxPointD, points[i - 1], points[i - 2], points[i - 3]);
m2::PointU const prediction = PredictPointInTriangle(maxPointD, points[i - 1], points[i - 2], points[i - 3]);
deltas.push_back(EncodePointDeltaAsUint(points[i], prediction));
}
}
}
void DecodeTriangleStrip(InDeltasT const & deltas, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutPointsT & points)
void DecodeTriangleStrip(InDeltasT const & deltas, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutPointsT & points)
{
size_t const count = deltas.size();
if (count > 0)
@@ -282,8 +276,7 @@ void DecodeTriangleStrip(InDeltasT const & deltas, m2::PointU const & basePoint,
for (size_t i = 3; i < count; ++i)
{
size_t const n = points.size();
m2::PointU const prediction = PredictPointInTriangle(
maxPointD, points[n - 1], points[n - 2], points[n - 3]);
m2::PointU const prediction = PredictPointInTriangle(maxPointD, points[n - 1], points[n - 2], points[n - 3]);
points.push_back(DecodePointDeltaFromUint(deltas[i], prediction));
}
}
@@ -298,14 +291,14 @@ GeometryCodingParams::GeometryCodingParams() : m_BasePointUint64(0), m_CoordBits
m_BasePoint = Uint64ToPointUObsolete(m_BasePointUint64);
}
GeometryCodingParams::GeometryCodingParams(uint8_t coordBits, m2::PointD const & pt)
: m_CoordBits(coordBits)
GeometryCodingParams::GeometryCodingParams(uint8_t coordBits, m2::PointD const & pt) : m_CoordBits(coordBits)
{
SetBasePoint(pt);
}
GeometryCodingParams::GeometryCodingParams(uint8_t coordBits, uint64_t basePointUint64)
: m_BasePointUint64(basePointUint64), m_CoordBits(coordBits)
: m_BasePointUint64(basePointUint64)
, m_CoordBits(coordBits)
{
m_BasePoint = Uint64ToPointUObsolete(m_BasePointUint64);
}
@@ -318,7 +311,10 @@ void GeometryCodingParams::SetBasePoint(m2::PointD const & pt)
namespace pts
{
m2::PointU D2U(m2::PointD const & p, uint32_t coordBits) { return PointDToPointU(p, coordBits); }
m2::PointU D2U(m2::PointD const & p, uint32_t coordBits)
{
return PointDToPointU(p, coordBits);
}
m2::PointD U2D(m2::PointU const & p, uint32_t coordBits)
{
@@ -333,7 +329,10 @@ m2::PointU GetMaxPoint(GeometryCodingParams const & params)
return D2U(m2::PointD(mercator::Bounds::kMaxX, mercator::Bounds::kMaxY), params.GetCoordBits());
}
m2::PointU GetBasePoint(GeometryCodingParams const & params) { return params.GetBasePoint(); }
m2::PointU GetBasePoint(GeometryCodingParams const & params)
{
return params.GetBasePoint();
}
} // namespace pts
void Encode(EncodeFunT fn, std::vector<m2::PointD> const & points, GeometryCodingParams const & params,
@@ -354,8 +353,8 @@ void Encode(EncodeFunT fn, std::vector<m2::PointD> const & points, GeometryCodin
(*fn)(make_read_adapter(upoints), pts::GetBasePoint(params), pts::GetMaxPoint(params), adapt);
}
void Decode(DecodeFunT fn, DeltasT const & deltas, GeometryCodingParams const & params,
OutPointsT & points, size_t reserveF)
void Decode(DecodeFunT fn, DeltasT const & deltas, GeometryCodingParams const & params, OutPointsT & points,
size_t reserveF)
{
DecodeImpl(fn, deltas, params, points, reserveF);
}
@@ -366,13 +365,12 @@ void Decode(DecodeFunT fn, DeltasT const & deltas, GeometryCodingParams const &
DecodeImpl(fn, deltas, params, points, reserveF);
}
void const * LoadInner(DecodeFunT fn, void const * pBeg, size_t count,
GeometryCodingParams const & params, OutPointsT & points)
void const * LoadInner(DecodeFunT fn, void const * pBeg, size_t count, GeometryCodingParams const & params,
OutPointsT & points)
{
DeltasT deltas;
deltas.reserve(count);
void const * ret =
ReadVarUint64Array(static_cast<char const *>(pBeg), count, base::MakeBackInsertFunctor(deltas));
void const * ret = ReadVarUint64Array(static_cast<char const *>(pBeg), count, base::MakeBackInsertFunctor(deltas));
Decode(fn, deltas, params, points);
return ret;
@@ -450,8 +448,8 @@ void TrianglesChainSaver::operator()(TPoint arr[3], std::vector<TEdge> edges)
}
}
void DecodeTriangles(coding::InDeltasT const & deltas, m2::PointU const & basePoint,
m2::PointU const & maxPoint, coding::OutPointsT & points)
void DecodeTriangles(coding::InDeltasT const & deltas, m2::PointU const & basePoint, m2::PointU const & maxPoint,
coding::OutPointsT & points)
{
size_t const count = deltas.size();
ASSERT_GREATER(count, 2, ());
@@ -504,8 +502,8 @@ void DecodeTriangles(coding::InDeltasT const & deltas, m2::PointU const & basePo
// push points
points.push_back(points[trg[0]]);
points.push_back(points[trg[1]]);
points.push_back(coding::DecodePointDeltaFromUint(deltas[i] >> 2, coding::PredictPointInTriangle(
maxPointD, points[trg[0]], points[trg[1]], points[trg[2]])));
points.push_back(coding::DecodePointDeltaFromUint(
deltas[i] >> 2, coding::PredictPointInTriangle(maxPointD, points[trg[0]], points[trg[1]], points[trg[2]])));
// next step
treeBits = deltas[i] & 3;

View File

@@ -52,47 +52,46 @@ m2::PointU DecodePointDelta(Source & source, m2::PointU const & base)
}
/// Predict next point for polyline with given previous points (p1, p2).
m2::PointU PredictPointInPolyline(m2::PointD const & maxPoint, m2::PointU const & p1,
m2::PointU const & p2);
m2::PointU PredictPointInPolyline(m2::PointD const & maxPoint, m2::PointU const & p1, m2::PointU const & p2);
/// Predict next point for polyline with given previous points (p1, p2, p3).
m2::PointU PredictPointInPolyline(m2::PointD const & maxPoint, m2::PointU const & p1,
m2::PointU const & p2, m2::PointU const & p3);
m2::PointU PredictPointInPolyline(m2::PointD const & maxPoint, m2::PointU const & p1, m2::PointU const & p2,
m2::PointU const & p3);
/// Predict point for neighbour triangle with given
/// previous triangle (p1, p2, p3) and common edge (p1, p2).
m2::PointU PredictPointInTriangle(m2::PointD const & maxPoint, m2::PointU const & p1,
m2::PointU const & p2, m2::PointU const & p3);
m2::PointU PredictPointInTriangle(m2::PointD const & maxPoint, m2::PointU const & p1, m2::PointU const & p2,
m2::PointU const & p3);
void EncodePolylinePrev1(InPointsT const & points, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutDeltasT & deltas);
void EncodePolylinePrev1(InPointsT const & points, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutDeltasT & deltas);
void DecodePolylinePrev1(InDeltasT const & deltas, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutPointsT & points);
void DecodePolylinePrev1(InDeltasT const & deltas, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutPointsT & points);
void EncodePolylinePrev2(InPointsT const & points, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutDeltasT & deltas);
void EncodePolylinePrev2(InPointsT const & points, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutDeltasT & deltas);
void DecodePolylinePrev2(InDeltasT const & deltas, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutPointsT & points);
void DecodePolylinePrev2(InDeltasT const & deltas, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutPointsT & points);
void EncodePolylinePrev3(InPointsT const & points, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutDeltasT & deltas);
void EncodePolylinePrev3(InPointsT const & points, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutDeltasT & deltas);
void DecodePolylinePrev3(InDeltasT const & deltas, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutPointsT & points);
void DecodePolylinePrev3(InDeltasT const & deltas, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutPointsT & points);
void EncodePolyline(InPointsT const & points, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutDeltasT & deltas);
void EncodePolyline(InPointsT const & points, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutDeltasT & deltas);
void DecodePolyline(InDeltasT const & deltas, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutPointsT & points);
void DecodePolyline(InDeltasT const & deltas, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutPointsT & points);
void EncodeTriangleStrip(InPointsT const & points, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutDeltasT & deltas);
void EncodeTriangleStrip(InPointsT const & points, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutDeltasT & deltas);
void DecodeTriangleStrip(InDeltasT const & deltas, m2::PointU const & basePoint,
m2::PointU const & maxPoint, OutPointsT & points);
void DecodeTriangleStrip(InDeltasT const & deltas, m2::PointU const & basePoint, m2::PointU const & maxPoint,
OutPointsT & points);
} // namespace coding
namespace serial
@@ -147,26 +146,24 @@ m2::PointU GetBasePoint(GeometryCodingParams const & params);
} // namespace pts
/// @name Encode and Decode function types.
typedef void (*EncodeFunT)(coding::InPointsT const &, m2::PointU const &, m2::PointU const &,
coding::OutDeltasT &);
typedef void (*DecodeFunT)(coding::InDeltasT const &, m2::PointU const &, m2::PointU const &,
coding::OutPointsT &);
typedef void (*EncodeFunT)(coding::InPointsT const &, m2::PointU const &, m2::PointU const &, coding::OutDeltasT &);
typedef void (*DecodeFunT)(coding::InDeltasT const &, m2::PointU const &, m2::PointU const &, coding::OutPointsT &);
using DeltasT = buffer_vector<uint64_t, 32>;
using OutPointsT = buffer_vector<m2::PointD, 32>;
void Encode(EncodeFunT fn, std::vector<m2::PointD> const & points,
GeometryCodingParams const & params, DeltasT & deltas);
void Encode(EncodeFunT fn, std::vector<m2::PointD> const & points, GeometryCodingParams const & params,
DeltasT & deltas);
/// @name Overloads for different out container types.
void Decode(DecodeFunT fn, DeltasT const & deltas, GeometryCodingParams const & params,
OutPointsT & points, size_t reserveF = 1);
void Decode(DecodeFunT fn, DeltasT const & deltas, GeometryCodingParams const & params, OutPointsT & points,
size_t reserveF = 1);
void Decode(DecodeFunT fn, DeltasT const & deltas, GeometryCodingParams const & params,
std::vector<m2::PointD> & points, size_t reserveF = 1);
template <class TDecodeFun, class TOutPoints>
void DecodeImpl(TDecodeFun fn, DeltasT const & deltas, GeometryCodingParams const & params,
TOutPoints & points, size_t reserveF)
void DecodeImpl(TDecodeFun fn, DeltasT const & deltas, GeometryCodingParams const & params, TOutPoints & points,
size_t reserveF)
{
size_t const count = deltas.size() * reserveF;
@@ -189,22 +186,19 @@ void DecodeImpl(TDecodeFun fn, DeltasT const & deltas, GeometryCodingParams cons
template <class TSink>
void SavePoint(TSink & sink, m2::PointD const & pt, GeometryCodingParams const & cp)
{
WriteVarUint(sink, coding::EncodePointDeltaAsUint(PointDToPointU(pt, cp.GetCoordBits()),
cp.GetBasePoint()));
WriteVarUint(sink, coding::EncodePointDeltaAsUint(PointDToPointU(pt, cp.GetCoordBits()), cp.GetBasePoint()));
}
template <class TSource>
m2::PointD LoadPoint(TSource & src, GeometryCodingParams const & cp)
{
m2::PointD const pt = PointUToPointD(
coding::DecodePointDeltaFromUint(ReadVarUint<uint64_t>(src), cp.GetBasePoint()),
cp.GetCoordBits());
m2::PointD const pt = PointUToPointD(coding::DecodePointDeltaFromUint(ReadVarUint<uint64_t>(src), cp.GetBasePoint()),
cp.GetCoordBits());
return pt;
}
template <class TSink>
void SaveInner(EncodeFunT fn, std::vector<m2::PointD> const & points,
GeometryCodingParams const & params, TSink & sink)
void SaveInner(EncodeFunT fn, std::vector<m2::PointD> const & points, GeometryCodingParams const & params, TSink & sink)
{
DeltasT deltas;
Encode(fn, points, params, deltas);
@@ -220,8 +214,7 @@ void WriteBufferToSink(std::vector<char> const & buffer, TSink & sink)
}
template <class TSink>
void SaveOuter(EncodeFunT fn, std::vector<m2::PointD> const & points,
GeometryCodingParams const & params, TSink & sink)
void SaveOuter(EncodeFunT fn, std::vector<m2::PointD> const & points, GeometryCodingParams const & params, TSink & sink)
{
DeltasT deltas;
Encode(fn, points, params, deltas);
@@ -233,12 +226,11 @@ void SaveOuter(EncodeFunT fn, std::vector<m2::PointD> const & points,
WriteBufferToSink(buffer, sink);
}
void const * LoadInner(DecodeFunT fn, void const * pBeg, size_t count,
GeometryCodingParams const & params, OutPointsT & points);
void const * LoadInner(DecodeFunT fn, void const * pBeg, size_t count, GeometryCodingParams const & params,
OutPointsT & points);
template <class TSource, class TPoints>
void LoadOuter(DecodeFunT fn, TSource & src, GeometryCodingParams const & params, TPoints & points,
size_t reserveF = 1)
void LoadOuter(DecodeFunT fn, TSource & src, GeometryCodingParams const & params, TPoints & points, size_t reserveF = 1)
{
uint32_t const count = ReadVarUint<uint32_t>(src);
std::vector<char> buffer(count);
@@ -254,21 +246,19 @@ void LoadOuter(DecodeFunT fn, TSource & src, GeometryCodingParams const & params
/// @name Paths.
template <class TSink>
void SaveInnerPath(std::vector<m2::PointD> const & points, GeometryCodingParams const & params,
TSink & sink)
void SaveInnerPath(std::vector<m2::PointD> const & points, GeometryCodingParams const & params, TSink & sink)
{
SaveInner(&coding::EncodePolyline, points, params, sink);
}
template <class TSink>
void SaveOuterPath(std::vector<m2::PointD> const & points, GeometryCodingParams const & params,
TSink & sink)
void SaveOuterPath(std::vector<m2::PointD> const & points, GeometryCodingParams const & params, TSink & sink)
{
SaveOuter(&coding::EncodePolyline, points, params, sink);
}
inline void const * LoadInnerPath(void const * pBeg, size_t count,
GeometryCodingParams const & params, OutPointsT & points)
inline void const * LoadInnerPath(void const * pBeg, size_t count, GeometryCodingParams const & params,
OutPointsT & points)
{
return LoadInner(&coding::DecodePolyline, pBeg, count, params, points);
}
@@ -281,8 +271,7 @@ void LoadOuterPath(TSource & src, GeometryCodingParams const & params, TPoints &
/// @name Triangles.
template <class TSink>
void SaveInnerTriangles(std::vector<m2::PointD> const & points, GeometryCodingParams const & params,
TSink & sink)
void SaveInnerTriangles(std::vector<m2::PointD> const & points, GeometryCodingParams const & params, TSink & sink)
{
SaveInner(&coding::EncodeTriangleStrip, points, params, sink);
}
@@ -300,8 +289,8 @@ inline void StripToTriangles(size_t count, OutPointsT const & strip, OutPointsT
}
}
inline void const * LoadInnerTriangles(void const * pBeg, size_t count,
GeometryCodingParams const & params, OutPointsT & triangles)
inline void const * LoadInnerTriangles(void const * pBeg, size_t count, GeometryCodingParams const & params,
OutPointsT & triangles)
{
CHECK_GREATER_OR_EQUAL(count, 2, ());
OutPointsT points;
@@ -311,8 +300,8 @@ inline void const * LoadInnerTriangles(void const * pBeg, size_t count,
return res;
}
void DecodeTriangles(coding::InDeltasT const & deltas, m2::PointU const & basePoint,
m2::PointU const & maxPoint, coding::OutPointsT & triangles);
void DecodeTriangles(coding::InDeltasT const & deltas, m2::PointU const & basePoint, m2::PointU const & maxPoint,
coding::OutPointsT & triangles);
template <class TSource>
void LoadOuterTriangles(TSource & src, GeometryCodingParams const & params, OutPointsT & triangles)

View File

@@ -2,48 +2,47 @@
#include "base/assert.hpp"
namespace impl
{
static const char kToHexTable[] = "0123456789ABCDEF";
static char const kToHexTable[] = "0123456789ABCDEF";
void ToHexRaw(void const * src, size_t size, void * dst)
void ToHexRaw(void const * src, size_t size, void * dst)
{
uint8_t const * ptr = static_cast<uint8_t const *>(src);
uint8_t const * end = ptr + size;
uint8_t * out = static_cast<uint8_t *>(dst);
while (ptr != end)
{
uint8_t const * ptr = static_cast<uint8_t const *>(src);
uint8_t const * end = ptr + size;
uint8_t * out = static_cast<uint8_t*>(dst);
while (ptr != end)
{
*out++ = kToHexTable[(*ptr) >> 4];
*out++ = kToHexTable[(*ptr) & 0xF];
++ptr;
}
}
uint8_t HexDigitToRaw(uint8_t const digit)
{
if (digit >= '0' && digit <= '9')
return (digit - '0');
else if (digit >= 'A' && digit <= 'F')
return (digit - 'A' + 10);
else if (digit >= 'a' && digit <= 'f')
return (digit - 'a' + 10);
ASSERT(false, (digit));
return 0;
}
void FromHexRaw(void const * src, size_t size, void * dst)
{
uint8_t const * ptr = static_cast<uint8_t const *>(src);
uint8_t const * end = ptr + size;
uint8_t * out = static_cast<uint8_t*>(dst);
while (ptr < end)
{
*out = HexDigitToRaw(*ptr++) << 4;
*out |= HexDigitToRaw(*ptr++);
++out;
}
*out++ = kToHexTable[(*ptr) >> 4];
*out++ = kToHexTable[(*ptr) & 0xF];
++ptr;
}
}
uint8_t HexDigitToRaw(uint8_t const digit)
{
if (digit >= '0' && digit <= '9')
return (digit - '0');
else if (digit >= 'A' && digit <= 'F')
return (digit - 'A' + 10);
else if (digit >= 'a' && digit <= 'f')
return (digit - 'a' + 10);
ASSERT(false, (digit));
return 0;
}
void FromHexRaw(void const * src, size_t size, void * dst)
{
uint8_t const * ptr = static_cast<uint8_t const *>(src);
uint8_t const * end = ptr + size;
uint8_t * out = static_cast<uint8_t *>(dst);
while (ptr < end)
{
*out = HexDigitToRaw(*ptr++) << 4;
*out |= HexDigitToRaw(*ptr++);
++out;
}
}
} // namespace impl

View File

@@ -9,14 +9,15 @@
namespace impl
{
void ToHexRaw(void const * src, size_t size, void * dst);
void FromHexRaw(void const * src, size_t size, void * dst);
}
void ToHexRaw(void const * src, size_t size, void * dst);
void FromHexRaw(void const * src, size_t size, void * dst);
} // namespace impl
inline std::string ToHex(const void * ptr, size_t size)
inline std::string ToHex(void const * ptr, size_t size)
{
std::string result;
if (size == 0) return result;
if (size == 0)
return result;
result.resize(size * 2);
::impl::ToHexRaw(ptr, size, &result[0]);

View File

@@ -83,7 +83,7 @@ public:
Code() : bits(0), len(0) {}
Code(uint32_t bits, size_t len) : bits(bits), len(len) {}
bool operator<(const Code & o) const
bool operator<(Code const & o) const
{
if (bits != o.bits)
return bits < o.bits;
@@ -224,9 +224,13 @@ private:
bool isLeaf;
Node(uint32_t symbol, uint32_t freq, bool isLeaf)
: l(nullptr), r(nullptr), symbol(symbol), freq(freq), depth(0), isLeaf(isLeaf)
{
}
: l(nullptr)
, r(nullptr)
, symbol(symbol)
, freq(freq)
, depth(0)
, isLeaf(isLeaf)
{}
};
struct NodeComparator

View File

@@ -3,26 +3,26 @@
#include "std/target_os.hpp"
#if defined(OMIM_OS_WINDOWS_NATIVE)
#define fseek64 _fseeki64
#define ftell64 _ftelli64
#define fseek64 _fseeki64
#define ftell64 _ftelli64
#elif defined(OMIM_OS_WINDOWS_MINGW)
#define fseek64 fseeko64
#define ftell64 ftello64
#define fseek64 fseeko64
#define ftell64 ftello64
#else
// POSIX standart.
#include <sys/types.h>
// POSIX standart.
#include <sys/types.h>
// TODO: Always assert for 8 bytes after increasing min Android API to 24+.
// See more details here: https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md
#if defined(OMIM_OS_ANDROID) && (defined(__arm__) || defined(__i386__))
static_assert(sizeof(off_t) == 4, "32-bit Android NDK < API 24 has only 32-bit file operations support");
#else
static_assert(sizeof(off_t) == 8, "FileReader and FileWriter require 64-bit file operations");
#endif
#define fseek64 fseeko
#define ftell64 ftello
// TODO: Always assert for 8 bytes after increasing min Android API to 24+.
// See more details here: https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md
#if defined(OMIM_OS_ANDROID) && (defined(__arm__) || defined(__i386__))
static_assert(sizeof(off_t) == 4, "32-bit Android NDK < API 24 has only 32-bit file operations support");
#else
static_assert(sizeof(off_t) == 8, "FileReader and FileWriter require 64-bit file operations");
#endif
#define fseek64 fseeko
#define ftell64 ftello
#endif

View File

@@ -2,8 +2,8 @@
#include "coding/constants.hpp"
#include "coding/internal/file64_api.hpp"
#include "coding/reader.hpp" // For Reader exceptions.
#include "coding/writer.hpp" // For Writer exceptions.
#include "coding/reader.hpp" // For Reader exceptions.
#include "coding/writer.hpp" // For Writer exceptions.
#include "base/exception.hpp"
#include "base/logging.hpp"
@@ -40,10 +40,9 @@ std::ostream & operator<<(std::ostream & stream, FileData::Op op)
return stream;
}
FileData::FileData(string const & fileName, Op op)
: m_FileName(fileName), m_Op(op)
FileData::FileData(string const & fileName, Op op) : m_FileName(fileName), m_Op(op)
{
char const * const modes [] = {"rb", "wb", "r+b", "ab"};
char const * const modes[] = {"rb", "wb", "r+b", "ab"};
m_File = fopen(fileName.c_str(), modes[static_cast<int>(op)]);
if (m_File)
@@ -190,9 +189,7 @@ bool CheckFileOperationResult(int res, string const & fName)
// additional check if file really was removed correctly
uint64_t dummy;
if (GetFileSize(fName, dummy))
{
LOG(LERROR, ("File exists but can't be deleted. Sharing violation?", fName));
}
return false;
}
@@ -226,18 +223,16 @@ bool MoveFileX(string const & fOld, string const & fNew)
// Otherwise perform the full move.
if (!CopyFileX(fOld, fNew))
{
(void) DeleteFileX(fNew);
(void)DeleteFileX(fNew);
return false;
}
(void) DeleteFileX(fOld);
(void)DeleteFileX(fOld);
return true;
}
bool WriteToTempAndRenameToFile(string const & dest, function<bool(string const &)> const & write,
string const & tmp)
bool WriteToTempAndRenameToFile(string const & dest, function<bool(string const &)> const & write, string const & tmp)
{
string const tmpFileName =
tmp.empty() ? dest + ".tmp" + strings::to_string(this_thread::get_id()) : tmp;
string const tmpFileName = tmp.empty() ? dest + ".tmp" + strings::to_string(this_thread::get_id()) : tmp;
if (!write(tmpFileName))
{
LOG(LERROR, ("Can't write to", tmpFileName));
@@ -298,7 +293,7 @@ bool CopyFileX(string const & fOld, string const & fNew)
}
// Don't care about possible error here ..
(void) DeleteFileX(fNew);
(void)DeleteFileX(fNew);
return false;
}

View File

@@ -13,7 +13,13 @@ class FileData
{
public:
/// @note Do not change order (@see FileData::FileData).
enum class Op { READ = 0, WRITE_TRUNCATE, WRITE_EXISTING, APPEND };
enum class Op
{
READ = 0,
WRITE_TRUNCATE,
WRITE_EXISTING,
APPEND
};
FileData(std::string const & fileName, Op op);
~FileData();
@@ -33,8 +39,8 @@ public:
private:
FILE * m_File;
const std::string m_FileName;
const Op m_Op;
std::string const m_FileName;
Op const m_Op;
std::string GetErrorProlog() const;
@@ -47,8 +53,7 @@ bool RenameFileX(std::string const & fOld, std::string const & fNew);
/// Write to temp file and rename it to dest. Delete temp on failure.
/// @param write function that writes to file with a given name, returns true on success.
bool WriteToTempAndRenameToFile(std::string const & dest,
std::function<bool(std::string const &)> const & write,
bool WriteToTempAndRenameToFile(std::string const & dest, std::function<bool(std::string const &)> const & write,
std::string const & tmp = "");
void AppendFileToFile(std::string const & fromFilename, std::string const & toFilename);

View File

@@ -36,15 +36,14 @@ public:
, m_restrictDepth(static_cast<size_t>(-1))
, m_dispatcher(dispatcher)
, m_enableCharHandler(enableCharHandler)
, m_parser(std::unique_ptr<XML_ParserStruct, decltype(&XML_ParserFree)>(
XML_ParserCreate(nullptr /* encoding */), &XML_ParserFree))
, m_parser(std::unique_ptr<XML_ParserStruct, decltype(&XML_ParserFree)>(XML_ParserCreate(nullptr /* encoding */),
&XML_ParserFree))
{
CHECK(m_parser, ());
OnPostCreate();
}
static void StartElementHandler(void * userData, XML_Char const * name,
XML_Char const ** attrs)
static void StartElementHandler(void * userData, XML_Char const * name, XML_Char const ** attrs)
{
CHECK(userData, (name));
auto * xmlParser = static_cast<XmlParser *>(userData);
@@ -138,8 +137,8 @@ public:
return {};
std::stringstream s;
s << "XML parse error at line " << XML_GetCurrentLineNumber(m_parser.get())
<< " and byte " << XML_GetCurrentByteIndex(m_parser.get());
s << "XML parse error at line " << XML_GetCurrentLineNumber(m_parser.get()) << " and byte "
<< XML_GetCurrentByteIndex(m_parser.get());
return s.str();
}

View File

@@ -101,9 +101,9 @@ public:
};
MapUint32ToValue(Reader & reader, ReadBlockCallback const & readBlockCallback)
: m_reader(reader), m_readBlockCallback(readBlockCallback)
{
}
: m_reader(reader)
, m_readBlockCallback(readBlockCallback)
{}
/// @name Tries to get |value| for key identified by |id|.
/// @returns false if table does not have entry for this id.
@@ -284,8 +284,7 @@ public:
}
{
succinct::elias_fano::elias_fano_builder builder(offsets.empty() ? 0 : offsets.back() + 1,
offsets.size());
succinct::elias_fano::elias_fano_builder builder(offsets.empty() ? 0 : offsets.back() + 1, offsets.size());
for (auto const & offset : offsets)
builder.push_back(offset);

View File

@@ -20,9 +20,7 @@ public:
class MappedMemoryRegion : public MemoryRegion
{
public:
explicit MappedMemoryRegion(FilesMappingContainer::Handle && handle) : m_handle(std::move(handle))
{
}
explicit MappedMemoryRegion(FilesMappingContainer::Handle && handle) : m_handle(std::move(handle)) {}
// MemoryRegion overrides:
uint64_t Size() const override { return m_handle.GetSize(); }

View File

@@ -7,16 +7,16 @@
#include <cstring>
#ifdef OMIM_OS_WINDOWS
#include <windows.h>
#include <windows.h>
#else
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#ifdef OMIM_OS_ANDROID
#include <fcntl.h>
#else
#include <sys/fcntl.h>
#endif
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#ifdef OMIM_OS_ANDROID
#include <fcntl.h>
#else
#include <sys/fcntl.h>
#endif
#endif
class MmapReader::MmapData
@@ -33,7 +33,8 @@ public:
m_hMapping = CreateFileMappingA(m_hFile, nullptr, PAGE_READONLY, 0, 0, nullptr);
if (!m_hMapping)
MYTHROW(Reader::OpenException, ("Can't create file's Windows mapping:", fileName, "win last error:", GetLastError()));
MYTHROW(Reader::OpenException,
("Can't create file's Windows mapping:", fileName, "win last error:", GetLastError()));
SCOPE_GUARD(mappingGuard, [this] { CloseHandle(m_hMapping); });
@@ -44,7 +45,8 @@ public:
m_size = fileSize.QuadPart;
m_memory = static_cast<uint8_t *>(MapViewOfFile(m_hMapping, FILE_MAP_READ, 0, 0, 0));
if (!m_memory)
MYTHROW(Reader::OpenException, ("Can't create file's Windows mapping:", fileName, "win last error:", GetLastError()));
MYTHROW(Reader::OpenException,
("Can't create file's Windows mapping:", fileName, "win last error:", GetLastError()));
mappingGuard.release();
fileGuard.release();
@@ -58,8 +60,7 @@ public:
MYTHROW(OpenException, ("fstat failed for file", fileName));
m_size = s.st_size;
m_memory = static_cast<uint8_t *>(
mmap(0, static_cast<size_t>(m_size), PROT_READ, MAP_PRIVATE, m_fd, 0));
m_memory = static_cast<uint8_t *>(mmap(0, static_cast<size_t>(m_size), PROT_READ, MAP_PRIVATE, m_fd, 0));
if (m_memory == MAP_FAILED)
{
close(m_fd);
@@ -109,14 +110,14 @@ MmapReader::MmapReader(std::string const & fileName, Advice advice)
, m_data(std::make_shared<MmapData>(fileName, advice))
, m_offset(0)
, m_size(m_data->m_size)
{
}
{}
MmapReader::MmapReader(MmapReader const & reader, uint64_t offset, uint64_t size)
: base_type(reader.GetName()), m_data(reader.m_data),
m_offset(offset), m_size(size)
{
}
: base_type(reader.GetName())
, m_data(reader.m_data)
, m_offset(offset)
, m_size(size)
{}
uint64_t MmapReader::Size() const
{

View File

@@ -20,8 +20,7 @@ public:
, m_numRead(0)
, m_source(source)
, m_parser(dispatcher, useCharData)
{
}
{}
bool Read()
{
@@ -65,7 +64,6 @@ private:
Source & m_source;
};
template <typename XMLDispatcher, typename Source>
bool ParseXML(Source & source, XMLDispatcher & dispatcher, bool useCharData = false)
{
@@ -73,7 +71,8 @@ bool ParseXML(Source & source, XMLDispatcher & dispatcher, bool useCharData = fa
XMLSequenceParser<decltype(adapter), XMLDispatcher> parser(adapter, dispatcher, useCharData);
try
{
while (parser.Read()) /* empty */;
while (parser.Read()) /* empty */
;
}
catch (std::exception const & e)
{

View File

@@ -45,10 +45,10 @@ double Uint32ToDouble(uint32_t x, double min, double max, uint8_t coordBits)
// It doesn't work now because of fancy serialization of m2::DiamondBox.
/// @todo Check PathsThroughLayers search test. Refactor CitiesBoundariesSerDes.
//ASSERT_LESS_OR_EQUAL(x, coordSize, (d, min, max, coordBits));
// ASSERT_LESS_OR_EQUAL(x, coordSize, (d, min, max, coordBits));
// It doesn't work because of possible floating errors.
//ASSERT(d >= min && d <= max, (d, x, min, max, coordBits));
// ASSERT(d >= min && d <= max, (d, x, min, max, coordBits));
return math::Clamp(d, min, max);
}
@@ -56,8 +56,8 @@ double Uint32ToDouble(uint32_t x, double min, double max, uint8_t coordBits)
m2::PointU PointDToPointU(double x, double y, uint8_t coordBits)
{
using mercator::Bounds;
return { DoubleToUint32(x, Bounds::kMinX, Bounds::kMaxX, coordBits),
DoubleToUint32(y, Bounds::kMinY, Bounds::kMaxY, coordBits) };
return {DoubleToUint32(x, Bounds::kMinX, Bounds::kMaxX, coordBits),
DoubleToUint32(y, Bounds::kMinY, Bounds::kMaxY, coordBits)};
}
m2::PointU PointDToPointU(m2::PointD const & pt, uint8_t coordBits)
@@ -67,21 +67,21 @@ m2::PointU PointDToPointU(m2::PointD const & pt, uint8_t coordBits)
m2::PointU PointDToPointU(m2::PointD const & pt, uint8_t coordBits, m2::RectD const & limitRect)
{
return { DoubleToUint32(pt.x, limitRect.minX(), limitRect.maxX(), coordBits),
DoubleToUint32(pt.y, limitRect.minY(), limitRect.maxY(), coordBits) };
return {DoubleToUint32(pt.x, limitRect.minX(), limitRect.maxX(), coordBits),
DoubleToUint32(pt.y, limitRect.minY(), limitRect.maxY(), coordBits)};
}
m2::PointD PointUToPointD(m2::PointU const & pt, uint8_t coordBits)
{
using mercator::Bounds;
return { Uint32ToDouble(pt.x, Bounds::kMinX, Bounds::kMaxX, coordBits),
Uint32ToDouble(pt.y, Bounds::kMinY, Bounds::kMaxY, coordBits) };
return {Uint32ToDouble(pt.x, Bounds::kMinX, Bounds::kMaxX, coordBits),
Uint32ToDouble(pt.y, Bounds::kMinY, Bounds::kMaxY, coordBits)};
}
m2::PointD PointUToPointD(m2::PointU const & pt, uint8_t coordBits, m2::RectD const & limitRect)
{
return { Uint32ToDouble(pt.x, limitRect.minX(), limitRect.maxX(), coordBits),
Uint32ToDouble(pt.y, limitRect.minY(), limitRect.maxY(), coordBits) };
return {Uint32ToDouble(pt.x, limitRect.minX(), limitRect.maxX(), coordBits),
Uint32ToDouble(pt.y, limitRect.minY(), limitRect.maxY(), coordBits)};
}
uint8_t GetCoordBits(m2::RectD const & limitRect, double accuracy)
@@ -89,10 +89,8 @@ uint8_t GetCoordBits(m2::RectD const & limitRect, double accuracy)
auto const range = std::max(limitRect.SizeX(), limitRect.SizeY());
auto const valuesNumber = 1.0 + range / accuracy;
for (uint8_t coordBits = 1; coordBits <= 32; ++coordBits)
{
if (CoordSize(coordBits) >= valuesNumber)
return coordBits;
}
return 0;
}

View File

@@ -11,156 +11,152 @@
namespace rw
{
template <class T, class TSink>
std::enable_if_t<std::is_integral_v<T> && std::is_unsigned_v<T>, void>
Write(TSink & sink, T i)
template <class T, class TSink>
std::enable_if_t<std::is_integral_v<T> && std::is_unsigned_v<T>, void> Write(TSink & sink, T i)
{
WriteVarUint(sink, i);
}
template <class T, class TSource>
std::enable_if_t<std::is_integral_v<T> && std::is_unsigned_v<T>, void> Read(TSource & src, T & i)
{
i = ReadVarUint<T>(src);
}
template <class T, class TSink>
std::enable_if_t<std::is_integral_v<T> && std::is_signed_v<T>, void> Write(TSink & sink, T i)
{
WriteVarInt(sink, i);
}
template <class T, class TSource>
std::enable_if_t<std::is_integral_v<T> && std::is_signed_v<T>, void> Read(TSource & src, T & i)
{
i = ReadVarInt<T>(src);
}
template <class TSink>
void Write(TSink & sink, std::string const & s)
{
uint32_t const count = static_cast<uint32_t>(s.size());
WriteVarUint(sink, count);
if (!s.empty())
sink.Write(&s[0], count);
}
template <class TSource>
void Read(TSource & src, std::string & s)
{
uint32_t const count = ReadVarUint<uint32_t>(src);
s.resize(count);
if (count > 0)
src.Read(&s[0], count);
}
namespace impl
{
template <class TSink, class TCont>
void WriteCont(TSink & sink, TCont const & v)
{
uint32_t const count = static_cast<uint32_t>(v.size());
WriteVarUint(sink, count);
for (uint32_t i = 0; i < count; ++i)
Write(sink, v[i]);
}
template <class TSource, class TCont>
void ReadCont(TSource & src, TCont & v)
{
uint32_t const count = ReadVarUint<uint32_t>(src);
v.resize(count);
for (size_t i = 0; i < count; ++i)
Read(src, v[i]);
}
} // namespace impl
template <class TSink, class T>
void Write(TSink & sink, std::vector<T> const & v)
{
impl::WriteCont(sink, v);
}
template <class TSource, class T>
void Read(TSource & src, std::vector<T> & v)
{
impl::ReadCont(src, v);
}
template <class TSink, class T, size_t N>
void Write(TSink & sink, buffer_vector<T, N> const & v)
{
impl::WriteCont(sink, v);
}
template <class TSource, class T, size_t N>
void Read(TSource & src, buffer_vector<T, N> & v)
{
impl::ReadCont(src, v);
}
template <class Sink, class T>
void WritePOD(Sink & sink, T const & value)
{
static_assert(std::is_trivially_copyable<T>::value, "");
sink.Write(&value, sizeof(T));
}
template <class Sink, class T>
void ReadPOD(Sink & src, T & value)
{
static_assert(std::is_trivially_copyable<T>::value, "");
src.Read(&value, sizeof(T));
}
template <class TSource, class TCont>
void ReadVectorOfPOD(TSource & src, TCont & v)
{
typedef typename TCont::value_type ValueT;
/// This assert fails on std::pair<int, int> and OsmID class because std::pair is not trivially copyable:
/// std::pair has a non-trivial copy-assignment and move-assignment operator.
// static_assert(std::is_trivially_copyable_v<ValueT>);
uint32_t const count = ReadVarUint<uint32_t>(src);
if (count > 0)
{
WriteVarUint(sink, i);
}
template <class T, class TSource>
std::enable_if_t<std::is_integral_v<T> && std::is_unsigned_v<T>, void>
Read(TSource & src, T & i)
{
i = ReadVarUint<T>(src);
}
template <class T, class TSink>
std::enable_if_t<std::is_integral_v<T> && std::is_signed_v<T>, void>
Write(TSink & sink, T i)
{
WriteVarInt(sink, i);
}
template <class T, class TSource>
std::enable_if_t<std::is_integral_v<T> && std::is_signed_v<T>, void>
Read(TSource & src, T & i)
{
i = ReadVarInt<T>(src);
}
template <class TSink>
void Write(TSink & sink, std::string const & s)
{
uint32_t const count = static_cast<uint32_t>(s.size());
WriteVarUint(sink, count);
if (!s.empty())
sink.Write(&s[0], count);
}
template <class TSource>
void Read(TSource & src, std::string & s)
{
uint32_t const count = ReadVarUint<uint32_t>(src);
s.resize(count);
if (count > 0)
src.Read(&s[0], count);
}
namespace impl
{
template <class TSink, class TCont>
void WriteCont(TSink & sink, TCont const & v)
{
uint32_t const count = static_cast<uint32_t>(v.size());
WriteVarUint(sink, count);
for (uint32_t i = 0; i < count; ++i)
Write(sink, v[i]);
}
template <class TSource, class TCont>
void ReadCont(TSource & src, TCont & v)
{
uint32_t const count = ReadVarUint<uint32_t>(src);
v.resize(count);
for (size_t i = 0; i < count; ++i)
Read(src, v[i]);
}
}
template <class TSink, class T>
void Write(TSink & sink, std::vector<T> const & v)
{
impl::WriteCont(sink, v);
}
template <class TSource, class T>
void Read(TSource & src, std::vector<T> & v)
{
impl::ReadCont(src, v);
}
template <class TSink, class T, size_t N>
void Write(TSink & sink, buffer_vector<T, N> const & v)
{
impl::WriteCont(sink, v);
}
template <class TSource, class T, size_t N>
void Read(TSource & src, buffer_vector<T, N> & v)
{
impl::ReadCont(src, v);
}
template <class Sink, class T>
void WritePOD(Sink & sink, T const & value)
{
static_assert(std::is_trivially_copyable<T>::value, "");
sink.Write(&value, sizeof(T));
}
template <class Sink, class T>
void ReadPOD(Sink & src, T & value)
{
static_assert(std::is_trivially_copyable<T>::value, "");
src.Read(&value, sizeof(T));
}
template <class TSource, class TCont>
void ReadVectorOfPOD(TSource & src, TCont & v)
{
typedef typename TCont::value_type ValueT;
/// This assert fails on std::pair<int, int> and OsmID class because std::pair is not trivially copyable:
/// std::pair has a non-trivial copy-assignment and move-assignment operator.
//static_assert(std::is_trivially_copyable_v<ValueT>);
uint32_t const count = ReadVarUint<uint32_t>(src);
if (count > 0)
{
v.resize(count);
src.Read(&v[0], count * sizeof(ValueT));
}
}
template <class TSink, class TCont>
void WriteVectorOfPOD(TSink & sink, TCont const & v)
{
typedef typename TCont::value_type ValueT;
/// This assert fails on std::pair<int, int> and OsmID class because std::pair is not trivially copyable:
/// std::pair has a non-trivial copy-assignment and move-assignment operator.
//static_assert(std::is_trivially_copyable_v<ValueT>);
uint32_t const count = static_cast<uint32_t>(v.size());
WriteVarUint(sink, count);
if (count > 0)
sink.Write(&v[0], count * sizeof(ValueT));
}
template <class ReaderT, class WriterT>
void ReadAndWrite(ReaderT & reader, WriterT & writer, size_t bufferSize = 4*1024)
{
uint64_t size = reader.Size();
std::vector<char> buffer(std::min(bufferSize, static_cast<size_t>(size)));
while (size > 0)
{
size_t const curr = std::min(bufferSize, static_cast<size_t>(size));
reader.Read(&buffer[0], curr);
writer.Write(&buffer[0], curr);
size -= curr;
}
v.resize(count);
src.Read(&v[0], count * sizeof(ValueT));
}
}
template <class TSink, class TCont>
void WriteVectorOfPOD(TSink & sink, TCont const & v)
{
typedef typename TCont::value_type ValueT;
/// This assert fails on std::pair<int, int> and OsmID class because std::pair is not trivially copyable:
/// std::pair has a non-trivial copy-assignment and move-assignment operator.
// static_assert(std::is_trivially_copyable_v<ValueT>);
uint32_t const count = static_cast<uint32_t>(v.size());
WriteVarUint(sink, count);
if (count > 0)
sink.Write(&v[0], count * sizeof(ValueT));
}
template <class ReaderT, class WriterT>
void ReadAndWrite(ReaderT & reader, WriterT & writer, size_t bufferSize = 4 * 1024)
{
uint64_t size = reader.Size();
std::vector<char> buffer(std::min(bufferSize, static_cast<size_t>(size)));
while (size > 0)
{
size_t const curr = std::min(bufferSize, static_cast<size_t>(size));
reader.Read(&buffer[0], curr);
writer.Write(&buffer[0], curr);
size -= curr;
}
}
} // namespace rw

View File

@@ -37,15 +37,9 @@ class MemReaderTemplate : public Reader
{
public:
// Construct from block of memory.
MemReaderTemplate(void const * pData, size_t size)
: m_pData(static_cast<char const *>(pData)), m_size(size)
{
}
MemReaderTemplate(void const * pData, size_t size) : m_pData(static_cast<char const *>(pData)), m_size(size) {}
explicit MemReaderTemplate(std::string_view data)
: m_pData{data.data()}, m_size{data.size()}
{
}
explicit MemReaderTemplate(std::string_view data) : m_pData{data.data()}, m_size{data.size()} {}
uint64_t Size() const override { return m_size; }
@@ -106,25 +100,15 @@ protected:
public:
template <typename TReaderDerived>
ReaderPtr(std::unique_ptr<TReaderDerived> p) : m_p(std::move(p))
{
}
{}
uint64_t Size() const
{
return m_p->Size();
}
uint64_t Size() const { return m_p->Size(); }
void Read(uint64_t pos, void * p, size_t size) const
{
m_p->Read(pos, p, size);
}
void Read(uint64_t pos, void * p, size_t size) const { m_p->Read(pos, p, size); }
void ReadAsString(std::string & s) const { m_p->ReadAsString(s); }
ReaderPtr<Reader> SubReader(uint64_t pos, uint64_t size) const
{
return {m_p->CreateSubReader(pos, size)};
}
ReaderPtr<Reader> SubReader(uint64_t pos, uint64_t size) const { return {m_p->CreateSubReader(pos, size)}; }
TReader * GetPtr() const { return m_p.get(); }
};
@@ -148,13 +132,11 @@ class ModelReaderPtr : public ReaderPtr<ModelReader>
public:
template <typename TReaderDerived>
ModelReaderPtr(std::unique_ptr<TReaderDerived> p) : TBase(std::move(p))
{
}
{}
ModelReaderPtr SubReader(uint64_t pos, uint64_t size) const
{
return std::unique_ptr<ModelReader>(
static_cast<ModelReader *>(m_p->CreateSubReader(pos, size).release()));
return std::unique_ptr<ModelReader>(static_cast<ModelReader *>(m_p->CreateSubReader(pos, size).release()));
}
std::string const & GetName() const { return m_p->GetName(); }
@@ -166,13 +148,9 @@ class NonOwningReaderSource
{
public:
/// @note Reader shouldn't change it's size during the source's lifetime.
explicit NonOwningReaderSource(Reader const & reader)
: m_reader(reader), m_pos(0), m_end(reader.Size())
{}
explicit NonOwningReaderSource(Reader const & reader) : m_reader(reader), m_pos(0), m_end(reader.Size()) {}
NonOwningReaderSource(Reader const & reader, uint64_t pos, uint64_t end)
: m_reader(reader), m_pos(pos), m_end(end)
{}
NonOwningReaderSource(Reader const & reader, uint64_t pos, uint64_t end) : m_reader(reader), m_pos(pos), m_end(end) {}
void Read(void * p, size_t size)
{
@@ -202,10 +180,7 @@ public:
}
private:
void CheckPosition() const
{
ASSERT_LESS_OR_EQUAL(m_pos, m_end, ());
}
void CheckPosition() const { ASSERT_LESS_OR_EQUAL(m_pos, m_end, ()); }
Reader const & m_reader;
uint64_t m_pos, m_end;
@@ -229,17 +204,14 @@ public:
void Skip(uint64_t size)
{
m_pos += size;
ASSERT ( AssertPosition(), () );
ASSERT(AssertPosition(), ());
}
uint64_t Pos() const
{
return m_pos;
}
uint64_t Pos() const { return m_pos; }
uint64_t Size() const
{
ASSERT ( AssertPosition(), () );
ASSERT(AssertPosition(), ());
return (m_reader.Size() - m_pos);
}
@@ -270,7 +242,7 @@ private:
bool AssertPosition() const
{
bool const ret = (m_pos <= m_reader.Size());
ASSERT ( ret, (m_pos, m_reader.Size()) );
ASSERT(ret, (m_pos, m_reader.Size()));
return ret;
}

View File

@@ -47,10 +47,7 @@ template <class ReaderT, bool bStats = false>
class ReaderCache
{
public:
ReaderCache(uint32_t logPageSize, uint32_t logPageCount)
: m_Cache(logPageCount), m_LogPageSize(logPageSize)
{
}
ReaderCache(uint32_t logPageSize, uint32_t logPageCount) : m_Cache(logPageCount), m_LogPageSize(logPageSize) {}
void Read(ReaderT & reader, uint64_t pos, void * p, size_t size)
{
@@ -79,10 +76,7 @@ public:
}
}
std::string GetStatsStr() const
{
return m_Stats.GetStatsStr(m_LogPageSize, m_Cache.GetCacheSize());
}
std::string GetStatsStr() const { return m_Stats.GetStatsStr(m_LogPageSize, m_Cache.GetCacheSize()); }
private:
inline size_t PageSize() const { return 1 << m_LogPageSize; }
@@ -102,7 +96,7 @@ private:
return &v[0];
}
base::Cache<uint64_t, std::vector<char> > m_Cache;
base::Cache<uint64_t, std::vector<char>> m_Cache;
uint32_t const m_LogPageSize;
impl::ReaderCacheStats<bStats> m_Stats;
};

View File

@@ -1,13 +1,10 @@
#include "coding/reader_streambuf.hpp"
#include "coding/reader.hpp"
#include "coding/file_writer.hpp"
#include "coding/reader.hpp"
#include <algorithm>
ReaderStreamBuf::ReaderStreamBuf(std::unique_ptr<Reader> && p)
: m_p(std::move(p)), m_pos(0), m_size(m_p->Size())
{
}
ReaderStreamBuf::ReaderStreamBuf(std::unique_ptr<Reader> && p) : m_p(std::move(p)), m_pos(0), m_size(m_p->Size()) {}
// Define destructor in .cpp due to using unique_ptr with incomplete type.
ReaderStreamBuf::~ReaderStreamBuf() = default;
@@ -37,7 +34,6 @@ ReaderStreamBuf::int_type ReaderStreamBuf::underflow()
}
}
std::streamsize WriterStreamBuf::xsputn(char_type const * s, std::streamsize n)
{
m_writer.Write(s, n);

View File

@@ -7,7 +7,6 @@
class Reader;
class Writer;
class BaseStreamBuf : public std::streambuf
{
public:

View File

@@ -2,19 +2,18 @@
#include "coding/reader.hpp"
/// Reader wrapper to avoid penalty on copy and polymorphic SubReader creation.
template <class ReaderT> class SubReaderWrapper
template <class ReaderT>
class SubReaderWrapper
{
ReaderT * m_p;
uint64_t m_pos;
uint64_t m_size;
protected:
SubReaderWrapper(ReaderT * p, uint64_t pos, uint64_t size)
: m_p(p), m_pos(pos), m_size(size)
SubReaderWrapper(ReaderT * p, uint64_t pos, uint64_t size) : m_p(p), m_pos(pos), m_size(size)
{
ASSERT_LESS_OR_EQUAL ( pos + size, m_p->Size(), (pos, size) );
ASSERT_LESS_OR_EQUAL(pos + size, m_p->Size(), (pos, size));
}
public:
@@ -24,14 +23,11 @@ public:
void Read(uint64_t pos, void * p, size_t size) const
{
ASSERT_LESS_OR_EQUAL ( pos + size, m_size, (pos, size) );
ASSERT_LESS_OR_EQUAL(pos + size, m_size, (pos, size));
m_p->Read(pos + m_pos, p, size);
}
SubReaderWrapper SubReader(uint64_t pos, uint64_t size) const
{
return SubReaderWrapper(m_p, pos + m_pos, size);
}
SubReaderWrapper SubReader(uint64_t pos, uint64_t size) const { return SubReaderWrapper(m_p, pos + m_pos, size); }
};
/// Non template reader source for regular functions with incapsulated implementation.

View File

@@ -5,7 +5,7 @@
namespace rw_ops
{
/// Do reverse bytes.
/// Note! src and dest should be for different entities.
void Reverse(Reader const & src, Writer & dest);
}
/// Do reverse bytes.
/// Note! src and dest should be for different entities.
void Reverse(Reader const & src, Writer & dest);
} // namespace rw_ops

View File

@@ -41,12 +41,9 @@ struct HeaderSerVisitor
template <typename Source>
struct HeaderDesVisitor
{
HeaderDesVisitor(Source & source): m_source(source) {}
HeaderDesVisitor(Source & source) : m_source(source) {}
void operator()(uint64_t & v, char const * /* name */ = nullptr)
{
v = ReadPrimitiveFromSource<uint64_t>(m_source);
}
void operator()(uint64_t & v, char const * /* name */ = nullptr) { v = ReadPrimitiveFromSource<uint64_t>(m_source); }
template <typename R>
void operator()(R & r, char const * /* name */ = nullptr)

View File

@@ -28,20 +28,16 @@ namespace traits
namespace impl
{
template <typename T>
auto is_iterable_checker(int) -> decltype(
std::begin(std::declval<T>()),
std::end(std::declval<T>()),
++std::declval<decltype(std::begin(std::declval<T>())) &>(),
std::true_type {});
auto is_iterable_checker(int)
-> decltype(std::begin(std::declval<T>()), std::end(std::declval<T>()),
++std::declval<decltype(std::begin(std::declval<T>())) &>(), std::true_type{});
template <typename T>
std::false_type is_iterable_checker(...);
template <typename T>
auto is_dynamic_sequence_checker(int) -> decltype(
std::declval<T &>().resize(0),
std::declval<T &>()[0],
std::true_type {});
auto is_dynamic_sequence_checker(int)
-> decltype(std::declval<T &>().resize(0), std::declval<T &>()[0], std::true_type{});
template <typename T>
std::false_type is_dynamic_sequence_checker(...);
@@ -67,13 +63,13 @@ template <typename T>
using EnableIfNotEnum = std::enable_if_t<!std::is_enum<T>::value>;
template <typename T>
using EnableIfVectorOrDeque = std::enable_if_t<traits::is_dynamic_sequence<T>::value &&
!std::is_same<std::string, T>::value>;
using EnableIfVectorOrDeque =
std::enable_if_t<traits::is_dynamic_sequence<T>::value && !std::is_same<std::string, T>::value>;
template <typename T>
using EnableIfNotVectorOrDeque = std::enable_if_t<!traits::is_dynamic_sequence<T>::value>;
template<typename Sink>
template <typename Sink>
class SerializerJson
{
public:
@@ -122,7 +118,8 @@ public:
template <typename T, EnableIfIterable<T> * = nullptr>
void operator()(T const & src, char const * name = nullptr)
{
NewScopeWith(base::NewJSONArray(), name, [this, &src] {
NewScopeWith(base::NewJSONArray(), name, [this, &src]
{
for (auto const & v : src)
(*this)(v);
});
@@ -131,7 +128,8 @@ public:
template <typename R>
void operator()(std::unique_ptr<R> const & r, char const * name = nullptr)
{
NewScopeWith(base::NewJSONObject(), name, [this, &r] {
NewScopeWith(base::NewJSONObject(), name, [this, &r]
{
CHECK(r, ());
r->Visit(*this);
});
@@ -140,7 +138,8 @@ public:
template <typename R>
void operator()(std::shared_ptr<R> const & r, char const * name = nullptr)
{
NewScopeWith(base::NewJSONObject(), name, [this, &r] {
NewScopeWith(base::NewJSONObject(), name, [this, &r]
{
CHECK(r, ());
r->Visit(*this);
});
@@ -159,7 +158,8 @@ public:
void operator()(m2::PointD const & p, char const * name = nullptr)
{
NewScopeWith(base::NewJSONObject(), name, [this, &p] {
NewScopeWith(base::NewJSONObject(), name, [this, &p]
{
(*this)(p.x, "x");
(*this)(p.y, "y");
});
@@ -167,7 +167,8 @@ public:
void operator()(ms::LatLon const & ll, char const * name = nullptr)
{
NewScopeWith(base::NewJSONObject(), name, [this, &ll] {
NewScopeWith(base::NewJSONObject(), name, [this, &ll]
{
(*this)(ll.m_lat, "lat");
(*this)(ll.m_lon, "lon");
});
@@ -176,7 +177,8 @@ public:
template <typename Key, typename Value>
void operator()(std::pair<Key, Value> const & p, char const * name = nullptr)
{
NewScopeWith(base::NewJSONObject(), name, [this, &p] {
NewScopeWith(base::NewJSONObject(), name, [this, &p]
{
(*this)(p.first, "key");
(*this)(p.second, "value");
});
@@ -222,8 +224,7 @@ public:
using Exception = base::Json::Exception;
template <typename Source,
typename std::enable_if<!std::is_convertible<Source, std::string>::value,
Source>::type * = nullptr>
typename std::enable_if<!std::is_convertible<Source, std::string>::value, Source>::type * = nullptr>
explicit DeserializerJson(Source & source)
{
auto const size = static_cast<size_t>(source.Size());
@@ -233,15 +234,9 @@ public:
m_json = m_jsonObject.get();
}
explicit DeserializerJson(std::string const & source)
: m_jsonObject(source), m_json(m_jsonObject.get())
{
}
explicit DeserializerJson(std::string const & source) : m_jsonObject(source), m_json(m_jsonObject.get()) {}
explicit DeserializerJson(char const * buffer)
: m_jsonObject(buffer), m_json(m_jsonObject.get())
{
}
explicit DeserializerJson(char const * buffer) : m_jsonObject(buffer), m_json(m_jsonObject.get()) {}
explicit DeserializerJson(json_t * json) : m_json(json) {}
@@ -313,15 +308,12 @@ public:
json_t * outerContext = SaveContext(name);
if (!json_is_array(m_json))
{
MYTHROW(base::Json::Exception,
("The field", name, "must contain a json array.", json_dumps(m_json, 0)));
}
MYTHROW(base::Json::Exception, ("The field", name, "must contain a json array.", json_dumps(m_json, 0)));
if (N != json_array_size(m_json))
{
MYTHROW(base::Json::Exception, ("The field", name, "must contain a json array of size", N,
"but size is", json_array_size(m_json)));
MYTHROW(base::Json::Exception,
("The field", name, "must contain a json array of size", N, "but size is", json_array_size(m_json)));
}
for (size_t index = 0; index < N; ++index)
@@ -341,10 +333,7 @@ public:
json_t * outerContext = SaveContext(name);
if (!json_is_array(m_json))
{
MYTHROW(base::Json::Exception,
("The field", name, "must contain a json array.", json_dumps(m_json, 0)));
}
MYTHROW(base::Json::Exception, ("The field", name, "must contain a json array.", json_dumps(m_json, 0)));
size_t const size = json_array_size(m_json);
for (size_t index = 0; index < size; ++index)

View File

@@ -29,7 +29,7 @@ SHA1::Hash ExtractHash(boost::uuids::detail::sha1 & sha1)
std::copy_n(reinterpret_cast<uint8_t const *>(digest), sizeof(digest), std::begin(result));
return result;
}
}
} // namespace
// static
SHA1::Hash SHA1::Calculate(std::string const & filePath)
@@ -74,4 +74,4 @@ SHA1::Hash SHA1::CalculateForString(std::string_view str)
sha1.process_bytes(str.data(), str.size());
return ExtractHash(sha1);
}
} // coding
} // namespace coding

View File

@@ -17,4 +17,4 @@ public:
static Hash CalculateForString(std::string_view str);
};
} // coding
} // namespace coding

View File

@@ -23,7 +23,7 @@ SimpleDenseCoding::SimpleDenseCoding(std::vector<uint8_t> const & data)
{
size_t constexpr kAlphabetSize = size_t(std::numeric_limits<uint8_t>::max()) + 1;
uint64_t frequency[kAlphabetSize] = { 0 }; // Maps symbols to frequences.
uint64_t frequency[kAlphabetSize] = {0}; // Maps symbols to frequences.
for (uint8_t symbol : data)
++frequency[symbol];
@@ -33,18 +33,12 @@ SimpleDenseCoding::SimpleDenseCoding(std::vector<uint8_t> const & data)
for (size_t i = 0; i < kAlphabetSize; ++i)
symbols[i] = i;
auto frequencyCmp = [&frequency](uint8_t lsym, uint8_t rsym)
{
return frequency[lsym] > frequency[rsym];
};
auto frequencyCmp = [&frequency](uint8_t lsym, uint8_t rsym) { return frequency[lsym] > frequency[rsym]; };
std::sort(symbols, symbols + kAlphabetSize, frequencyCmp);
for (size_t r = 0; r < kAlphabetSize; ++r)
rank[symbols[r]] = r;
auto getRank = [&rank](uint8_t sym)
{
return rank[sym];
};
auto getRank = [&rank](uint8_t sym) { return rank[sym]; };
using namespace boost::adaptors;
succinct::elias_fano_compressed_list(data | transformed(getRank)).swap(m_ranks);

View File

@@ -4,16 +4,15 @@
#include <vector>
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#endif
#include "3party/succinct/elias_fano_compressed_list.hpp"
#if defined(__clang__)
#pragma clang diagnostic pop
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#endif
#include "3party/succinct/elias_fano_compressed_list.hpp"
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
namespace coding
{

View File

@@ -6,7 +6,8 @@ namespace coding
{
/// Simple sparse vector for better memory usage.
template <class Value> class SparseVector
template <class Value>
class SparseVector
{
succinct::rs_bit_vector m_bits;
std::vector<Value> m_values;
@@ -19,30 +20,26 @@ public:
bool Has(uint64_t i) const { return m_bits[i]; }
Value const & Get(uint64_t i) const { return m_values[m_bits.rank(i)]; }
size_t GetMemorySize() const
{
return m_values.capacity() * sizeof(Value) + m_bits.size() / 8;
}
size_t GetMemorySize() const { return m_values.capacity() * sizeof(Value) + m_bits.size() / 8; }
private:
SparseVector(std::vector<Value> && values, succinct::bit_vector_builder & bitsBuilder)
: m_bits(&bitsBuilder), m_values(std::move(values))
{
}
: m_bits(&bitsBuilder)
, m_values(std::move(values))
{}
template <class T> friend class SparseVectorBuilder;
template <class T>
friend class SparseVectorBuilder;
};
template <class Value> class SparseVectorBuilder
template <class Value>
class SparseVectorBuilder
{
succinct::bit_vector_builder m_bitsBuilder;
std::vector<Value> m_values;
public:
explicit SparseVectorBuilder(size_t reserveSize = 0)
{
m_bitsBuilder.reserve(reserveSize);
}
explicit SparseVectorBuilder(size_t reserveSize = 0) { m_bitsBuilder.reserve(reserveSize); }
void PushEmpty() { m_bitsBuilder.push_back(false); }
void PushValue(Value v)
@@ -61,4 +58,4 @@ public:
}
};
} // namespace coding
} // namespace coding

View File

@@ -3,56 +3,106 @@
namespace stream
{
template <class TReader> class ReaderStream
template <class TReader>
class ReaderStream
{
TReader & m_reader;
public:
ReaderStream(TReader & reader) : m_reader(reader) {}
ReaderStream & operator>>(char & t)
{
TReader & m_reader;
public:
ReaderStream(TReader & reader) : m_reader(reader) {}
ReaderStream & operator >> (char & t) { m_reader.Read(&t, sizeof(t)); return (*this); }
ReaderStream & operator >> (uint32_t & t) { m_reader.Read(&t, sizeof(t)); return (*this); }
ReaderStream & operator >> (int32_t & t) { m_reader.Read(&t, sizeof(t)); return (*this); }
ReaderStream & operator >> (uint64_t & t) { m_reader.Read(&t, sizeof(t)); return (*this); }
ReaderStream & operator >> (int64_t & t) { m_reader.Read(&t, sizeof(t)); return (*this); }
ReaderStream & operator >> (double & t) { m_reader.Read(&t, sizeof(t)); return (*this); }
ReaderStream & operator >> (bool & t)
{
detail::ReadBool(*this, t);
return *this;
}
ReaderStream & operator >> (string & t)
{
detail::ReadString(*this, t);
return *this;
}
};
template <class TWriter> class WriterStream
m_reader.Read(&t, sizeof(t));
return (*this);
}
ReaderStream & operator>>(uint32_t & t)
{
TWriter & m_writer;
m_reader.Read(&t, sizeof(t));
return (*this);
}
ReaderStream & operator>>(int32_t & t)
{
m_reader.Read(&t, sizeof(t));
return (*this);
}
ReaderStream & operator>>(uint64_t & t)
{
m_reader.Read(&t, sizeof(t));
return (*this);
}
ReaderStream & operator>>(int64_t & t)
{
m_reader.Read(&t, sizeof(t));
return (*this);
}
ReaderStream & operator>>(double & t)
{
m_reader.Read(&t, sizeof(t));
return (*this);
}
public:
WriterStream(TWriter & writer) : m_writer(writer) {}
ReaderStream & operator>>(bool & t)
{
detail::ReadBool(*this, t);
return *this;
}
WriterStream & operator << (char t) { m_writer.Write(&t, sizeof(t)); return (*this); }
WriterStream & operator << (uint64_t t) { m_writer.Write(&t, sizeof(t)); return (*this); }
WriterStream & operator << (uint32_t t) { m_writer.Write(&t, sizeof(t)); return (*this); }
WriterStream & operator << (int64_t t) { m_writer.Write(&t, sizeof(t)); return (*this); }
WriterStream & operator << (int32_t t) { m_writer.Write(&t, sizeof(t)); return (*this); }
WriterStream & operator << (double t) { m_writer.Write(&t, sizeof(t)); return (*this); }
WriterStream & operator << (bool t)
{
detail::WriteBool(*this, t);
return (*this);
}
ReaderStream & operator>>(string & t)
{
detail::ReadString(*this, t);
return *this;
}
};
WriterStream & operator << (string const & t)
{
detail::WriteString(*this, m_writer, t);
return *this;
}
};
}
template <class TWriter>
class WriterStream
{
TWriter & m_writer;
public:
WriterStream(TWriter & writer) : m_writer(writer) {}
WriterStream & operator<<(char t)
{
m_writer.Write(&t, sizeof(t));
return (*this);
}
WriterStream & operator<<(uint64_t t)
{
m_writer.Write(&t, sizeof(t));
return (*this);
}
WriterStream & operator<<(uint32_t t)
{
m_writer.Write(&t, sizeof(t));
return (*this);
}
WriterStream & operator<<(int64_t t)
{
m_writer.Write(&t, sizeof(t));
return (*this);
}
WriterStream & operator<<(int32_t t)
{
m_writer.Write(&t, sizeof(t));
return (*this);
}
WriterStream & operator<<(double t)
{
m_writer.Write(&t, sizeof(t));
return (*this);
}
WriterStream & operator<<(bool t)
{
detail::WriteBool(*this, t);
return (*this);
}
WriterStream & operator<<(string const & t)
{
detail::WriteString(*this, m_writer, t);
return *this;
}
};
} // namespace stream

View File

@@ -1,7 +1,7 @@
#pragma once
#include "base/base.hpp"
#include "base/assert.hpp"
#include "base/base.hpp"
#include <cstdint>
#include <string>

View File

@@ -1,7 +1,7 @@
#pragma once
#include "coding/streams_common.hpp"
#include "coding/reader.hpp"
#include "coding/streams_common.hpp"
#include "coding/write_to_sink.hpp"
#include <cstdint>
@@ -10,73 +10,75 @@
namespace stream
{
template <class TReader> class SinkReaderStream
template <class TReader>
class SinkReaderStream
{
TReader & m_reader;
public:
SinkReaderStream(TReader & reader) : m_reader(reader) {}
template <typename T>
std::enable_if_t<std::is_integral<T>::value, SinkReaderStream &> operator>>(T & t)
{
TReader & m_reader;
t = ReadPrimitiveFromSource<T>(m_reader);
return (*this);
}
public:
SinkReaderStream(TReader & reader) : m_reader(reader) {}
template <typename T>
std::enable_if_t<std::is_integral<T>::value, SinkReaderStream &> operator>>(T & t)
{
t = ReadPrimitiveFromSource<T>(m_reader);
return (*this);
}
SinkReaderStream & operator >> (bool & t)
{
detail::ReadBool(*this, t);
return *this;
}
SinkReaderStream & operator >> (string & t)
{
detail::ReadString(*this, t);
return *this;
}
SinkReaderStream & operator >> (double & t)
{
static_assert(sizeof(double) == sizeof(int64_t), "");
int64_t * tInt = reinterpret_cast<int64_t *>(&t);
operator >> (*tInt);
return *this;
}
};
template <class TWriter> class SinkWriterStream
SinkReaderStream & operator>>(bool & t)
{
TWriter & m_writer;
detail::ReadBool(*this, t);
return *this;
}
public:
SinkWriterStream(TWriter & writer) : m_writer(writer) {}
SinkReaderStream & operator>>(string & t)
{
detail::ReadString(*this, t);
return *this;
}
template <typename T>
std::enable_if_t<std::is_integral<T>::value, SinkWriterStream &> operator<<(T const & t)
{
WriteToSink(m_writer, t);
return (*this);
}
SinkReaderStream & operator>>(double & t)
{
static_assert(sizeof(double) == sizeof(int64_t), "");
int64_t * tInt = reinterpret_cast<int64_t *>(&t);
operator>>(*tInt);
return *this;
}
};
SinkWriterStream & operator << (bool t)
{
detail::WriteBool(*this, t);
return (*this);
}
template <class TWriter>
class SinkWriterStream
{
TWriter & m_writer;
SinkWriterStream & operator<<(std::string const & t)
{
detail::WriteString(*this, m_writer, t);
return *this;
}
public:
SinkWriterStream(TWriter & writer) : m_writer(writer) {}
SinkWriterStream & operator << (double t)
{
static_assert(sizeof(double) == sizeof(int64_t), "");
int64_t const tInt = *reinterpret_cast<int64_t const *>(&t);
operator << (tInt);
return (*this);
}
};
}
template <typename T>
std::enable_if_t<std::is_integral<T>::value, SinkWriterStream &> operator<<(T const & t)
{
WriteToSink(m_writer, t);
return (*this);
}
SinkWriterStream & operator<<(bool t)
{
detail::WriteBool(*this, t);
return (*this);
}
SinkWriterStream & operator<<(std::string const & t)
{
detail::WriteString(*this, m_writer, t);
return *this;
}
SinkWriterStream & operator<<(double t)
{
static_assert(sizeof(double) == sizeof(int64_t), "");
int64_t const tInt = *reinterpret_cast<int64_t const *>(&t);
operator<<(tInt);
return (*this);
}
};
} // namespace stream

View File

@@ -10,8 +10,8 @@ namespace
// several data releases.
// Note that it's not feasible to increase languages number here due to current encoding (6 bit to
// store language code).
std::array<StringUtf8Multilang::Lang, StringUtf8Multilang::kMaxSupportedLanguages> const kLanguages = {{
{"default", "Name in local language", {"Any-Latin"}},
std::array<StringUtf8Multilang::Lang, StringUtf8Multilang::kMaxSupportedLanguages> const kLanguages = {
{{"default", "Name in local language", {"Any-Latin"}},
{"en", "English", {}},
{"ja", "日本語", {}},
{"fr", "Français", {}},
@@ -74,13 +74,11 @@ std::array<StringUtf8Multilang::Lang, StringUtf8Multilang::kMaxSupportedLanguage
{"mn", "Mongolian", {"Mongolian-Latin/BGN"}},
{"mk", "Македонски", {"Macedonian-Latin/BGN"}},
{"lv", "Latviešu", {}},
{"hi", "हिन्दी", {"Any-Latin"}}
}};
{"hi", "हिन्दी", {"Any-Latin"}}}};
static_assert(
kLanguages.size() == StringUtf8Multilang::kMaxSupportedLanguages,
"With current encoding we are limited to 64 languages max. And we need kLanguages.size()"
" to be exactly 64 for backward compatibility.");
static_assert(kLanguages.size() == StringUtf8Multilang::kMaxSupportedLanguages,
"With current encoding we are limited to 64 languages max. And we need kLanguages.size()"
" to be exactly 64 for backward compatibility.");
constexpr bool IsSupportedLangCode(int8_t langCode)
{
@@ -91,21 +89,20 @@ constexpr bool IsSupportedLangCode(int8_t langCode)
bool StringUtf8Multilang::IsServiceLang(std::string_view lang)
{
return lang == kLanguages[kDefaultCode].m_code
|| lang == kLanguages[kInternationalCode].m_code
|| lang == kLanguages[kAltNameCode].m_code
|| lang == kLanguages[kOldNameCode].m_code;
return lang == kLanguages[kDefaultCode].m_code || lang == kLanguages[kInternationalCode].m_code ||
lang == kLanguages[kAltNameCode].m_code || lang == kLanguages[kOldNameCode].m_code;
}
// static
static const StringUtf8Multilang::Languages allLanguages = []()
static StringUtf8Multilang::Languages const allLanguages = []()
{
StringUtf8Multilang::Languages langs;
std::copy_if(kLanguages.cbegin(), kLanguages.cend(), std::back_inserter(langs),
[](StringUtf8Multilang::Lang const & lang) { return lang.m_code != StringUtf8Multilang::kReservedLang; });
[](StringUtf8Multilang::Lang const & lang)
{ return lang.m_code != StringUtf8Multilang::kReservedLang; });
return langs;
}();
static const StringUtf8Multilang::Languages languagesWithoutService = []()
static StringUtf8Multilang::Languages const languagesWithoutService = []()
{
StringUtf8Multilang::Languages langs;
std::copy_if(allLanguages.cbegin(), allLanguages.cend(), std::back_inserter(langs),
@@ -113,7 +110,6 @@ static const StringUtf8Multilang::Languages languagesWithoutService = []()
return langs;
}();
StringUtf8Multilang::Languages const & StringUtf8Multilang::GetSupportedLanguages(bool includeServiceLangs)
{
// Asserts for generic class constants.
@@ -202,7 +198,6 @@ size_t StringUtf8Multilang::GetNextIndex(size_t i) const
size_t const sz = m_s.size();
while (i < sz && (m_s[i] & 0xC0) != 0x80)
{
if ((m_s[i] & 0x80) == 0)
i += 1;
else if ((m_s[i] & 0xFE) == 0xFE)
@@ -217,7 +212,6 @@ size_t StringUtf8Multilang::GetNextIndex(size_t i) const
i += 3;
else if ((m_s[i] & 0xC0) == 0xC0)
i += 2;
}
return i;
}
@@ -279,7 +273,7 @@ bool StringUtf8Multilang::GetString(int8_t lang, std::string_view & utf8s) const
if ((m_s[i] & kLangCodeMask) == lang)
{
++i;
utf8s = { m_s.c_str() + i, next - i };
utf8s = {m_s.c_str() + i, next - i};
return true;
}
@@ -295,10 +289,8 @@ bool StringUtf8Multilang::HasString(int8_t lang) const
return false;
for (size_t i = 0; i < m_s.size(); i = GetNextIndex(i))
{
if ((m_s[i] & kLangCodeMask) == lang)
return true;
}
return false;
}

View File

@@ -95,10 +95,7 @@ public:
static bool IsServiceLang(std::string_view lang);
// These names require separate search/street processing.
static bool IsAltOrOldName(int8_t langCode)
{
return langCode == kAltNameCode || langCode == kOldNameCode;
}
static bool IsAltOrOldName(int8_t langCode) { return langCode == kAltNameCode || langCode == kOldNameCode; }
/// @returns kUnsupportedLanguageCode if language is not recognized.
static int8_t GetLangIndex(std::string_view lang);

View File

@@ -28,9 +28,15 @@ static T * Align8Ptr(T * ptr)
return reinterpret_cast<T *>(value);
}
inline uint32_t ToAlign8(uint64_t written) { return (0x8 - (written & 0x7)) & 0x7; }
inline uint32_t ToAlign8(uint64_t written)
{
return (0x8 - (written & 0x7)) & 0x7;
}
inline bool IsAlign8(uint64_t offset) { return ToAlign8(offset) == 0; }
inline bool IsAlign8(uint64_t offset)
{
return ToAlign8(offset) == 0;
}
template <typename TWriter>
void WritePadding(TWriter & writer, uint64_t & bytesWritten)
@@ -57,8 +63,7 @@ public:
explicit MapVisitor(uint8_t const * base) : m_base(base), m_cur(m_base) {}
template <typename T>
std::enable_if_t<!std::is_trivial_v<T>, MapVisitor &> operator()(T & val,
char const * /* name */)
std::enable_if_t<!std::is_trivial_v<T>, MapVisitor &> operator()(T & val, char const * /* name */)
{
val.map(*this);
return *this;
@@ -79,7 +84,7 @@ public:
{
vec.clear();
(*this)(vec.m_size, "size");
vec.m_data = reinterpret_cast<const T *>(m_cur);
vec.m_data = reinterpret_cast<T const *>(m_cur);
m_cur = Align8Ptr(m_cur + vec.m_size * sizeof(T));
return *this;
@@ -100,16 +105,14 @@ public:
explicit ReverseMapVisitor(uint8_t * base) : m_base(base), m_cur(m_base) {}
template <typename T>
std::enable_if_t<!std::is_trivial_v<T>, ReverseMapVisitor &> operator()(T & val,
char const * /* name */)
std::enable_if_t<!std::is_trivial_v<T>, ReverseMapVisitor &> operator()(T & val, char const * /* name */)
{
val.map(*this);
return *this;
}
template <typename T>
std::enable_if_t<std::is_trivial_v<T>, ReverseMapVisitor &> operator()(T & val,
char const * /* name */)
std::enable_if_t<std::is_trivial_v<T>, ReverseMapVisitor &> operator()(T & val, char const * /* name */)
{
T * valPtr = reinterpret_cast<T *>(m_cur);
*valPtr = ReverseByteOrder(*valPtr);
@@ -120,8 +123,7 @@ public:
}
template <typename T>
ReverseMapVisitor & operator()(succinct::mapper::mappable_vector<T> & vec,
char const * /* name */)
ReverseMapVisitor & operator()(succinct::mapper::mappable_vector<T> & vec, char const * /* name */)
{
vec.clear();
(*this)(vec.m_size, "size");
@@ -151,8 +153,7 @@ public:
explicit FreezeVisitor(TWriter & writer) : m_writer(writer), m_bytesWritten(0) {}
template <typename T>
std::enable_if_t<!std::is_trivial_v<T>, FreezeVisitor &> operator()(T & val,
char const * /* name */)
std::enable_if_t<!std::is_trivial_v<T>, FreezeVisitor &> operator()(T & val, char const * /* name */)
{
ASSERT(IsAlign8(m_writer.Pos()), ());
val.map(*this);
@@ -160,8 +161,7 @@ public:
}
template <typename T>
std::enable_if_t<std::is_trivial_v<T>, FreezeVisitor &> operator()(T & val,
char const * /* name */)
std::enable_if_t<std::is_trivial_v<T>, FreezeVisitor &> operator()(T & val, char const * /* name */)
{
ASSERT(IsAlign8(m_writer.Pos()), ());
m_writer.Write(&val, sizeof(T));
@@ -199,8 +199,7 @@ public:
explicit ReverseFreezeVisitor(TWriter & writer) : m_writer(writer), m_bytesWritten(0) {}
template <typename T>
std::enable_if_t<!std::is_trivial_v<T>, ReverseFreezeVisitor &> operator()(
T & val, char const * /* name */)
std::enable_if_t<!std::is_trivial_v<T>, ReverseFreezeVisitor &> operator()(T & val, char const * /* name */)
{
ASSERT(IsAlign8(m_writer.Pos()), ());
val.map(*this);
@@ -208,8 +207,7 @@ public:
}
template <typename T>
std::enable_if_t<std::is_trivial_v<T>, ReverseFreezeVisitor &> operator()(
T & val, char const * /* name */)
std::enable_if_t<std::is_trivial_v<T>, ReverseFreezeVisitor &> operator()(T & val, char const * /* name */)
{
ASSERT(IsAlign8(m_writer.Pos()), ());
T const reversedVal = ReverseByteOrder(val);
@@ -220,8 +218,7 @@ public:
}
template <typename T>
ReverseFreezeVisitor & operator()(succinct::mapper::mappable_vector<T> & vec,
char const * /* name */)
ReverseFreezeVisitor & operator()(succinct::mapper::mappable_vector<T> & vec, char const * /* name */)
{
ASSERT(IsAlign8(m_writer.Pos()), ());
(*this)(vec.m_size, "size");

View File

@@ -37,7 +37,10 @@ class BlockedTextStorageWriter
{
public:
BlockedTextStorageWriter(Writer & writer, uint64_t blockSize)
: m_writer(writer), m_blockSize(blockSize), m_startOffset(writer.Pos()), m_blocks(1)
: m_writer(writer)
, m_blockSize(blockSize)
, m_startOffset(writer.Pos())
, m_blocks(1)
{
CHECK(m_blockSize != 0, ());
WriteToSink(m_writer, static_cast<uint64_t>(0));
@@ -110,8 +113,7 @@ private:
{
for (auto const & length : lengths)
WriteVarUint(m_writer, length);
BWTCoder::EncodeAndWriteBlock(m_writer, pool.size(),
reinterpret_cast<uint8_t const *>(pool.c_str()));
BWTCoder::EncodeAndWriteBlock(m_writer, pool.size(), reinterpret_cast<uint8_t const *>(pool.c_str()));
}
Writer & m_writer;
@@ -121,7 +123,7 @@ private:
std::vector<Block> m_blocks;
std::string m_pool; // concatenated strings
std::string m_pool; // concatenated strings
std::vector<uint64_t> m_lengths; // lengths of strings inside the |m_pool|
};
@@ -142,10 +144,7 @@ public:
};
size_t GetNumBlockInfos() const { return m_blocks.size(); }
size_t GetNumStrings() const
{
return m_blocks.empty() ? 0 : static_cast<size_t>(m_blocks.back().To());
}
size_t GetNumStrings() const { return m_blocks.empty() ? 0 : static_cast<size_t>(m_blocks.back().To()); }
BlockInfo const & GetBlockInfo(size_t blockIx) const
{
@@ -282,7 +281,7 @@ private:
struct StringInfo
{
StringInfo() = default;
StringInfo(uint64_t offset, uint64_t length): m_offset(offset), m_length(length) {}
StringInfo(uint64_t offset, uint64_t length) : m_offset(offset), m_length(length) {}
uint64_t m_offset = 0; // offset of the string inside the decompressed block
uint64_t m_length = 0; // length of the string
@@ -290,8 +289,8 @@ private:
struct CacheEntry
{
BWTCoder::BufferT m_value; // concatenation of the strings
std::vector<StringInfo> m_subs; // indices of individual strings
BWTCoder::BufferT m_value; // concatenation of the strings
std::vector<StringInfo> m_subs; // indices of individual strings
};
BlockedTextStorageIndex m_index;
@@ -303,10 +302,7 @@ template <typename Reader>
class BlockedTextStorage
{
public:
explicit BlockedTextStorage(Reader & reader) : m_reader(reader)
{
m_storage.InitializeIfNeeded(m_reader);
}
explicit BlockedTextStorage(Reader & reader) : m_reader(reader) { m_storage.InitializeIfNeeded(m_reader); }
size_t GetNumStrings() const { return m_storage.GetNumStrings(); }
std::string ExtractString(size_t stringIx) { return m_storage.ExtractString(m_reader, stringIx); }

View File

@@ -30,9 +30,10 @@ public:
DataPoint() = default;
DataPoint(uint64_t timestamp, ms::LatLon latLon, uint8_t traffic)
: m_timestamp(timestamp), m_latLon(latLon), m_traffic(traffic)
{
}
: m_timestamp(timestamp)
, m_latLon(latLon)
, m_traffic(traffic)
{}
// Uint64 should be enough for all our use cases.
// It is expected that |m_timestamp| stores time since epoch in seconds.
uint64_t m_timestamp = 0;
@@ -42,10 +43,7 @@ public:
// This field was added in Version 1 (and was the only addition).
uint8_t m_traffic = 0;
bool operator==(DataPoint const & p) const
{
return m_timestamp == p.m_timestamp && m_latLon == p.m_latLon;
}
bool operator==(DataPoint const & p) const { return m_timestamp == p.m_timestamp && m_latLon == p.m_latLon; }
};
// Serializes |points| to |writer| by storing delta-encoded points.
@@ -88,10 +86,10 @@ private:
if (!points.empty())
{
uint64_t const firstTimestamp = points[0].m_timestamp;
uint32_t const firstLat = DoubleToUint32(points[0].m_latLon.m_lat, ms::LatLon::kMinLat,
ms::LatLon::kMaxLat, kCoordBits);
uint32_t const firstLon = DoubleToUint32(points[0].m_latLon.m_lon, ms::LatLon::kMinLon,
ms::LatLon::kMaxLon, kCoordBits);
uint32_t const firstLat =
DoubleToUint32(points[0].m_latLon.m_lat, ms::LatLon::kMinLat, ms::LatLon::kMaxLat, kCoordBits);
uint32_t const firstLon =
DoubleToUint32(points[0].m_latLon.m_lon, ms::LatLon::kMinLon, ms::LatLon::kMaxLon, kCoordBits);
WriteVarUint(writer, firstTimestamp);
WriteVarUint(writer, firstLat);
WriteVarUint(writer, firstLon);
@@ -102,18 +100,17 @@ private:
ASSERT_LESS_OR_EQUAL(points[i - 1].m_timestamp, points[i].m_timestamp, ());
uint64_t const deltaTimestamp = points[i].m_timestamp - points[i - 1].m_timestamp;
uint32_t deltaLat = DoubleToUint32(points[i].m_latLon.m_lat - points[i - 1].m_latLon.m_lat,
kMinDeltaLat, kMaxDeltaLat, kCoordBits);
uint32_t deltaLon = DoubleToUint32(points[i].m_latLon.m_lon - points[i - 1].m_latLon.m_lon,
kMinDeltaLon, kMaxDeltaLon, kCoordBits);
uint32_t deltaLat = DoubleToUint32(points[i].m_latLon.m_lat - points[i - 1].m_latLon.m_lat, kMinDeltaLat,
kMaxDeltaLat, kCoordBits);
uint32_t deltaLon = DoubleToUint32(points[i].m_latLon.m_lon - points[i - 1].m_latLon.m_lon, kMinDeltaLon,
kMaxDeltaLon, kCoordBits);
WriteVarUint(writer, deltaTimestamp);
WriteVarUint(writer, deltaLat);
WriteVarUint(writer, deltaLon);
}
ASSERT_LESS_OR_EQUAL(writer.Pos() - startPos, std::numeric_limits<size_t>::max(),
("Too much data."));
ASSERT_LESS_OR_EQUAL(writer.Pos() - startPos, std::numeric_limits<size_t>::max(), ("Too much data."));
return static_cast<size_t>(writer.Pos() - startPos);
}
@@ -125,10 +122,10 @@ private:
if (!points.empty())
{
uint64_t const firstTimestamp = points[0].m_timestamp;
uint32_t const firstLat = DoubleToUint32(points[0].m_latLon.m_lat, ms::LatLon::kMinLat,
ms::LatLon::kMaxLat, kCoordBits);
uint32_t const firstLon = DoubleToUint32(points[0].m_latLon.m_lon, ms::LatLon::kMinLon,
ms::LatLon::kMaxLon, kCoordBits);
uint32_t const firstLat =
DoubleToUint32(points[0].m_latLon.m_lat, ms::LatLon::kMinLat, ms::LatLon::kMaxLat, kCoordBits);
uint32_t const firstLon =
DoubleToUint32(points[0].m_latLon.m_lon, ms::LatLon::kMinLon, ms::LatLon::kMaxLon, kCoordBits);
uint32_t const traffic = points[0].m_traffic;
WriteVarUint(writer, firstTimestamp);
WriteVarUint(writer, firstLat);
@@ -141,10 +138,10 @@ private:
ASSERT_LESS_OR_EQUAL(points[i - 1].m_timestamp, points[i].m_timestamp, ());
uint64_t const deltaTimestamp = points[i].m_timestamp - points[i - 1].m_timestamp;
uint32_t deltaLat = DoubleToUint32(points[i].m_latLon.m_lat - points[i - 1].m_latLon.m_lat,
kMinDeltaLat, kMaxDeltaLat, kCoordBits);
uint32_t deltaLon = DoubleToUint32(points[i].m_latLon.m_lon - points[i - 1].m_latLon.m_lon,
kMinDeltaLon, kMaxDeltaLon, kCoordBits);
uint32_t deltaLat = DoubleToUint32(points[i].m_latLon.m_lat - points[i - 1].m_latLon.m_lat, kMinDeltaLat,
kMaxDeltaLat, kCoordBits);
uint32_t deltaLon = DoubleToUint32(points[i].m_latLon.m_lon - points[i - 1].m_latLon.m_lon, kMinDeltaLon,
kMaxDeltaLon, kCoordBits);
uint32_t const traffic = points[i - 1].m_traffic;
WriteVarUint(writer, deltaTimestamp);
@@ -153,8 +150,7 @@ private:
WriteVarUint(writer, traffic);
}
ASSERT_LESS_OR_EQUAL(writer.Pos() - startPos, std::numeric_limits<size_t>::max(),
("Too much data."));
ASSERT_LESS_OR_EQUAL(writer.Pos() - startPos, std::numeric_limits<size_t>::max(), ("Too much data."));
return static_cast<size_t>(writer.Pos() - startPos);
}
@@ -172,20 +168,16 @@ private:
if (first)
{
lastTimestamp = ReadVarUint<uint64_t>(src);
lastLat = Uint32ToDouble(ReadVarUint<uint32_t>(src), ms::LatLon::kMinLat,
ms::LatLon::kMaxLat, kCoordBits);
lastLon = Uint32ToDouble(ReadVarUint<uint32_t>(src), ms::LatLon::kMinLon,
ms::LatLon::kMaxLon, kCoordBits);
lastLat = Uint32ToDouble(ReadVarUint<uint32_t>(src), ms::LatLon::kMinLat, ms::LatLon::kMaxLat, kCoordBits);
lastLon = Uint32ToDouble(ReadVarUint<uint32_t>(src), ms::LatLon::kMinLon, ms::LatLon::kMaxLon, kCoordBits);
result.emplace_back(lastTimestamp, ms::LatLon(lastLat, lastLon), traffic);
first = false;
}
else
{
lastTimestamp += ReadVarUint<uint64_t>(src);
lastLat +=
Uint32ToDouble(ReadVarUint<uint32_t>(src), kMinDeltaLat, kMaxDeltaLat, kCoordBits);
lastLon +=
Uint32ToDouble(ReadVarUint<uint32_t>(src), kMinDeltaLon, kMaxDeltaLon, kCoordBits);
lastLat += Uint32ToDouble(ReadVarUint<uint32_t>(src), kMinDeltaLat, kMaxDeltaLat, kCoordBits);
lastLon += Uint32ToDouble(ReadVarUint<uint32_t>(src), kMinDeltaLon, kMaxDeltaLon, kCoordBits);
result.emplace_back(lastTimestamp, ms::LatLon(lastLat, lastLon), traffic);
}
}
@@ -205,10 +197,8 @@ private:
if (first)
{
lastTimestamp = ReadVarUint<uint64_t>(src);
lastLat = Uint32ToDouble(ReadVarUint<uint32_t>(src), ms::LatLon::kMinLat,
ms::LatLon::kMaxLat, kCoordBits);
lastLon = Uint32ToDouble(ReadVarUint<uint32_t>(src), ms::LatLon::kMinLon,
ms::LatLon::kMaxLon, kCoordBits);
lastLat = Uint32ToDouble(ReadVarUint<uint32_t>(src), ms::LatLon::kMinLat, ms::LatLon::kMaxLat, kCoordBits);
lastLon = Uint32ToDouble(ReadVarUint<uint32_t>(src), ms::LatLon::kMinLon, ms::LatLon::kMaxLon, kCoordBits);
traffic = base::asserted_cast<uint8_t>(ReadVarUint<uint32_t>(src));
result.emplace_back(lastTimestamp, ms::LatLon(lastLat, lastLon), traffic);
first = false;
@@ -216,10 +206,8 @@ private:
else
{
lastTimestamp += ReadVarUint<uint64_t>(src);
lastLat +=
Uint32ToDouble(ReadVarUint<uint32_t>(src), kMinDeltaLat, kMaxDeltaLat, kCoordBits);
lastLon +=
Uint32ToDouble(ReadVarUint<uint32_t>(src), kMinDeltaLon, kMaxDeltaLon, kCoordBits);
lastLat += Uint32ToDouble(ReadVarUint<uint32_t>(src), kMinDeltaLat, kMaxDeltaLat, kCoordBits);
lastLon += Uint32ToDouble(ReadVarUint<uint32_t>(src), kMinDeltaLon, kMaxDeltaLon, kCoordBits);
traffic = base::asserted_cast<uint8_t>(ReadVarUint<uint32_t>(src));
result.emplace_back(lastTimestamp, ms::LatLon(lastLat, lastLon), traffic);
}

View File

@@ -23,9 +23,7 @@ struct Transliteration::TransliteratorInfo
std::unique_ptr<icu::Transliterator> m_transliterator;
};
Transliteration::Transliteration()
: m_inited(false), m_mode(Mode::Enabled)
{}
Transliteration::Transliteration() : m_inited(false), m_mode(Mode::Enabled) {}
Transliteration::~Transliteration()
{
@@ -64,10 +62,8 @@ void Transliteration::Init(std::string const & icuDataDir)
for (auto const & lang : StringUtf8Multilang::GetSupportedLanguages())
{
for (auto const & t : lang.m_transliteratorsIds)
{
if (m_transliterators.count(t) == 0)
m_transliterators.emplace(t, std::make_unique<TransliteratorInfo>());
}
}
// We need "Hiragana-Katakana" for strings normalization, not for latin transliteration.
@@ -103,8 +99,7 @@ bool Transliteration::Transliterate(std::string_view transID, icu::UnicodeString
auto const withDiacritic = std::string{transID}.append(";NFD;[\u02B9-\u02D3\u0301-\u0358\u00B7\u0027]Remove;NFC");
icu::UnicodeString const uTransID(withDiacritic.c_str());
it->second->m_transliterator.reset(
icu::Transliterator::createInstance(uTransID, UTRANS_FORWARD, status));
it->second->m_transliterator.reset(icu::Transliterator::createInstance(uTransID, UTRANS_FORWARD, status));
if (it->second->m_transliterator == nullptr)
LOG(LWARNING, ("Cannot create transliterator:", transID, "ICU error =", status));
@@ -132,8 +127,7 @@ bool Transliteration::TransliterateForce(std::string const & str, std::string co
return res;
}
bool Transliteration::Transliterate(std::string_view sv, int8_t langCode,
std::string & out) const
bool Transliteration::Transliterate(std::string_view sv, int8_t langCode, std::string & out) const
{
CHECK(m_inited, ());
if (m_mode != Mode::Enabled)

View File

@@ -35,8 +35,7 @@ public:
bool Transliterate(std::string_view sv, int8_t langCode, std::string & out) const;
// Transliterates |str| with |transliteratorId|, ignores mode.
bool TransliterateForce(std::string const & str, std::string const & transliteratorId,
std::string & out) const;
bool TransliterateForce(std::string const & str, std::string const & transliteratorId, std::string & out) const;
private:
struct TransliteratorInfo;

Some files were not shown because too many files have changed in this diff Show More