2010-11-05 04:17:08 +02:00
|
|
|
#include <algorithm>
|
2010-10-25 05:12:47 +03:00
|
|
|
#include <cassert>
|
2010-10-28 03:17:09 +03:00
|
|
|
#include <string>
|
2010-10-25 05:12:47 +03:00
|
|
|
#include <vector>
|
|
|
|
|
2011-05-23 21:01:08 +03:00
|
|
|
#include "mph_index.h"
|
2010-10-25 05:12:47 +03:00
|
|
|
|
2010-10-28 03:17:09 +03:00
|
|
|
using std::string;
|
2010-10-25 05:12:47 +03:00
|
|
|
using std::vector;
|
2012-03-12 06:43:06 +02:00
|
|
|
using namespace cxxmph;
|
2010-10-25 05:12:47 +03:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2010-10-28 05:45:43 +03:00
|
|
|
|
|
|
|
srand(1);
|
2010-10-28 03:17:09 +03:00
|
|
|
vector<string> keys;
|
|
|
|
keys.push_back("davi");
|
|
|
|
keys.push_back("paulo");
|
|
|
|
keys.push_back("joao");
|
|
|
|
keys.push_back("maria");
|
|
|
|
keys.push_back("bruno");
|
2010-10-29 03:53:40 +03:00
|
|
|
keys.push_back("paula");
|
|
|
|
keys.push_back("diego");
|
|
|
|
keys.push_back("diogo");
|
|
|
|
keys.push_back("algume");
|
2010-10-25 05:12:47 +03:00
|
|
|
|
2011-05-23 21:01:08 +03:00
|
|
|
SimpleMPHIndex<string> mph_index;
|
2012-03-12 04:21:18 +02:00
|
|
|
if (!mph_index.Reset(keys.begin(), keys.end(), keys.size())) { exit(-1); }
|
2010-10-25 05:12:47 +03:00
|
|
|
vector<int> ids;
|
2010-10-28 03:17:09 +03:00
|
|
|
for (vector<int>::size_type i = 0; i < keys.size(); ++i) {
|
2011-05-23 21:01:08 +03:00
|
|
|
ids.push_back(mph_index.index(keys[i]));
|
2010-10-28 03:17:09 +03:00
|
|
|
cerr << " " << *(ids.end() - 1);
|
|
|
|
}
|
|
|
|
cerr << endl;
|
2010-10-25 05:12:47 +03:00
|
|
|
sort(ids.begin(), ids.end());
|
2010-10-28 03:17:09 +03:00
|
|
|
for (vector<int>::size_type i = 0; i < ids.size(); ++i) assert(ids[i] == static_cast<vector<int>::value_type>(i));
|
2012-06-09 08:47:37 +03:00
|
|
|
|
2016-02-24 21:01:18 +02:00
|
|
|
// Test serialization
|
|
|
|
vector<uint32_t> params;
|
|
|
|
dynamic_2bitset g;
|
|
|
|
vector<uint32_t> ranktable;
|
|
|
|
mph_index.swap(params, g, ranktable);
|
|
|
|
assert(mph_index.size() == 0);
|
|
|
|
mph_index.swap(params, g, ranktable);
|
|
|
|
assert(mph_index.size() == ids.size());
|
|
|
|
for (vector<int>::size_type i = 0; i < ids.size(); ++i) assert(ids[i] == static_cast<vector<int>::value_type>(i));
|
|
|
|
|
2012-06-09 08:47:37 +03:00
|
|
|
FlexibleMPHIndex<false, true, int64_t, seeded_hash<std::hash<int64_t>>::hash_function> square_empty;
|
|
|
|
auto id = square_empty.index(1);
|
|
|
|
FlexibleMPHIndex<false, false, int64_t, seeded_hash<std::hash<int64_t>>::hash_function> unordered_empty;
|
|
|
|
id ^= unordered_empty.index(1);
|
|
|
|
FlexibleMPHIndex<true, false, int64_t, seeded_hash<std::hash<int64_t>>::hash_function> minimal_empty;
|
|
|
|
id ^= minimal_empty.index(1);
|
2010-10-25 05:12:47 +03:00
|
|
|
}
|