Coder Social home page Coder Social logo

Problem in Adding char* about cuckoofilter HOT 12 OPEN

efficient avatar efficient commented on July 25, 2024 3
Problem in Adding char*

from cuckoofilter.

Comments (12)

dnbaker avatar dnbaker commented on July 25, 2024 2

Here's the patch I've made. It compiles -- I'm not sure if it fixes the problem, as I haven't built any test cases. Want to give it a whirl, srbehera?

from cuckoofilter.

chialunwu avatar chialunwu commented on July 25, 2024

The reason you cannot find the existing items is because you have to clear the char array to make sure the chars behind '\0' are the same.
ex:
char[31] str;
bzero(str, 31);

from cuckoofilter.

srbehera avatar srbehera commented on July 25, 2024

It is still not working !
This is my code

CuckooFilter<string, 12> filter(total_items);
string line;
while(getline(inp, line))
{
    if(filter.Contain(line) == cuckoofilter::Ok)
        cout<<"Found:"<<line<<endl;
    else
        filter.Add(line);
}

from cuckoofilter.

chialunwu avatar chialunwu commented on July 25, 2024

I think no char* and string now. It needs primative and non-pointer type because there is sizeof(item) in the code. So sizeof(string) will go wrong.

from cuckoofilter.

apc999 avatar apc999 commented on July 25, 2024

@bingo4508 you are right. currently the way to calculate hash index is here .
As a result, the string is converted into char*, getting into problems.

@srbehera for now string is not supported but only primary types (where sizeof(item) makes sense). I planed to support string but still not able to find time doing that :(

from cuckoofilter.

srbehera avatar srbehera commented on July 25, 2024

@bingo4508 @apc999 Got it !! Thanks !!

from cuckoofilter.

dnbaker avatar dnbaker commented on July 25, 2024

Would a templated function that defaulted to sizeof() for other structs/types with a specialization for std::string (using std::string.c_str() rather than (const char *) and std::string.size() rather than sizeof) be a quick fix?

from cuckoofilter.

apc999 avatar apc999 commented on July 25, 2024

yes, I think so.
Deaniel, feel free to submit a patch.
otherwise, I will probably add one later .

best,

On Wed, Apr 27, 2016 at 5:31 PM, Daniel Baker [email protected]
wrote:

Would a templated function that defaulted to sizeof() for other
structs/types with a specialization for std::string (using
std::string.c_str() rather than (const char *) and std::string.size()
rather than sizeof) be a quick fix?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#2 (comment)

from cuckoofilter.

srbehera11 avatar srbehera11 commented on July 25, 2024

Daniel, it is not working for string.
Here is the simple code I was testing

int main(int argc, char** argv) {
    CuckooFilter<string, 12> filter2(total_items);
    srand (time(NULL));
    ifstream inp;
    inp.open("test.txt");
    string line;
    int c1 = 0;
    int i = 0;
    while(getline(inp, line))
    {
      cout<<line<<endl;
      if(filter2.Contain(line) == cuckoofilter::Ok){
        cout<<"Found:"<<line<<endl;
        c++;
      }
      else{
        filter2.Add(line);
      }
      i++;
    }
    cout<< "c = "<< c <<endl;
    cout<< "i = "<< i <<endl;
    inp.close();

Where test.txt has following entries

AAA
BBB
CCC
AAA
CCC
DDD
XYZ
CCC
XYZ
AAA

from cuckoofilter.

dnbaker avatar dnbaker commented on July 25, 2024

Is there any output? What does it do?

from cuckoofilter.

srbehera11 avatar srbehera11 commented on July 25, 2024

The program was putting the strings in the filter. If it is already there, it was printing "Found". The following output shows that it only puts the first string and then says "Found" all other strings.

AAA
BBB
Found:BBB
CCC
Found:CCC
AAA
Found:AAA
CCC
Found:CCC
DDD
Found:DDD
XYZ
Found:XYZ
CCC
Found:CCC
XYZ
Found:XYZ
AAA
Found:AAA
c1=9
i=10

from cuckoofilter.

siara-cc avatar siara-cc commented on July 25, 2024

I faced the same issue and it looks like according to the implementation the first parameter can only be uint64_t.
So I used following code:

std::string mystring = "Hello World";
cuckoofilter::CuckooFilter<size_t, 12> test(1000);
test.Add(CityHash64(mystring.c_str(), mystring.length()));

CitiHash64 can be found in src/City.h in https://github.com/aappleby/smhasher

from cuckoofilter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.