func Greedy(plan *plan) *workPlan {
	remaining := make(map[string]map[string]repositoryWork)
	for name, registry := range plan.registries {
		work := make(map[string]repositoryWork)
		remaining[name] = work
		for repoName, repository := range registry.repositories {
			work[repoName] = repositoryWork{
				registry:   registry,
				repository: repository,
			}
		}
	}

	alreadyUploaded := make(map[string]sets.String)

	var phases []phase
	for len(remaining) > 0 {
		var independent []repositoryWork
		for name, registry := range remaining {
			// we can always take any repository that has no shared layers
			if found := takeIndependent(registry); len(found) > 0 {
				independent = append(independent, found...)
			}
			exists := alreadyUploaded[name]
			if exists == nil {
				exists = sets.NewString()
				alreadyUploaded[name] = exists
			}

			// take the most shared repositories and any that don't overlap with it
			independent = append(independent, takeMostSharedWithoutOverlap(registry, exists)...)
			if len(registry) == 0 {
				delete(remaining, name)
			}
		}
		for _, work := range independent {
			repositoryPlanAddAllExcept(work.repository, alreadyUploaded[work.registry.name], nil)
		}
		phases = append(phases, phase{independent: independent})
	}
	work := &workPlan{
		phases: phases,
	}
	work.calculateStats()
	return work
}
// Greedy turns a plan into parallizable work by taking one repo at a time. It guarantees
// that no two phases in the plan attempt to upload the same blob at the same time. In the
// worst case each phase has one unit of work.
Greedy turns a plan into parallizable work by taking one repo at a time. It guarantees
that no two phases in the plan attempt to upload the same blob at the same time. In the
worst case each phase has one unit of work.
// Greedy turns a plan into parallizable work by taking one repo at a time . It guarantees // that no two phases in the plan attempt to upload the same blob at the same time . In the // worst case each phase has one unit of work .
func Greedy(plan *plan) *workPlan {
	remaining := make(map[string]map[string]repositoryWork)
	for name, registry := range plan.registries {
		work := make(map[string]repositoryWork)
		remaining[name] = work
		for repoName, repository := range registry.repositories {
			work[repoName] = repositoryWork{
				registry:   registry,
				repository: repository,
			}
		}
	}
	alreadyUploaded := make(map[string]sets.String)
	var phases []phase
	for len(remaining) > 0 {
		var independent []repositoryWork
		for name, registry := range remaining {
			if found := takeIndependent(registry); len(found) > 0 {
				independent = append(independent, found...)
			}
			exists := alreadyUploaded[name]
			if exists == nil {
				exists = sets.NewString()
				alreadyUploaded[name] = exists
			}
			independent = append(independent, takeMostSharedWithoutOverlap(registry, exists)...)
			if len(registry) == 0 {
				delete(remaining, name)
			}
		}
		for _, work := range independent {
			repositoryPlanAddAllExcept(work.repository, alreadyUploaded[work.registry.name], nil)
		}
		phases = append(phases, phase{independent: independent})
	}
	work := &workPlan{
		phases: phases,
	}
	work.calculateStats()
	return work
}
func Greedy ( plan * plan ) * workPlan { remaining := make ( map [ string ] map [ string ] repositoryWork ) for name , registry := range plan . registries { work := make ( map [ string ] repositoryWork ) remaining [ name ] = work for repoName , repository := range registry . repositories { work [ repoName ] = repositoryWork { registry : registry , repository : repository , } } } alreadyUploaded := make ( map [ string ] sets . String ) var phases [ ] phase for len ( remaining ) > 0 { var independent [ ] repositoryWork for name , registry := range remaining { if found := takeIndependent ( registry ) ; len ( found ) > 0 { independent = append ( independent , found ... ) } exists := alreadyUploaded [ name ] if exists == nil { exists = sets . NewString ( ) alreadyUploaded [ name ] = exists } independent = append ( independent , takeMostSharedWithoutOverlap ( registry , exists ) ... ) if len ( registry ) == 0 { delete ( remaining , name ) } } for _ , work := range independent { repositoryPlanAddAllExcept ( work . repository , alreadyUploaded [ work . registry . name ] , nil ) } phases = append ( phases , phase { independent : independent } ) } work := & workPlan { phases : phases , } work . calculateStats ( ) return work }
Greedy turns a plan into parallizable work by taking one repo at a time.
Greedy turns a plan into parallizable work by taking one repo at a time .
// we can always take any repository that has no shared layers // take the most shared repositories and any that don't overlap with it