00001 /* Copyright (C) 2010 webis.de 00002 * All rights reserved. 00003 */ 00004 #ifndef AITOOLS_INVERTEDINDEX_STORAGE_BUILDER_HPP 00005 #define AITOOLS_INVERTEDINDEX_STORAGE_BUILDER_HPP 00006 00007 #include "Quantile.hpp" 00008 #include "Vocabulary.hpp" 00009 #include "NonCopyable.hpp" 00010 #include "PostlistWriter.hpp" 00011 #include <tr1/unordered_map> 00012 #include <utility> 00013 #include <vector> 00014 00015 namespace aitools { 00016 namespace invertedindex { 00017 00027 class StorageBuilder : public NonCopyable { 00028 00029 public: // nested types 00030 00034 typedef std::pair<uint16_t, uint32_t> Location; 00035 00036 private: // nested types 00037 00038 typedef PostlistWriter::SharedPointer Writer; 00039 typedef std::tr1::unordered_map<std::string, Location> LocationMap; 00040 typedef std::tr1::unordered_map<std::string, Quantile> QuantileMap; 00041 typedef std::vector<Writer> WriterVector; 00042 00043 public: // class data 00044 00045 static const std::string data_file; 00046 static const std::string mphf_file; 00047 static const std::string vocab_file; 00048 static const std::string storage_file; 00049 static const std::string quantile_file; 00050 00051 static const size_t max_file_size = 1024 * 1024 * 1024; // 1 GB 00052 00053 public: // c'tor / d'tor 00054 00055 StorageBuilder(); 00056 00057 ~StorageBuilder(); 00058 00059 public: // methods 00060 00061 bool is_open() const; 00062 00063 const bfs::path& directory() const; 00064 00065 void close() throw (std::invalid_argument); 00066 00067 void open(const bfs::path& directory) throw (std::invalid_argument); 00068 00069 void put(const std::string& key, Iterator::SharedPointer iterator) 00070 throw (std::runtime_error); 00071 00072 void put(const std::string& key, const Quantile& quantile) 00073 throw (std::runtime_error); 00074 00075 const Vocabulary& vocabulary() const; 00076 00077 private: // member 00078 00079 bfs::path directory_; 00080 Vocabulary vocabulary_; 00081 LocationMap locations_; 00082 QuantileMap quantiles_; 00083 WriterVector writers_; 00084 00085 }; 00086 00087 } // namespace invertedindex 00088 } // namespace aitools 00089 00090 #endif // AITOOLS_INVERTEDINDEX_STORAGE_BUILDER_HPP