Example #1
0
 public static <T> Aggregator<T, Vector, ?> valueCounts() {
   return Aggregator.of(
       () -> new HashMap<T, Integer>(),
       (map, t) -> map.compute(t, (v, c) -> c == null ? 1 : c + 1),
       (map) -> {
         Vector.Builder b = Vec.inferringBuilder();
         Index.Builder ib = new HashIndex.Builder();
         for (Map.Entry<T, Integer> e : map.entrySet()) {
           b.add(e.getValue());
           ib.add(e.getKey());
         }
         Vector v = b.build();
         v.setIndex(ib.build());
         return v;
       });
 }
Example #2
0
 public static <T> Aggregator<T, Vector, ?> unique() {
   return Aggregator.of(
       HashSet::new, HashSet::add, (set) -> Vec.inferringBuilder().addAll(set).build());
 }