Possible bug in KTypeHashSet.add(KType key)

21 views
Skip to first unread message

Olivier G.

unread,
Dec 11, 2016, 1:57:31 PM12/11/16
to High Performance Primitive Collections for Java
Hello,

First thanks for this great library.
I think I found a bug in code or in JavaDoc: JavaDoc for ObjectHashSet.add(KType key) says when there is an already existing element with same key, it is replaced with the one provided in argument. But it is not the case.

I made a test to reproduce the problem (using JUnit and HPPC 0.7.2).

@Test
public void add() {
ObjectHashSet<Integer> set = new ObjectHashSet<Integer>();

set.add(new Integer(0));

Integer newKey = new Integer(0);
set.add(newKey);

Integer keyInSet = set.iterator().next().value;

assertSame(newKey, keyInSet);  // <-- Fails.
}

The key is not replaced, and KTypeHashSet source code seems to confirm that.

Regards,
Olivier

Dawid Weiss

unread,
Dec 11, 2016, 2:30:28 PM12/11/16
to java-high-performance-primitive-collections
Thanks Olivier, this looks like a bug. I'll take a look.

Dawid
> --
> You received this message because you are subscribed to the Google Groups
> "High Performance Primitive Collections for Java" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
> java-high-performance-primi...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Dawid Weiss

unread,
Dec 12, 2016, 4:06:31 AM12/12/16
to java-high-performance-primitive-collections
I fixed this in the documentation, Olivier. The behavior here should
be I think consistent with HashMap (leaving existing entry in the
set).

http://issues.carrot2.org/browse/HPPC-164

Olivier G.

unread,
Dec 19, 2016, 7:38:25 AM12/19/16
to High Performance Primitive Collections for Java
I think you meant: the behavior of HPPC KTypeSet.add(E) should be consistent with JCF Set.add(E) (that is leave the set unchanged).
Because for hash maps, JCF and HPPC are already consistent: put(K,V) replaces the existing value and returns the old one.

Olivier
>> For more options, visit https://groups.google.com/d/optout.
>> For more options, visit https://groups.google.com/d/optout.

Dawid Weiss

unread,
Dec 19, 2016, 8:02:56 AM12/19/16
to java-high-performance-primitive-collections
Yup, exactly.

D.
>> >> java-high-performance-primi...@googlegroups.com.
>> >> java-high-performance-primi...@googlegroups.com.
>> >> java-high-performance-primi...@googlegroups.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "High Performance Primitive Collections for Java" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
> java-high-performance-primi...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages