fastutil icon indicating copy to clipboard operation
fastutil copied to clipboard

Add collectors for Maps

Open shawjef3 opened this issue 3 years ago • 5 comments

This adds collectors for Stream to fastutil Maps.

Future improvements would be to investigate supporting primitive streams (e.g. IntStream) and improving the type signature for collectors where char is the key or value. When char is the key, the functions are for int. When char is the value, the functions are for Object.

~~Also there is boxing that could be avoided using more specialized function types, like Int2IntFunction instead of ToIntFunction<Integer>.~~

shawjef3 avatar Jun 24 '21 15:06 shawjef3

I won't be able to look at this for a couple of weeks as I'll be travelling. Did you use some of the infrastructure for primitive functions (look for PRIMITIVE_FUNCTION in gencsources.sh)?

vigna avatar Jun 28 '21 07:06 vigna

I tried to use JDK_PRIMITIVE_FUNCTION, but ran into many places it didn't fit. For instance, in Byte2BooleanMaps, the collector needs Object2ByteFunction<T> for the keys, and Predicate<T> for the values. However, JDK_PRIMITIVE_FUNCTION gives IntPredicate, which isn't applicable to the collector.

shawjef3 avatar Jul 06 '21 17:07 shawjef3

@vigna just a reminder to get eyes on this.

shawjef3 avatar Aug 27 '21 15:08 shawjef3

Ahem, I know I'm late, but I'm on vacation now. I'll be back to work in full in a couple of weeks.

vigna avatar Aug 30 '21 08:08 vigna

So, the way we did that for other containers is quite different—see, e.g., toSet() in OpenHashSet.drv. It would be better to try to follow the same scheme.

vigna avatar Feb 04 '22 11:02 vigna