Thanks to visit codestin.com
Credit goes to github.com

Skip to content

AncestorsWalker panics if we try to stop at the last vertex #37

@gaborszakacs

Description

@gaborszakacs

Reproduction based on the original usage example, but modifying the exit criteria:

package main

import (
	"fmt"

	"github.com/heimdalr/dag"
)

func main() {
	dag := dag.NewDAG()

	v1, _ := dag.AddVertex("1")
	v2, _ := dag.AddVertex("2")
	v3, _ := dag.AddVertex("3")
	v4, _ := dag.AddVertex("4")
	v5, _ := dag.AddVertex("5")
	_ = dag.AddEdge(v1, v2)
	_ = dag.AddEdge(v2, v3)
	_ = dag.AddEdge(v2, v4)
	_ = dag.AddEdge(v4, v5)

	var ancestors []interface{}
	vertices, signal, _ := dag.AncestorsWalker(v5)
	for v := range vertices {
		ancestors = append(ancestors, v)
		// v2 was modified to v1
		if v == v1 {
			signal <- true
			break
		}
	}
	fmt.Printf("%v", ancestors)
}

Results in

panic: send on closed channel

I'm happy to contribute, but I'm not quite sure how to resolve this while maintaining the current API contract.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions