Skip to content

Feature Request: Object2DoubleMap.replaceAllDouble(), .computeIfPreset() #371

@InI4

Description

@InI4

Hi,

I am doing some sparse vector calculation and found an immediate boost by switching from HashMap<Key,Double> to Object2DoubleOpenHashMap<Key>. Very nice, thank you for that! I also understand, that covering all the cases with boxing and unboxing kind of multiplies the API and you have to do balanced choices.

Having said that, I feel I missed APIs which would be convenient and helping to avoid more boxing and unboxing, i.e. gain another bit of performance. Given, one could provide an interface ObjectDouble2DoubleBiFunction<K> with a method double eval(K k, double v), it would be so nice to have methods Object2DoubleMap.replaceAllDouble(ObjectDouble2DoubleBiFunction<K> function) and Object2DoubleMap.computeIfPreset(ObjectDouble2DoubleBiFunction<K> function).

As a very simple sample, I currently feel I am kind of abusing mergeDouble() in this way:

   keySet().stream().forEach( k -> mergeDouble(k, 0.0, (v,u) -> 0.5 * v) );

but it would be nicer and should be slightly more performant to have it this way:

   replaceAllDouble( (k,v) -> 0.5 * v );

I didn't check, but I feel above suggested type of interface could have more applications.

Thank you for your attention.

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