48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
/*
|
|
* This file is part of solvar. (https://git.redxen.eu/caskd/solvar)
|
|
* Copyright (c) 2022 Alex-David Denes
|
|
*
|
|
* solvar is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* any later version.
|
|
*
|
|
* solvar is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with solvar. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package solvar
|
|
|
|
type DependencyGraph struct {
|
|
ol []Object
|
|
ic idCache
|
|
}
|
|
|
|
func (d *DependencyGraph) Add(o ...Object) {
|
|
d.ol = append(d.ol, o...)
|
|
}
|
|
|
|
func (d *DependencyGraph) Solve(id Identifier) (ob [][]*Object, err error) {
|
|
rel := Relation{
|
|
T: RelationTypeNeed,
|
|
Id: id,
|
|
}
|
|
|
|
cb := make(chan callbackSolver)
|
|
go d.solveRelation(&[]*Object{}, &rel, cb)
|
|
res := <-cb
|
|
if res.e != nil {
|
|
return
|
|
}
|
|
for _, io := range res.io {
|
|
ob = append(ob, io.n)
|
|
}
|
|
|
|
return
|
|
}
|