Numeric (and accumulators)
Brian Goetz
brian.goetz at oracle.com
Mon Sep 17 08:40:01 PDT 2012
> One reason for integrating into j.u.c is that keyed versions of
> these forms would need to generalize what is now LongAdderTable
How much better (pick your metrics) is the keyed form of LAT than a CHM
of Accumulators?
> /**
> * Example: Maps from keys to Accumulators can be used to create
> Histograms
> * (frequency maps) and related tables.
> *
> * To increment a count, installing if not already present:
> * map.computeIfAbsent(key, () ->
> LongAccumulator.optimisticSum()).update(1L);
> *
> * To determine the sum for a key, it is convenient to create a
> * singleton static EMPTY_ACCUMULATOR, enabling
> * long sum = map.getValueOrDefault(key, EMPTY_ACCUMULATOR).get();
> */
>
> Any thoughts on this?
Like it. Does that mean we don't need LAT at all?
More information about the lambda-libs-spec-observers
mailing list