Switch to exported constants

This commit is contained in:
Alex D. 2022-06-20 06:11:50 +00:00
parent 25f466a6ac
commit bd68c8a3e9
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
4 changed files with 12 additions and 16 deletions

View File

@ -28,9 +28,10 @@ func (d *DependencyGraph) Add(o ...Object) {
} }
func (d *DependencyGraph) Solve(id Identifier) (ob [][]*Object, err error) { func (d *DependencyGraph) Solve(id Identifier) (ob [][]*Object, err error) {
var rel Relation rel := Relation{
rel.T.SetNeed() T: RelationTypeNeed,
rel.Id = id Id: id,
}
cb := make(chan callbackSolver) cb := make(chan callbackSolver)
go d.solveRelation(&[]*Object{}, &rel, cb) go d.solveRelation(&[]*Object{}, &rel, cb)

View File

@ -42,9 +42,9 @@ func BenchmarkSolve(b *testing.B) {
o.Rel = append(o.Rel, Relation{ o.Rel = append(o.Rel, Relation{
T: func() RelationType { T: func() RelationType {
if (frand.Intn(2))%2 == 0 { if (frand.Intn(2))%2 == 0 {
return relationTypeNeed return RelationTypeNeed
} else { } else {
return relationTypeReject return RelationTypeReject
} }
}(), }(),
Id: Identifier(idpool[frand.Intn(len(idpool))]), Id: Identifier(idpool[frand.Intn(len(idpool))]),
@ -61,7 +61,7 @@ func BenchmarkSolve(b *testing.B) {
for _, v := range g.ol { for _, v := range g.ol {
c.i += len(v.Id) c.i += len(v.Id)
for _, vol := range v.Rel { for _, vol := range v.Rel {
if vol.T.IsNeed() { if vol.T == RelationTypeNeed {
c.r.n += 1 c.r.n += 1
} else { } else {
c.r.r += 1 c.r.r += 1

View File

@ -66,7 +66,7 @@ func (d *DependencyGraph) solveObject(np *[]*Object, object *Object, rel Relatio
// Check if we already have visited the graph path // Check if we already have visited the graph path
if !slices.Contains(p, object) { if !slices.Contains(p, object) {
// Fetch children and work on children if any // Fetch children and work on children if any
if rel.IsNeed() { if rel == RelationTypeNeed {
lcb := make(chan callbackSolver, len(object.Rel)) lcb := make(chan callbackSolver, len(object.Rel))
for idxrel := range object.Rel { for idxrel := range object.Rel {
go d.solveRelation(&p, &object.Rel[idxrel], lcb) 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 { for _, rv := range rio {
// Relation list to append to // Relation list to append to
var rl *[]*Object var rl *[]*Object
if rel.IsNeed() { if rel == RelationTypeNeed {
rl = &rv.n rl = &rv.n
} else { } else {
rl = &rv.r rl = &rv.r

View File

@ -29,8 +29,8 @@ type internalRelation struct {
type RelationType uint type RelationType uint
const ( const (
relationTypeNeed RelationType = iota RelationTypeNeed RelationType = iota
relationTypeReject RelationTypeReject
) )
type Relation struct { type Relation struct {
@ -38,11 +38,6 @@ type Relation struct {
T RelationType 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) { func (d *DependencyGraph) solveRelation(np *[]*Object, rel *Relation, cb chan callbackSolver) {
var err error var err error
var rio []*internalObject var rio []*internalObject
@ -66,7 +61,7 @@ func (d *DependencyGraph) solveRelation(np *[]*Object, rel *Relation, cb chan ca
} }
obs = tmp obs = tmp
if rel.T.IsNeed() { if rel.T == RelationTypeNeed {
lcb := make(chan callbackSolver, len(obs)) lcb := make(chan callbackSolver, len(obs))
for _, ob := range obs { for _, ob := range obs {
go d.solveObject(np, ob, rel.T, lcb) go d.solveObject(np, ob, rel.T, lcb)