Wrong behavior of Hashing classes when adding no_entry_value

Issue #68 closed
David Chapela de la Campa created an issue

Wrong behavior of hashing classes when a value occupies the place of no_entry_value.

For instance, using TIntHashSet with the default values (no_entry_value = 0), and assuming that default size allows to store 23 elements ([0-22]): - When 23 is added, it occupies the place with index 0. - Then, other elements are added with 0 among them. - After this the set always return 'true' when contains(0) is called even after it is removed. - The remove(0) method decreases 1 the size even when 0 is not in the set.

Code example:

// Instantiate and fill
        TIntHashSet nodes = new TIntHashSet();
        nodes.add(23);
        nodes.add(0);
        nodes.add(1);
        nodes.add(2);
        // Test
        System.out.println("Size: " + nodes.size() + " Contains '0': " + nodes.contains(0)); // Size: 4 Contains '0': true
        System.out.println("Size: " + nodes.size() + " Contains '2': " + nodes.contains(2)); // Size: 4 Contains '2': true
        nodes.remove(0);
        System.out.println("Size: " + nodes.size() + " Contains '0': " + nodes.contains(0)); // Size: 3 Contains '0': true
        nodes.remove(2);
        System.out.println("Size: " + nodes.size() + " Contains '2': " + nodes.contains(2)); // Size: 2 Contains '2': false
        nodes.remove(0);
        System.out.println("Size: " + nodes.size() + " Contains 0: " + nodes.contains(0)); // Size: 1 Contains 0: true

Comments (3)

  1. Jim Davies

    I cannot repeat this. The output that I see when I run this against HEAD is:

    Size: 4 Contains '0': true
    Size: 4 Contains '2': true
    Size: 3 Contains '0': false
    Size: 2 Contains '2': false
    Size: 2 Contains 0: false
    

    If there is a specific version of Trove that you see this error with, please specify this in the bug report, preferably in the Version field.

    I'm closing this, as I cannot repeat it.

  2. Log in to comment