Skip to content

Commit

Permalink
OpenHashMap.mergeX: Avoid double-hashing key
Browse files Browse the repository at this point in the history
Towards vigna#336
  • Loading branch information
mhansen committed Nov 18, 2024
1 parent 355d8eb commit 02c5414
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions drv/OpenHashMap.drv
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,25 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE
return value[pos] = newVal;
}

#if VALUES_PRIMITIVE && ! VALUE_CLASS_Boolean
/** {@inheritDoc} */
@Override
public VALUE_GENERIC_TYPE MERGE_VALUE(final KEY_GENERIC_TYPE k, final VALUE_GENERIC_TYPE v, METHOD_ARG_VALUE_BINARY_OPERATOR remappingFunction) {
java.util.Objects.requireNonNull(remappingFunction);
REQUIRE_VALUE_NON_NULL(v)

final int pos = find(k);
if (pos < 0) {
insert(-pos - 1, k, v);
return v;
}

final VALUE_GENERIC_TYPE newValue = remappingFunction.VALUE_OPERATOR_APPLY(value[pos], v);

return value[pos] = newValue;
}
#endif

/** {@inheritDoc} */
@Override
public VALUE_GENERIC_TYPE merge(final KEY_GENERIC_TYPE k, final VALUE_GENERIC_TYPE v, final java.util.function.BiFunction<? super VALUE_GENERIC_CLASS, ? super VALUE_GENERIC_CLASS, ? extends VALUE_GENERIC_CLASS> remappingFunction) {
Expand Down

0 comments on commit 02c5414

Please sign in to comment.