c++ - How to add strings to cuckoo filter? -
i running modified version of example provided @ cuckoo filter repository: https://github.com/efficient/cuckoofilter/blob/master/example/test.cc
i want add strings cuckoo filter. although string added when check if exists in filter, returns false. can point out what's wrong approach?
size_t total_items = 1000000; cuckoofilter<string, 12> filter(total_items); // insert items cuckoo filter string temp1 = "sample"; if (filter.add(temp1) != cuckoofilter::ok) { cout<<"not added"<<endl; } // check if inserted items in filter string temp2 = "sample"; assert(filter.contain(temp2) == cuckoofilter::ok); the assertion should true false in case. why?
a quick glance @ source of https://github.com/efficient/cuckoofilter/blob/master/src/cuckoofilter.h#l65 reveals uses function
inline void generateindextaghash(const itemtype &item, size_t* index, uint32_t* tag) const { std::string hashed_key = hashutil::sha1hash( (const char*) &item, sizeof(item) ); // ... rest skipped brevity } to generate initial index , fingerprint (tag) of item. problem hashes actual object passed. simplify, this:
// filter.add(temp1) inside hashutil::sha1hash((const char*) &temp1, sizeof(temp1)); // filter.contain(temp2) inside hashutil::sha1hash((const char*) &temp2, sizeof(temp2)); basically, hashes 2 different objects which, expected, generate different hashes , map different buckets.
for work in case need call hashutil::sha1hash() in way hashes actual string data, is:
// should hashutil::sha1hash( temp1.c_str(), // <-- notice pass pointer actual character data rather pointer instance of std::string() temp1.length() ); hashutil::sha1hash( temp2.c_str(), // <-- notice pass pointer actual character data rather pointer instance of std::string() temp2.length() ); this should answer why? question.
can point out what's wrong approach?
there nothing wrong approach per-se doesn't work might've expected, because library not support such use case.
Comments
Post a Comment