Hash 最小完全散列
我花了好几天的时间试图让这个库在我的系统上运行。 该库有几种生成MPHFs的算法。 我对最小散列函数的理解是,当我使用MPHF散列两个不同的键时,它们将返回两个不同的ID。 对于我生成的200万个键(整数,通过算法读取为字符串),情况似乎并非如此。我尝试了库实现的两种算法,但它们都会导致许多密钥的“ID”重复 以下是我写的:Hash 最小完全散列,hash,perfect-hash,universal-hashing,Hash,Perfect Hash,Universal Hashing,我花了好几天的时间试图让这个库在我的系统上运行。 该库有几种生成MPHFs的算法。 我对最小散列函数的理解是,当我使用MPHF散列两个不同的键时,它们将返回两个不同的ID。 对于我生成的200万个键(整数,通过算法读取为字符串),情况似乎并非如此。我尝试了库实现的两种算法,但它们都会导致许多密钥的“ID”重复 以下是我写的: #include <cmph.h> #include <iostream> #include <fstream> #include &l
#include <cmph.h>
#include <iostream>
#include <fstream>
#include <bitset>
#include <string>
#include <sstream>
#include <limits.h>
using namespace std;
int main(int argc, char** argv){
FILE *fp = fopen("keys.txt", "r");
FILE *read = fopen("keys2.txt", "r");
ofstream ids("ids2.txt");
if(!fp || !read || !ids.is_open()){
cerr<<"Failed to open the file\n";
exit(1);
}
cmph_t* hash = NULL;
// source of keys
cmph_io_adapter_t *source = cmph_io_nlfile_adapter(fp);
cmph_config_t *config = cmph_config_new(source);
cmph_config_set_algo(config, CMPH_BDZ);
hash = cmph_new(config);
cmph_config_destroy(config);
char *k = (char *)malloc(sizeof(12));
while(fgets(k, INT_MAX, read) != NULL){
string key = k;
unsigned int id = cmph_search(hash, k, (cmph_uint32)key.length());
ids<<id<<"\n";
}
cmph_destroy(hash);
cmph_io_nlfile_adapter_destroy(source);
fclose(fp);
fclose(read);
ids.close();
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main(int argc,字符**argv){
文件*fp=fopen(“keys.txt”、“r”);
文件*read=fopen(“keys2.txt”、“r”);
流ID(“ids2.txt”);
如果(!fp | | |!read | |!ids.is_open()){
cerr如果您的keys2.txt
包含不属于用于生成hash
的密钥集的密钥,则根据mphf的定义,您将获得重复的哈希值,或者可能得到超出您范围的值。由您存储用于生成hash
的所有密钥,然后验证密钥是否正确如果keys2.txt
包含的键不是用于生成哈希值的集合的一部分,那么根据mphf的定义,您将从您的范围。由您存储用于生成hash
的所有密钥,然后验证传递给cmph\u search
的密钥是否与导致cmph\u search返回哈希/id的密钥相同