Example #1
0
func (sg *SubGraph) startEmbeddings(indices *digraph.Indices, startIdx int) []*IdNode {
	color := sg.V[startIdx].Color
	embs := make([]*IdNode, 0, indices.VertexColorFrequency(color))
	for _, gIdx := range indices.ColorIndex[color] {
		embs = append(embs, &IdNode{VrtEmb: VrtEmb{Id: gIdx, Idx: startIdx}})
	}
	return embs
}
Example #2
0
func (sg *SubGraph) extendEmbedding(indices *digraph.Indices, cur *IdNode, e *Edge, o []map[int]bool, do func(*IdNode)) {
	doNew := func(newIdx, newId int) {
		// enforce forward consistency
		// we need a more performant way to do this
		// for _, xi := range sg.Adj[newIdx] {
		// 	x := &sg.E[xi]
		// 	if x.Src == newIdx {
		// 		if len(indices.SrcIndex[IdColorColor{newId, x.Color, sg.V[x.Targ].Color}]) == 0 {
		// 			return
		// 		}
		// 	} else {
		// 		if len(indices.TargIndex[IdColorColor{newId, x.Color, sg.V[x.Src].Color}]) == 0 {
		// 			return
		// 		}
		// 	}
		// }
		if o == nil || len(o[newIdx]) == 0 {
			do(&IdNode{VrtEmb: VrtEmb{Id: newId, Idx: newIdx}, Prev: cur})
		} else if o[newIdx] != nil && o[newIdx][newId] {
			do(&IdNode{VrtEmb: VrtEmb{Id: newId, Idx: newIdx}, Prev: cur})
		}
	}
	srcId, targId := cur.ids(e.Src, e.Targ)
	if srcId == -1 && targId == -1 {
		panic("src and targ == -1. Which means the edge chain was not connected.")
	} else if srcId != -1 && targId != -1 {
		// both src and targ are in the builder so we can just add this edge
		if indices.HasEdge(srcId, targId, e.Color) {
			do(cur)
		}
	} else if srcId != -1 {
		outDeg := sg.OutDeg[e.Targ]
		inDeg := sg.InDeg[e.Targ]
		indices.TargsFromSrc(srcId, e.Color, sg.V[e.Targ].Color, cur.hasId, func(targId int) {
			if outDeg <= indices.OutDegree(targId) && inDeg <= indices.InDegree(targId) {
				doNew(e.Targ, targId)
			}
		})
	} else if targId != -1 {
		outDeg := sg.OutDeg[e.Src]
		inDeg := sg.InDeg[e.Src]
		indices.SrcsToTarg(targId, e.Color, sg.V[e.Src].Color, cur.hasId, func(srcId int) {
			if outDeg <= indices.OutDegree(srcId) && inDeg <= indices.InDegree(srcId) {
				doNew(e.Src, srcId)
			}
		})
	} else {
		panic("unreachable")
	}
}
Example #3
0
func (sg *SubGraph) vertexFrequency(indices *digraph.Indices) func(int) int {
	return func(idx int) int {
		return indices.VertexColorFrequency(sg.V[idx].Color)
	}
}