Add TObjectLongMap.getOrElse(T, long) and similar methods

Issue #44 new
Karol Stasiak created an issue

It would be nice it there was a method, called for example getOrElse, that returns a given value if the key is not found.

The alternative, using no_entry_value, it less convenient, because a) it has to be either configured globally or b) it has to be specified as the third constructor parameter, after two parameters that are semantically neutral. Capacity and load factor do not influence program results, only its performance, but no_entry_value does.

The implementation could look like this (for TObjectLongMap):

public long getOrElse( Object key, long defaultValue ) {
    int index = index( key );
    return index < 0 ? defaultValue : _values[index];
}

Of course, a similar method would work for all maps.

Comments (0)

  1. Log in to comment