Skip to content

Duplication bug #28

Description

@zestyBug

Hi, I tried working with your library to build my own custom version and I think have found a small bug.
in a rare cases where there is a collision in hash function. for instance A and B.
then following code may result having duplicated items in the array.

tgc_add(gc, A, size, flags, dtor);
tgc_add(gc, B, size, flags, dtor);

tgc_add(gc, A, size, flags, dtor);
tgc_add(gc, B, size, flags, dtor);

// after sweep phase, dtor is called 4 times instead of 2.

I know it is never intended to accept such inputs. I needed this functionality.

I'm not sure about functionality of tgc_probe, but in this case changing this line

tgc/tgc.c

Line 46 in 81ce102

if (j >= p) {

to

 if (j > p) { 

solves this problem and saves performance by not moving items with same hash value.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions