c++ - 如何将字符串添加到杜鹃过滤器?
问题描述
我正在尝试使用来自 github 链接 https://github.com/efficient/cuckoofilter的布谷鸟过滤器代码
每当我使用数据类型字符串时,它都会给我错误 mycode:
cuckoofilter::CuckooFilter<string, 12> filter(total_items);
但每次我运行代码时都会出现这个错误
error: no match for call to ‘(const cuckoofilter::TwoIndependentMultiplyShift) (const std::_cxx11::basic_string&)’ 68 | const uint64_t hash = hasher(item);
在下一行
https://github.com/efficient/cuckoofilter/blob/master/src/cuckoofilter.h#L68
解决方案
在您的过滤器声明中,您使用的是 std::string; 类型 期望 std::string 是 ItemType
template <typename ItemType, ...> class CuckooFilter { }
但是,散列函数TwoIndependentMultiplyShift
需要uint64_t
类型键。该方法在文件https://github.com/efficient/cuckoofilter/blob/master/src/hashutil.h中。
由于类型不匹配,会发生运行时错误。在旧 C++ 标准下,这些类型在编译期间不受限制。因此,您看不到任何编译时错误。
要解决您的问题,您可能必须使用支持 std::string 的哈希函数或使用兼容的 ItemType。
C++20 引入了限制模板参数的概念,将有助于限制可用作模板参数的类型。有了这个错误将在编译时很明显。
推荐阅读
- system - torch.save(predictions, predictions_path, pickle_module=dill) 系统死机
- javascript - JS 变量相互影响导致嵌套 For 循环出现问题
- javascript - 淘汰赛JS“价值”绑定在Edge中不起作用
- python - 将列表的项目分配给图的节点
- c# - JWT:身份验证后更改用户角色
- python - PyQT clicked.connect() 动作。一个命运的大量按钮,以及多个(迭代)功能
- javascript - 当我使用history.push 时,如何从一个组件获取状态变量到另一个组件?
- java - 异步 serviceTasks 的 Activiti Job Executor 问题(activiti >= 5.17)
- reactjs - 如何使用带有 (axios/classhooks) 的 map 函数来读取 API
- html - 如何使用 bootstrap col 类创建不相等的列