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
path: root/coding
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <bykoianko@gmail.com>2016-07-22 15:40:37 +0300
committerGitHub <noreply@github.com>2016-07-22 15:40:37 +0300
commite69836616a71a12164b92fbaaccfb4c220a4bc5f (patch)
treec55fc118e0725035c3037374a3bbcda4c9c9a78a /coding
parentb4d8c1c997989267773f4a17bc3a869620cf29da (diff)
parent120cddc6295b3a79455cc30c7aea6ff7f4fb99d9 (diff)
Merge pull request #3822 from ygorshenin/implement-centers-storage
[indexer] Implemented CentersTable.
Diffstat (limited to 'coding')
-rw-r--r--coding/coding.pro1
-rw-r--r--coding/memory_region.hpp48
-rw-r--r--coding/reader.hpp37
-rw-r--r--coding/succinct_mapper.hpp14
4 files changed, 93 insertions, 7 deletions
diff --git a/coding/coding.pro b/coding/coding.pro
index 638202e5be..c2af2eb04f 100644
--- a/coding/coding.pro
+++ b/coding/coding.pro
@@ -65,6 +65,7 @@ HEADERS += \
internal/file_data.hpp \
internal/xmlparser.hpp \
matrix_traversal.hpp \
+ memory_region.hpp \
mmap_reader.hpp \
multilang_utf8_string.hpp \
parse_xml.hpp \
diff --git a/coding/memory_region.hpp b/coding/memory_region.hpp
new file mode 100644
index 0000000000..29b92d7759
--- /dev/null
+++ b/coding/memory_region.hpp
@@ -0,0 +1,48 @@
+#pragma once
+
+#include "coding/file_container.hpp"
+
+#include "base/macros.hpp"
+
+#include "std/cstdint.hpp"
+
+class MemoryRegion
+{
+public:
+ virtual ~MemoryRegion() = default;
+
+ virtual uint64_t Size() const = 0;
+ virtual uint8_t const * ImmutableData() const = 0;
+};
+
+class MappedMemoryRegion : public MemoryRegion
+{
+public:
+ explicit MappedMemoryRegion(FilesMappingContainer::Handle && handle) : m_handle(move(handle)) {}
+
+ // MemoryRegion overrides:
+ uint64_t Size() const override { return m_handle.GetSize(); }
+ uint8_t const * ImmutableData() const override { return m_handle.GetData<uint8_t>(); }
+
+private:
+ FilesMappingContainer::Handle m_handle;
+
+ DISALLOW_COPY(MappedMemoryRegion);
+};
+
+class CopiedMemoryRegion : public MemoryRegion
+{
+public:
+ explicit CopiedMemoryRegion(vector<uint8_t> && buffer) : m_buffer(move(buffer)) {}
+
+ // MemoryRegion overrides:
+ uint64_t Size() const override { return m_buffer.size(); }
+ uint8_t const * ImmutableData() const override { return m_buffer.data(); }
+
+ inline uint8_t * MutableData() { return m_buffer.data(); }
+
+private:
+ vector<uint8_t> m_buffer;
+
+ DISALLOW_COPY(CopiedMemoryRegion);
+};
diff --git a/coding/reader.hpp b/coding/reader.hpp
index df70e03143..c96088d0ff 100644
--- a/coding/reader.hpp
+++ b/coding/reader.hpp
@@ -133,6 +133,43 @@ public:
};
// Source that reads from a reader.
+class NonOwningReaderSource
+{
+public:
+ NonOwningReaderSource(Reader const & reader) : m_reader(reader), m_pos(0) {}
+
+ void Read(void * p, size_t size)
+ {
+ m_reader.Read(m_pos, p, size);
+ m_pos += size;
+ CheckPosition();
+ }
+
+ void Skip(uint64_t size)
+ {
+ m_pos += size;
+ CheckPosition();
+ }
+
+ uint64_t Pos() const { return m_pos; }
+
+ uint64_t Size() const
+ {
+ CheckPosition();
+ return (m_reader.Size() - m_pos);
+ }
+
+private:
+ void CheckPosition() const
+ {
+ ASSERT_LESS_OR_EQUAL(m_pos, m_reader.Size(), (m_pos, m_reader.Size()));
+ }
+
+ Reader const & m_reader;
+ uint64_t m_pos;
+};
+
+// Source that reads from a reader.
template <typename TReader>
class ReaderSource
{
diff --git a/coding/succinct_mapper.hpp b/coding/succinct_mapper.hpp
index 30d413f732..e6f856bbc6 100644
--- a/coding/succinct_mapper.hpp
+++ b/coding/succinct_mapper.hpp
@@ -21,7 +21,7 @@ static T * Align8Ptr(T * ptr)
inline uint32_t ToAlign8(uint64_t written) { return (0x8 - (written & 0x7)) & 0x7; }
-inline bool IsAligned(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)
@@ -139,7 +139,7 @@ public:
typename enable_if<!is_pod<T>::value, FreezeVisitor &>::type operator()(T & val,
char const * /* name */)
{
- ASSERT(IsAligned(m_writer.Pos()), ());
+ ASSERT(IsAlign8(m_writer.Pos()), ());
val.map(*this);
return *this;
}
@@ -148,7 +148,7 @@ public:
typename enable_if<is_pod<T>::value, FreezeVisitor &>::type operator()(T & val,
char const * /* name */)
{
- ASSERT(IsAligned(m_writer.Pos()), ());
+ ASSERT(IsAlign8(m_writer.Pos()), ());
m_writer.Write(&val, sizeof(T));
m_bytesWritten += sizeof(T);
WritePadding(m_writer, m_bytesWritten);
@@ -158,7 +158,7 @@ public:
template <typename T>
FreezeVisitor & operator()(succinct::mapper::mappable_vector<T> & vec, char const * /* name */)
{
- ASSERT(IsAligned(m_writer.Pos()), ());
+ ASSERT(IsAlign8(m_writer.Pos()), ());
(*this)(vec.m_size, "size");
size_t const bytes = static_cast<size_t>(vec.m_size * sizeof(T));
@@ -187,7 +187,7 @@ public:
typename enable_if<!is_pod<T>::value, ReverseFreezeVisitor &>::type operator()(
T & val, char const * /* name */)
{
- ASSERT(IsAligned(m_writer.Pos()), ());
+ ASSERT(IsAlign8(m_writer.Pos()), ());
val.map(*this);
return *this;
}
@@ -196,7 +196,7 @@ public:
typename enable_if<is_pod<T>::value, ReverseFreezeVisitor &>::type operator()(
T & val, char const * /* name */)
{
- ASSERT(IsAligned(m_writer.Pos()), ());
+ ASSERT(IsAlign8(m_writer.Pos()), ());
T const reversedVal = ReverseByteOrder(val);
m_writer.Write(&reversedVal, sizeof(reversedVal));
m_bytesWritten += sizeof(T);
@@ -208,7 +208,7 @@ public:
ReverseFreezeVisitor & operator()(succinct::mapper::mappable_vector<T> & vec,
char const * /* name */)
{
- ASSERT(IsAligned(m_writer.Pos()), ());
+ ASSERT(IsAlign8(m_writer.Pos()), ());
(*this)(vec.m_size, "size");
for (auto const & val : vec)