@@ -23,15 +23,10 @@ type Entry interface {
2323}
2424
2525// BatchFactory partitions Entry values by their leaseholder relative to a fixed host
26- // node. Construct one with NewBatchFactory, then call Batch.
27- type BatchFactory [E Entry ] struct { host node.Key }
28-
29- // NewBatchFactory returns a BatchFactory that treats host as the local node: Batch
30- // routes entries leased to host into the gateway bucket and all other leased entries to
31- // peers.
32- func NewBatchFactory [E Entry ](host node.Key ) BatchFactory [E ] {
33- return BatchFactory [E ]{host : host }
34- }
26+ // node, treating that host as the local node: Batch routes entries leased to it into the
27+ // gateway bucket and all other leased entries to peers. Construct one by converting a
28+ // host node.Key, e.g. BatchFactory[E](host), then call Batch.
29+ type BatchFactory [E Entry ] node.Key
3530
3631// Batch is the result of partitioning a set of Entry values by leaseholder. Every input
3732// entry appears in exactly one of the three buckets.
@@ -50,12 +45,13 @@ type Batch[E Entry] struct {
5045// grouped into Peers by their leaseholder key. The relative order of entries is
5146// preserved within each bucket.
5247func (f BatchFactory [E ]) Batch (entries []E ) Batch [E ] {
48+ host := node .Key (f )
5349 b := Batch [E ]{Peers : make (map [node.Key ][]E )}
5450 for _ , entry := range entries {
5551 lease := entry .Lease ()
5652 if lease .IsFree () {
5753 b .Free = append (b .Free , entry )
58- } else if lease == f . host {
54+ } else if lease == host {
5955 b .Gateway = append (b .Gateway , entry )
6056 } else {
6157 b .Peers [lease ] = append (b .Peers [lease ], entry )
0 commit comments