Skip to content

Commit

Permalink
Addressed comments related to cycle and ctor naming
Browse files Browse the repository at this point in the history
  • Loading branch information
anuptalwalkar committed May 2, 2017
1 parent 53fa0da commit b218032
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions internal/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func (g *Graph) InsertObject(v reflect.Value) error {
}

// InsertConstructor adds the constructor to the Graph
func (g *Graph) InsertConstructor(constr interface{}) error {
ctype := reflect.TypeOf(constr)
func (g *Graph) InsertConstructor(ctor interface{}) error {
ctype := reflect.TypeOf(ctor)
// count of number of objects to be registered from the list of return parameters
count := ctype.NumOut()
objTypes := make([]reflect.Type, count, count)
Expand All @@ -106,7 +106,7 @@ func (g *Graph) InsertConstructor(constr interface{}) error {
argc := ctype.NumIn()
n := funcNode{
deps: make([]interface{}, argc),
constructor: constr,
constructor: ctor,
nodes: nodes,
}
for i := 0; i < argc; i++ {
Expand All @@ -124,7 +124,7 @@ func (g *Graph) InsertConstructor(constr interface{}) error {
}

// object needs to be part of the container to properly detect cycles
if cycleErr := g.detectCycles(&n); cycleErr != nil {
if cycleErr := g.recursiveDetectCycles(&n, nil); cycleErr != nil {
// if the cycle was detected delete from the container
for objType := range objTypes {
delete(g.nodes, objType)
Expand All @@ -135,12 +135,6 @@ func (g *Graph) InsertConstructor(constr interface{}) error {
return nil
}

// When a new constructor is being inserted, detect any present cycles
func (g *Graph) detectCycles(n *funcNode) error {
l := []string{}
return g.recursiveDetectCycles(n, l)
}

// DFS and tracking if same node is visited twice
func (g *Graph) recursiveDetectCycles(n graphNode, l []string) error {
for _, el := range l {
Expand Down

0 comments on commit b218032

Please sign in to comment.