Switch to exported constants
This commit is contained in:
parent
25f466a6ac
commit
bd68c8a3e9
7
main.go
7
main.go
@ -28,9 +28,10 @@ func (d *DependencyGraph) Add(o ...Object) {
|
||||
}
|
||||
|
||||
func (d *DependencyGraph) Solve(id Identifier) (ob [][]*Object, err error) {
|
||||
var rel Relation
|
||||
rel.T.SetNeed()
|
||||
rel.Id = id
|
||||
rel := Relation{
|
||||
T: RelationTypeNeed,
|
||||
Id: id,
|
||||
}
|
||||
|
||||
cb := make(chan callbackSolver)
|
||||
go d.solveRelation(&[]*Object{}, &rel, cb)
|
||||
|
@ -42,9 +42,9 @@ func BenchmarkSolve(b *testing.B) {
|
||||
o.Rel = append(o.Rel, Relation{
|
||||
T: func() RelationType {
|
||||
if (frand.Intn(2))%2 == 0 {
|
||||
return relationTypeNeed
|
||||
return RelationTypeNeed
|
||||
} else {
|
||||
return relationTypeReject
|
||||
return RelationTypeReject
|
||||
}
|
||||
}(),
|
||||
Id: Identifier(idpool[frand.Intn(len(idpool))]),
|
||||
@ -61,7 +61,7 @@ func BenchmarkSolve(b *testing.B) {
|
||||
for _, v := range g.ol {
|
||||
c.i += len(v.Id)
|
||||
for _, vol := range v.Rel {
|
||||
if vol.T.IsNeed() {
|
||||
if vol.T == RelationTypeNeed {
|
||||
c.r.n += 1
|
||||
} else {
|
||||
c.r.r += 1
|
||||
|
@ -66,7 +66,7 @@ func (d *DependencyGraph) solveObject(np *[]*Object, object *Object, rel Relatio
|
||||
// Check if we already have visited the graph path
|
||||
if !slices.Contains(p, object) {
|
||||
// Fetch children and work on children if any
|
||||
if rel.IsNeed() {
|
||||
if rel == RelationTypeNeed {
|
||||
lcb := make(chan callbackSolver, len(object.Rel))
|
||||
for idxrel := range object.Rel {
|
||||
go d.solveRelation(&p, &object.Rel[idxrel], lcb)
|
||||
@ -103,7 +103,7 @@ func (d *DependencyGraph) solveObject(np *[]*Object, object *Object, rel Relatio
|
||||
for _, rv := range rio {
|
||||
// Relation list to append to
|
||||
var rl *[]*Object
|
||||
if rel.IsNeed() {
|
||||
if rel == RelationTypeNeed {
|
||||
rl = &rv.n
|
||||
} else {
|
||||
rl = &rv.r
|
||||
|
11
relation.go
11
relation.go
@ -29,8 +29,8 @@ type internalRelation struct {
|
||||
type RelationType uint
|
||||
|
||||
const (
|
||||
relationTypeNeed RelationType = iota
|
||||
relationTypeReject
|
||||
RelationTypeNeed RelationType = iota
|
||||
RelationTypeReject
|
||||
)
|
||||
|
||||
type Relation struct {
|
||||
@ -38,11 +38,6 @@ type Relation struct {
|
||||
T RelationType
|
||||
}
|
||||
|
||||
func (r RelationType) IsNeed() bool { return r == relationTypeNeed }
|
||||
func (r RelationType) IsReject() bool { return r == relationTypeReject }
|
||||
func (r *RelationType) SetNeed() { *r = relationTypeNeed }
|
||||
func (r *RelationType) SetReject() { *r = relationTypeReject }
|
||||
|
||||
func (d *DependencyGraph) solveRelation(np *[]*Object, rel *Relation, cb chan callbackSolver) {
|
||||
var err error
|
||||
var rio []*internalObject
|
||||
@ -66,7 +61,7 @@ func (d *DependencyGraph) solveRelation(np *[]*Object, rel *Relation, cb chan ca
|
||||
}
|
||||
obs = tmp
|
||||
|
||||
if rel.T.IsNeed() {
|
||||
if rel.T == RelationTypeNeed {
|
||||
lcb := make(chan callbackSolver, len(obs))
|
||||
for _, ob := range obs {
|
||||
go d.solveObject(np, ob, rel.T, lcb)
|
||||
|
Loading…
Reference in New Issue
Block a user