00001
00002
00003
00004 #ifndef AITOOLS_INVERTEDINDEX_MP_HASH_FUNCTION_HPP
00005 #define AITOOLS_INVERTEDINDEX_MP_HASH_FUNCTION_HPP
00006
00007 #include "Externalizable.hpp"
00008 #include "Vocabulary.hpp"
00009 #include <string>
00010 #include <cmph.h>
00011
00012 namespace bfs = boost::filesystem;
00013
00014 namespace aitools {
00015 namespace invertedindex {
00016
00031 class MPHashFunction : public Externalizable {
00032
00033 public:
00034
00038 enum Algorithm
00039 {
00040 BMZ, CHM, BRZ, FCH, BDZ, CHD
00041 };
00042
00043 public:
00044
00048 MPHashFunction();
00049
00053 ~MPHashFunction();
00054
00055 public:
00056
00057 void create(const bfs::path& vocabulary, Algorithm algorithm = BDZ)
00058 throw (std::invalid_argument, std::runtime_error);
00059
00060 void create(const Vocabulary& vocabulary, Algorithm algorithm = BDZ)
00061 throw (std::runtime_error);
00062
00063 uint32_t hash(const std::string& key) const;
00064
00065 void load(const bfs::path& path) throw (std::invalid_argument);
00066
00067 void save(const bfs::path& path) throw (std::invalid_argument);
00068
00069 uint32_t size() const;
00070
00071 private:
00072
00073 void clear_();
00074 void create_(Algorithm algorithm, cmph_io_adapter_t* source)
00075 throw (std::runtime_error);
00076
00077 private:
00078
00079 cmph_t* mphf_;
00080
00081 };
00082
00083 }
00084 }
00085
00086 #endif // AITOOLS_INVERTEDINDEX_MP_HASH_FUNCTION_HPP