Skip to content

MapSetMultiMap performance degradation when backed by special sets#150

Description

@jjppp

馃摑 Overall Description

A MapSetMultiMap<K, V> can be backed by different user-defined sets to offer functionality similar to but cleaner than a Map<K, Set<V>>, which is quite nice.

However, the Set<V> get(K key) method of the class MapSetMultiMap will return a set of type UnmodifiableSet<V>, instead of using the set generated by the setFactory.

public Set<V> get(@Nonnull K key) {
Objects.requireNonNull(key, NULL_KEY);
Set<V> values = map.get(key);
return values == null ? Set.of() :
Collections.unmodifiableSet(values);
}

For cases when setFactory returns IndexerBitSets and operations like addAll are performed, this implementation will cause severe performance degradation as operations like addAll are slow when the type of the two sets are different.

public boolean addAll(@Nonnull Collection<? extends E> c) {
if (c instanceof GenericBitSet s) {
checkContext(s);
return bitSet.or(s.bitSet);
} else {
return super.addAll(c);
}
}

馃幆 Expected Behavior

return a set of the same type of the sets generated by setFactory

馃悰 Current Behavior

Collections.unmodifiableSet() is used

馃攧 Reproducible Example

No response

鈿欙笍 Tai-e Arguments

馃攳 Click here to see Tai-e Options
{{The content of 'output/options.yml' file}}
馃攳 Click here to see Tai-e Analysis Plan
{{The content of 'output/tai-e-plan.yml' file}}

馃摐 Tai-e Log

馃攳 Click here to see Tai-e Log
{{The content of 'output/tai-e.log' file}}

鈩癸笍 Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions