6 import . "github.com/onsi/gomega/matchers/support/goraph/node"
7 import . "github.com/onsi/gomega/matchers/support/goraph/edge"
9 type BipartiteGraph struct {
15 func NewBipartiteGraph(leftValues, rightValues []interface{}, neighbours func(interface{}, interface{}) (bool, error)) (*BipartiteGraph, error) {
16 left := NodeOrderedSet{}
17 for i, _ := range leftValues {
18 left = append(left, Node{i})
21 right := NodeOrderedSet{}
22 for j, _ := range rightValues {
23 right = append(right, Node{j + len(left)})
27 for i, leftValue := range leftValues {
28 for j, rightValue := range rightValues {
29 neighbours, err := neighbours(leftValue, rightValue)
31 return nil, errors.New(fmt.Sprintf("error determining adjacency for %v and %v: %s", leftValue, rightValue, err.Error()))
35 edges = append(edges, Edge{left[i], right[j]})
40 return &BipartiteGraph{left, right, edges}, nil