MCPcopy Create free account
hub / github.com/cortexproject/cortex / orderedDeps

Method orderedDeps

pkg/util/modules/modules.go:173–207  ·  view source on GitHub ↗

orderedDeps gets a list of all dependencies ordered so that items are always after any of their dependencies.

(mod string)

Source from the content-addressed store, hash-verified

171
172// orderedDeps gets a list of all dependencies ordered so that items are always after any of their dependencies.
173func (m *Manager) orderedDeps(mod string) []string {
174 deps := m.listDeps(mod)
175
176 // get a unique list of moduleNames, with a flag for whether they have been added to our result
177 uniq := map[string]bool{}
178 for _, dep := range deps {
179 uniq[dep] = false
180 }
181
182 result := make([]string, 0, len(uniq))
183
184 // keep looping through all modules until they have all been added to the result.
185
186 for len(result) < len(uniq) {
187 OUTER:
188 for name, added := range uniq {
189 if added {
190 continue
191 }
192 for _, dep := range m.modules[name].deps {
193 // stop processing this module if one of its dependencies has
194 // not been added to the result yet.
195 if !uniq[dep] {
196 continue OUTER
197 }
198 }
199
200 // if all of the module's dependencies have been added to the result slice,
201 // then we can safely add this module to the result slice as well.
202 uniq[name] = true
203 result = append(result, name)
204 }
205 }
206 return result
207}
208
209// find modules in the supplied list, that depend on mod
210func (m *Manager) findInverseDependencies(mod string, mods []string) []string {

Callers 1

initModuleMethod · 0.95

Calls 1

listDepsMethod · 0.95

Tested by

no test coverage detected