// cluster will modify the passed in clusters, centroid and list of pointers,
// so a copy must have been made before reaching this function.
979226
func cluster(clusters []*Cluster, distancer ClusterDistancer, threshold float64) []*Cluster {
	if len(clusters) < 2 {
		return clusters
	}

	count := 0
	for _, cluster := range clusters {
		count += len(cluster.Pointers)
	}

	clusters, found := clusterClusters(
		clusters,
		// Default initialization, TODO: better bucketing/prefiltering will greatly increase performance.
		initClusterDistances(clusters, distancer, threshold),
		distancer,
		threshold,
	)

	result := make([]*Cluster, 0, found)
	for _, cluster := range clusters {
		if cluster != nil {
			result = append(result, cluster)
		}
	}

	return result
}
228204
func (c *VFSClientset) ListClusters(options metav1.ListOptions) (*kops.ClusterList, error) {
	return c.clusters().List(options)
}
128334
func (c *MemberlistManager) clusterStats() {
	primReady := 0
	primNotReady := 0
	secReady := 0
	secNotReady := 0
	queryReady := 0
	queryNotReady := 0
	partitions := make(map[int32]int)
	for _, p := range c.members {
		if p.Primary {
			if p.IsReady() {
				primReady++
			} else {
				primNotReady++
			}
		} else if p.Mode != ModeQuery {
			if p.IsReady() {
				secReady++
			} else {
				secNotReady++
			}
		} else {
			if p.IsReady() {
				queryReady++
			} else {
				queryNotReady++
			}
		}
		for _, partition := range p.Partitions {
			partitions[partition]++
		}
	}

	totalPrimaryReady.Set(primReady)
	totalPrimaryNotReady.Set(primNotReady)
	totalSecondaryReady.Set(secReady)
	totalSecondaryNotReady.Set(secNotReady)
	totalQueryReady.Set(queryReady)
	totalQueryNotReady.Set(queryNotReady)

	totalPartitions.Set(len(partitions))
}
472829
func (c *Client) ListClusters(opts ...interface{}) (res ListClustersRes, err error) {
	err = c.transport.Request(&res, http.MethodGet, "/1/clusters", nil, call.Read, opts...)
	return
}
1261158
func (s *ModifySnapshotCopyRetentionPeriodOutput) SetCluster(v *Cluster) *ModifySnapshotCopyRetentionPeriodOutput {
	s.Cluster = v
	return s
}
485618
func (cs *CSCloud) Clusters() (cloudprovider.Clusters, bool) {
	if cs.client == nil {
		return nil, false
	}

	return nil, false
}
597011
func (s *Scheduler) Checkpoint(clusterOp ClusterOperationInstance) {
	// TODO(mberlin): Add here support for persistent checkpoints.
	s.muOpList.Lock()
	defer s.muOpList.Unlock()
	s.activeClusterOperations[clusterOp.Id] = clusterOp.Clone()
}
108619
func (s *DecreaseReplicationFactorOutput) SetCluster(v *Cluster) *DecreaseReplicationFactorOutput {
	s.Cluster = v
	return s
}
682597
func (s *UpdateServicePrimaryTaskSetInput) SetCluster(v string) *UpdateServicePrimaryTaskSetInput {
	s.Cluster = &v
	return s
}
324457
func (s *ListTasksInput) SetCluster(v string) *ListTasksInput {
	s.Cluster = &v
	return s
}
1042365
func ClusterCombiners(combiners []Combiner, threshold float64) []Combiner {
	if len(combiners) < 2 {
		return combiners
	}

	s := &state{
		Distances: initializeCombinerDistances(combiners, threshold),
		DistanceFunc: func(a, b int) float64 {
			return combiners[a].DistanceFromCombiner(combiners[b])
		},
	}

	// successively merge
	for i := 1; i < len(combiners); i++ {
		lower, higher, dist := s.MinDistance()
		if dist > threshold {
			break
		}

		// merge these two
		combiners[lower] = combiners[lower].Combine(combiners[higher])
		s.ResetDistances(lower, higher)
		combiners[higher] = nil
	}

	last := len(combiners) - 1
	for i := range combiners {
		if combiners[i] == nil {
			combiners[i] = combiners[last]
			last--
		}
	}

	return combiners[:last+1]
}
376495
func (a *Api) clusterMetrics(request *restful.Request, response *restful.Response) {
	a.processMetricRequest(core.ClusterKey(), request, response)
}
373130
func (s *CreateServiceInput) SetCluster(v string) *CreateServiceInput {
	s.Cluster = &v
	return s
}
1155408
func (s *ListClustersOutput) SetClusters(v []*string) *ListClustersOutput {
	s.Clusters = v
	return s
}
551530
func (csd CentroidSquaredDistance) ClusterDistance(c1, c2 *Cluster) float64 {
	// save the function call, is this faster?
	d0 := (c1.Centroid[0] - c2.Centroid[0])
	d1 := (c1.Centroid[1] - c2.Centroid[1])
	return d0*d0 + d1*d1
}
1109175
func NewClusterWithCentroid(centroid *geo.Point, pointers ...geo.Pointer) *Cluster {
	return &Cluster{
		Centroid: centroid.Clone(),
		Pointers: pointers,
	}
}
601292
func (s *DiscoverPollEndpointInput) SetCluster(v string) *DiscoverPollEndpointInput {
	s.Cluster = &v
	return s
}