MCPcopy
hub / github.com/grafana/dskit / orderedDeps

Method orderedDeps

modules/modules.go:214–248  ·  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

212
213// orderedDeps gets a list of all dependencies ordered so that items are always after any of their dependencies.
214func (m *Manager) orderedDeps(mod string) []string {
215 deps := m.listDeps(mod)
216
217 // get a unique list of moduleNames, with a flag for whether they have been added to our result
218 uniq := map[string]bool{}
219 for _, dep := range deps {
220 uniq[dep] = false
221 }
222
223 result := make([]string, 0, len(uniq))
224
225 // keep looping through all modules until they have all been added to the result.
226
227 for len(result) < len(uniq) {
228 OUTER:
229 for name, added := range uniq {
230 if added {
231 continue
232 }
233 for _, dep := range m.modules[name].deps {
234 // stop processing this module if one of its dependencies has
235 // not been added to the result yet.
236 if !uniq[dep] {
237 continue OUTER
238 }
239 }
240
241 // if all of the module's dependencies have been added to the result slice,
242 // then we can safely add this module to the result slice as well.
243 uniq[name] = true
244 result = append(result, name)
245 }
246 }
247 return result
248}
249
250// inverseDependenciesForModule returns the list of modules depending on the input module, sorted by name.
251func (m *Manager) inverseDependenciesForModule(mod string) []string {

Callers 1

initModuleMethod · 0.95

Calls 1

listDepsMethod · 0.95

Tested by

no test coverage detected