eclipse-collections icon indicating copy to clipboard operation
eclipse-collections copied to clipboard

EMPTY_VALUE should be settable for Map

Open keeper3000 opened this issue 10 years ago • 4 comments

When using classes such as ObjectDoubleHashMap we should be able to set the EMPTY_VALUE upon construction. In our situation, Zero is a perfectly valid double value and does not properly differentiate between a valid or invalid key without explictly checking containsKey. Which is expensive!

We would like to be able to set this to NaN which was supported by Trove collections.

keeper3000 avatar Aug 04 '16 18:08 keeper3000

It looks like this would be exceptionally simple to impliment... This is a make or break for us.

Thank you!

keeper3000 avatar Aug 04 '16 18:08 keeper3000

You're expected to use the getIfAbsent method in your case. E.g. getIfAbsent(someKey, Double.NaN). We'd prefer not to add 8 bytes to every map when a lighter solution exists.

gs-rezaem avatar Aug 05 '16 13:08 gs-rezaem

Also, if you are so performance sensitive that contains() is too much of an overhead, you might be interested in several other methods in the API that make working with *DoubleMap's faster and more productive. Some of my favorites:

public double addToValue(K key, double toBeAdded) public double updateValue(K key, double initialValueIfAbsent, DoubleToDoubleFunction function) public <P> double getIfAbsentPutWith(K key, DoubleFunction<? super P> function, P parameter)

gs-rezaem avatar Aug 05 '16 13:08 gs-rezaem

Oh thats perfect!! I overlooked it because I saw it was "Static" and was more familiar with Trove that supplied it as part of construction. Thank you!

keeper3000 avatar Aug 05 '16 14:08 keeper3000