diff options
author | Yuri Gorshenin <y@maps.me> | 2015-02-11 13:45:23 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:37:26 +0300 |
commit | fca244a024176a1543ba859cc8d5bc6958cc0f72 (patch) | |
tree | 9b3aa42229974b22e9c5e46dec92856999c3e98f /indexer/features_offsets_table.hpp | |
parent | a2524383f6299b0deedbcf4a748311143a4d4b5f (diff) |
Added FeaturesOffsetsTable, which maps feature's index to its offset in a MWM file.
Diffstat (limited to 'indexer/features_offsets_table.hpp')
-rw-r--r-- | indexer/features_offsets_table.hpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/indexer/features_offsets_table.hpp b/indexer/features_offsets_table.hpp new file mode 100644 index 0000000000..c4dbb1c8ea --- /dev/null +++ b/indexer/features_offsets_table.hpp @@ -0,0 +1,69 @@ +#pragma once + +#include "../3party/succinct/elias_fano.hpp" +#include "../3party/succinct/mapper.hpp" +#include "../coding/file_container.hpp" +#include "../std/stdint.hpp" +#include "../std/unique_ptr.hpp" +#include "../std/vector.hpp" + +namespace feature +{ + class FeaturesOffsetsTable + { + public: + class Builder + { + public: + Builder(); + + ~Builder(); + + void PushOffset(uint64_t offset); + + inline uint64_t size() const + { + return static_cast<uint64_t>(m_offsets.size()); + } + + private: + friend class FeaturesOffsetsTable; + + vector<uint64_t> m_offsets; + }; + + static unique_ptr<FeaturesOffsetsTable> Build(Builder & builder); + + static unique_ptr<FeaturesOffsetsTable> Load( + FilesMappingContainer const & container); + + ~FeaturesOffsetsTable(); + + FeaturesOffsetsTable(FeaturesOffsetsTable const &) = delete; + FeaturesOffsetsTable const & operator=(FeaturesOffsetsTable const &) = + delete; + + void Save(FilesContainerW & container); + + uint64_t GetFeatureOffset(size_t index) const; + + inline uint64_t size() const + { + return m_table.num_ones(); + } + + inline uint64_t byte_size() + { + return succinct::mapper::size_of(m_table); + } + + private: + FeaturesOffsetsTable(succinct::elias_fano::elias_fano_builder & builder); + + FeaturesOffsetsTable(FilesMappingContainer::Handle && handle); + + succinct::elias_fano m_table; + + FilesMappingContainer::Handle m_handle; + }; +} // namespace feature |