hashset.c icon indicating copy to clipboard operation
hashset.c copied to clipboard

strings don't really work

Open rhulha opened this issue 10 years ago • 1 comments

I found this out much too late...

int main(int argc, char* argv[])
{
    char *foo = "foo";
    char *missing = "missing";
    hashset_t set = hashset_create();

    if (set == NULL) {
        fprintf(stderr, "failed to create hashset instance\n");
        abort();
    }

    hashset_add(set, foo);
    printf("%d\n", hashset_is_member(set, foo));
    printf("%d\n", hashset_is_member(set, _strdup(foo));
}

This will print 1 0

rhulha avatar Sep 09 '15 18:09 rhulha

The red flag here should have been that you weren't asked to provide your own hash function. That means it can only possibly be hashing the pointer.

elfprince13 avatar Jan 26 '16 18:01 elfprince13