TIntIntHashMap getNoEntryValue() == 0

Issue #37 resolved
Valeriy Avanesov created an issue


The following code

TIntIntHashMap map = new TIntIntHashMap();
map.put(10, 0);
System.out.println(map.get(10) == map.getNoEntryValue());

prints 'true'.

Javadocs say, NoEntryValue "can be changed during construction of the collection" and it looks like it should be changed, though it is not.

Is it a bug or a feature?

Comments (7)

  1. Andre Bogus

    TIntIntHashMap has a constructor

    TIntIntHashMap( int initialCapacity, float loadFactor, int noEntryKey, int noEntryValue )

    So the only bug is perhaps in the documentation that should say "it can be set during construction" instead of "it can be changed during construction". No major bug, but it could be worth removing this possible source of misunderstanding.

  2. Rob Eden

    Yes, the no entry value can be set during construction. I'm fine with that wording change if it is less confusing.

    Comparing a return value is not a great way to see if an entry was contained in the map. Using contains() would be better. Ideally the no entry value would be set to a value your map would never contain (but don't use NaN for floats/doubles!) and then equals comparisons would work. This is dependent on your data set though.

  3. Log in to comment