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:
authorYuri Gorshenin <y@maps.me>2016-07-18 16:39:49 +0300
committerYuri Gorshenin <y@maps.me>2016-07-22 14:08:44 +0300
commit32af6db6fd63955565a2b26533eb9015ec2f1b56 (patch)
treeb5434fc9024c6039e3bc888e7c31ac253ec5b14e /coding
parent9c128b3a9f250acefae6c213e6410b9a0cd2368c (diff)
[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.hpp46
-rw-r--r--coding/succinct_mapper.hpp14
4 files changed, 102 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..b7a1994d95
--- /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:
+ 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:
+ 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..6c8ed98cb3 100644
--- a/coding/reader.hpp
+++ b/coding/reader.hpp
@@ -133,6 +133,52 @@ 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);
+ }
+
+ // unique_ptr<Reader> SubReader(uint64_t size)
+ // {
+ // uint64_t const pos = m_pos;
+ // Skip(size);
+ // return m_reader.SubReader(pos, size);
+ // }
+
+ // unique_ptr<Reader> SubReader() { return SubReader(Size()); }
+
+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)