-
Notifications
You must be signed in to change notification settings - Fork 3
/
accumulator.go
37 lines (33 loc) · 1.83 KB
/
accumulator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package sif
// An Accumulator is an alternative reduction technique, which siphons data from
// Partitions into a custom data structure. The result is itself an Accumulator,
// rather than a series of Partitions, thus ending the job (no more operations may
// be performed against the data). The advantage, however, is full control over the
// reduction technique, which can yield substantial performance benefits.
// As reduction is performed locally on all workers, then worker results are
// all reduced on the Coordinator, Accumulators are best utilized for smaller
// results. Distributed reductions via Reduce() are more efficient when
// there is a large reduction result (i.e. a large number of buckets).
type Accumulator interface {
Accumulate(row Row) error // Accumulate adds a row to this Accumulator
Merge(o Accumulator) error // Merge merges another Accumulator into this one
ToBytes() ([]byte, error) // ToBytes serializes this Accumulator
FromBytes(buf []byte) (Accumulator, error) // FromBytes produces a *new* Accumulator from serialized data
}
// GenericAccumulator holds the generic methods of Accumulator, allowing
// typed access to the internal (generally final) value of the Accumulator
type GenericAccumulator[T any] interface {
Accumulator
Value() T // Value returns the accumulated value of this Accumulator
}
// AccumulatorFactory produces a Accumulators
type AccumulatorFactory interface {
New() Accumulator
}
// GenericAccumulatorFactory is the generic version of Accumulator,
// indicating the value type of the Accumulator and providing
// access to its value
type GenericAccumulatorFactory[T any] interface {
AccumulatorFactory
Value(Accumulator) (T, error) // retrieves the value from the given accumulator or an error if the given accumulator does not match the expected type
}