func (m *Miner) mine() (err error) { var wg sync.WaitGroup pool := pool.New(m.Config.Workers()) errors.Logf("DEBUG", "pool %v", pool) stack := NewStack() stack.Push(m.Dt.Root()) errs := make(chan error) reports := make(chan lattice.Node, 100) go func() { for n := range reports { err := m.Rptr.Report(n) if err != nil { errs <- err } wg.Done() } }() errList := make([]error, 0, 10) go func() { for err := range errs { if err != nil { errList = append(errList, err) } wg.Done() } }() outer: for { n := stack.Pop() for n == nil { i := pool.WaitCount() if i <= 0 && stack.Empty() { break outer } n = stack.Pop() } if n == nil { panic("nil") } err := pool.Do(func(n lattice.Node) func() { if n == nil { panic("nil") } return func() { if n == nil { panic("nil") } var err error err = m.step(&wg, n, reports, stack) if err != nil { wg.Add(1) errs <- err } } }(n)) if err != nil { return err } } pool.Stop() close(reports) close(errs) wg.Wait() if len(errList) > 0 { return errList[0] } return nil }
func NewDigraph(config *config.Config, dc *Config) (g *Digraph, err error) { if dc.MaxEdges <= 0 { dc.MaxEdges = int(math.MaxInt32) } if dc.MaxVertices <= 0 { dc.MaxVertices = int(math.MaxInt32) } if dc.MinEdges > dc.MaxEdges { dc.MinEdges = dc.MaxEdges - 1 } if dc.MinVertices > dc.MaxVertices { dc.MinVertices = dc.MaxVertices - 1 } nodeAttrs, err := config.IntJsonMultiMap("digraph-node-attrs") if err != nil { return nil, err } parents, err := config.MultiMap("digraph-parents") if err != nil { return nil, err } parentCount, err := config.BytesIntMultiMap("digraph-parent-count") if err != nil { return nil, err } children, err := config.MultiMap("digraph-children") if err != nil { return nil, err } childCount, err := config.BytesIntMultiMap("digraph-child-count") if err != nil { return nil, err } canonKids, err := config.MultiMap("digraph-canon-kids") if err != nil { return nil, err } canonKidCount, err := config.BytesIntMultiMap("digraph-canon-kid-count") if err != nil { return nil, err } embeddings, err := config.SubgraphEmbeddingMultiMap("digraph-embeddings") if err != nil { return nil, err } var unsupEmbs subgraph_embedding.MultiMap = nil if dc.Mode&EmbeddingPruning == EmbeddingPruning { unsupEmbs, err = config.SubgraphEmbeddingMultiMap("digraph-unsupported-embeddings") if err != nil { return nil, err } } var overlap subgraph_overlap.MultiMap = nil if dc.Mode&OverlapPruning == OverlapPruning { overlap, err = config.SubgraphOverlapMultiMap("digraph-overlap") if err != nil { return nil, err } } exts, err := config.BytesExtensionMultiMap("digraph-extensions") if err != nil { return nil, err } var unexts bytes_extension.MultiMap if dc.Mode&ExtensionPruning == ExtensionPruning { unexts, err = config.BytesExtensionMultiMap("digraph-unsupported-extensions") if err != nil { return nil, err } } frequency, err := config.BytesIntMultiMap("digraph-pattern-frequency") if err != nil { return nil, err } g = &Digraph{ Config: *dc, NodeAttrs: nodeAttrs, Embeddings: embeddings, UnsupEmbs: unsupEmbs, Overlap: overlap, Extensions: exts, UnsupExts: unexts, Parents: parents, ParentCount: parentCount, Children: children, ChildCount: childCount, CanonKids: canonKids, CanonKidCount: canonKidCount, Frequency: frequency, config: config, pool: pool.New(config.Workers()), } return g, nil }