1
Fork 0
turbonss/cxxmph/mphtable.h

45 lines
1.1 KiB
C
Raw Normal View History

2010-09-10 10:07:06 +03:00
// Minimal perfect hash abstraction implementing the BDZ algorithm
2010-10-05 17:51:17 +03:00
#include <vector>
2010-09-10 10:07:06 +03:00
#include "trigraph.h"
2010-06-28 22:01:18 +03:00
2010-10-05 17:51:17 +03:00
template <class Key, class NewRandomlySeededHashFcn = __gnu_cxx::hash<Key> >
2010-06-28 22:01:18 +03:00
class MPHTable {
public:
typedef Key key_type;
2010-10-05 17:51:17 +03:00
typedef NewRandomlySeededHashFcn hasher;
2010-09-10 10:07:06 +03:00
MPHTable();
2010-06-28 22:01:18 +03:00
~MPHTable();
2010-10-05 17:51:17 +03:00
template <class ForwardIterator>
2010-09-10 10:07:06 +03:00
bool Reset(ForwardIterator begin, ForwardIterator end);
2010-06-28 22:01:18 +03:00
cmph_uint32 index(const key_type& x) const;
private:
2010-10-05 17:51:17 +03:00
typedef std::vector<cmph_uint32> Queue;
template<class ForwardIterator>
struct TableBuilderState {
ForwardIterator begin;
ForwardIterator end;
Queue edges_queue;
TriGraph graph_builder;
double c;
cmph_uint32 m;
cmph_uint32 n;
cmph_uint32 k;
cmph_uint32 ranktablesize;
};
2010-09-10 10:07:06 +03:00
int GenerateQueue(
cmph_uint32 nedges, cmph_uint32 nvertices,
TriGraph* graph, Queue* queue);
2010-10-05 17:51:17 +03:00
void Assigning(TriGraph* graph, Queue* queue);
void Ranking(TriGraph* graph, Queue* queue);
cmph_uint32 Search(const StringPiece& key);
cmph_uint32 Rank(const StringPiece& key);
2010-06-28 22:01:18 +03:00
2010-10-05 17:51:17 +03:00
std::vector<ConnectedEdge> graph_;
2010-06-28 22:01:18 +03:00
};