Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury Melnichek <melnichek@gmail.com>2010-12-30 05:30:56 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:08:55 +0300
commit22844c07f36dc4ed22896727684e6fd5047cfd8a (patch)
tree3160ade511ac2952408b258dd8c1971ca718e7ed /indexer/interval_index.hpp
parentaf425358e31328613359582fc77542d038a88181 (diff)
Get rid of most pragma pack's, because using it causes wrong alignment on GCC.
May cause build failures on MSVC, will check soon.
Diffstat (limited to 'indexer/interval_index.hpp')
-rw-r--r--indexer/interval_index.hpp46
1 files changed, 26 insertions, 20 deletions
diff --git a/indexer/interval_index.hpp b/indexer/interval_index.hpp
index e23e6e5b48..851aedf34a 100644
--- a/indexer/interval_index.hpp
+++ b/indexer/interval_index.hpp
@@ -1,7 +1,8 @@
#pragma once
#include "../coding/endianness.hpp"
-#include "../base/base.hpp"
#include "../base/assert.hpp"
+#include "../base/base.hpp"
+#include "../base/macros.hpp"
class IntervalIndexBase
{
@@ -11,15 +12,28 @@ public:
{
uint8_t m_CellIdLeafBytes;
};
+#pragma pack(pop)
- struct Index
+ class Index
{
- uint32_t m_BaseOffset;
+ public:
+ uint32_t GetBaseOffset() const { return UINT32_FROM_UINT16(m_BaseOffsetHi, m_BaseOffsetLo); }
+ void SetBaseOffset(uint32_t baseOffset)
+ {
+ m_BaseOffsetLo = UINT32_LO(baseOffset);
+ m_BaseOffsetHi = UINT32_HI(baseOffset);
+ }
+
+ private:
+ uint16_t m_BaseOffsetLo;
+ uint16_t m_BaseOffsetHi;
+ public:
uint16_t m_Count[256];
};
-#pragma pack(pop)
+ STATIC_ASSERT(sizeof(Index) == 2 * 258);
};
+// TODO: IntervalIndex shouldn't do SwapIfBigEndian for ValueT.
template <typename ValueT, class ReaderT>
class IntervalIndex : public IntervalIndexBase
{
@@ -61,7 +75,7 @@ private:
if (level > m_Header.m_CellIdLeafBytes)
{
Index index1;
- ReadIndex(index.m_BaseOffset + (cumCount * sizeof(Index)), index1);
+ ReadIndex(index.GetBaseOffset() + (cumCount * sizeof(Index)), index1);
ForEachImpl(f, b1, e1, index1, level - 1);
}
else
@@ -69,20 +83,21 @@ private:
// TODO: Use binary search here if count is very large.
uint32_t const step = sizeof(ValueT) + m_Header.m_CellIdLeafBytes;
uint32_t const count = index.m_Count[i];
- uint32_t pos = index.m_BaseOffset + (cumCount * step);
+ uint32_t pos = index.GetBaseOffset() + (cumCount * step);
vector<char> data(step * count);
char const * pData = &data[0];
m_Reader.Read(pos, &data[0], data.size());
for (uint32_t j = 0; j < count; ++j, pData += step)
// for (uint32_t j = 0; j < count; ++j, pos += step)
{
- Value value;
- value.m_CellId = 0;
- memcpy(&value, pData, step);
+ ValueT value;
+ uint32_t cellIdOnDisk = 0;
+ memcpy(&value, pData, sizeof(ValueT));
+ memcpy(&cellIdOnDisk, pData + sizeof(ValueT), m_Header.m_CellIdLeafBytes);
// m_Reader.Read(pos, &value, step);
- uint32_t const cellId = SwapIfBigEndian(value.m_CellId);
+ uint32_t const cellId = SwapIfBigEndian(cellIdOnDisk);
if (b1 <= cellId && cellId <= e1)
- f(SwapIfBigEndian(value.m_Value));
+ f(SwapIfBigEndian(value));
}
}
cumCount += index.m_Count[i];
@@ -95,20 +110,11 @@ private:
m_Reader.Read(pos, &index, sizeof(Index));
if (IsBigEndian())
{
- index.m_BaseOffset = SwapIfBigEndian(index.m_BaseOffset);
for (uint32_t i = 0; i < 256; ++i)
index.m_Count[i] = SwapIfBigEndian(index.m_Count[i]);
}
}
-#pragma pack(push, 1)
- struct Value
- {
- ValueT m_Value;
- uint32_t m_CellId;
- };
-#pragma pack(pop)
-
ReaderT m_Reader;
Header m_Header;
Index m_Level0Index;