#ifndef __CXXMPH_MPHTABLE_H__ #define __CXXMPH_MPHTABLE_H__ // Minimal perfect hash abstraction implementing the BDZ algorithm #include #include "randomly_seeded_hash.h" #include "stringpiece.h" #include "trigraph.h" namespace cxxmph { template class MPHTable { public: typedef Key key_type; typedef NewRandomlySeededHashFcn hasher; MPHTable(double c = 1.23, cmph_uint8 b = 7) : c_(c), b_(b) { } ~MPHTable(); template bool Reset(ForwardIterator begin, ForwardIterator end); cmph_uint32 index(const key_type& x) const; private: template bool Mapping(ForwardIterator begin, ForwardIterator end, vector* edges, vector queue); bool GenerateQueue(TriGraph* graph, vector* queue); void Assigning(TriGraph* graph_builder, Queue* queue); void Ranking(TriGraph* graph_builder, Queue* queue); cmph_uint32 Search(const StringPiece& key); cmph_uint32 Rank(const StringPiece& key); // Algorithm parameters cmph_uint8 b_; // Number of bits of the kth index in the ranktable double c_; // Number of bits per key (? is it right) // Values used during generation cmph_uint32 m_; // edges count cmph_uint32 n_; // vertex count cmph_uint32 k_ // kth index in ranktable, $k = log_2(n=3r)\varepsilon$ // Values used during search // Partition vertex count, derived from c parameter. cmph_uint32 r_; // The array containing the minimal perfect hash function graph. std::vector g_; // The table used for the rank step of the minimal perfect hash function std::vector ranktable_; // The selected hash function triplet for finding the edges in the minimal // perfect hash function graph. hasher hash_function_[3]; }; } // namespace cxxmph #define // __CXXMPH_MPHTABLE_H__