// recurse generated the triple by recursing while there are still triples // left to generate. func (t *treeGenerator) recurse(parent *node.Node, left *int, currentDepth, maxDepth int, trpls []*triple.Triple) ([]*triple.Triple, error) { if *left < 1 { return trpls, nil } for i, last := 0, *left <= t.branch; i < t.branch; i++ { offspring, err := t.newNode(i, parent.ID().String()) if err != nil { return trpls, err } trpl, err := t.newTriple(parent, offspring) if err != nil { return trpls, err } trpls = append(trpls, trpl) (*left)-- if *left < 1 { break } if currentDepth < maxDepth && !last { ntrpls, err := t.recurse(offspring, left, currentDepth+1, maxDepth, trpls) if err != nil { return ntrpls, err } trpls = ntrpls } if *left < 1 { break } } return trpls, nil }
// TriplesForSubject returns all triples available for a given subect. func (m *memory) TriplesForSubject(s *node.Node, lo *storage.LookupOptions) (storage.Triples, error) { sGUID := s.GUID() m.rwmu.RLock() triples := make(chan *triple.Triple, len(m.idxS[sGUID])) go func() { ckr := newChecker(lo) for _, t := range m.idxS[sGUID] { if ckr.CheckAndUpdate(t.P()) { triples <- t } } m.rwmu.RUnlock() close(triples) }() return triples, nil }
// PredicatesForSubject returns all the predicats know for the given // subject. func (m *memory) PredicatesForSubject(s *node.Node, lo *storage.LookupOptions) (storage.Predicates, error) { sGUID := s.GUID() m.rwmu.RLock() preds := make(chan *predicate.Predicate, len(m.idxS[sGUID])) go func() { ckr := newChecker(lo) for _, t := range m.idxS[sGUID] { if ckr.CheckAndUpdate(t.P()) { preds <- t.P() } } m.rwmu.RUnlock() close(preds) }() return preds, nil }
// TriplesForSubjectAndPredicate returns all triples available for the given // subject and predicate. func (m *memory) TriplesForSubjectAndPredicate(s *node.Node, p *predicate.Predicate, lo *storage.LookupOptions) (storage.Triples, error) { sGUID := s.GUID() pGUID := p.GUID() spIdx := strings.Join([]string{sGUID, pGUID}, ":") m.rwmu.RLock() triples := make(chan *triple.Triple, len(m.idxSP[spIdx])) go func() { ckr := newChecker(lo) for _, t := range m.idxSP[spIdx] { if ckr.CheckAndUpdate(t.P()) { triples <- t } } m.rwmu.RUnlock() close(triples) }() return triples, nil }
// PredicatesForSubjecAndObject returns all predicates available for the // given subject and object. func (m *memory) PredicatesForSubjectAndObject(s *node.Node, o *triple.Object, lo *storage.LookupOptions) (storage.Predicates, error) { sGUID := s.GUID() oGUID := o.GUID() soIdx := strings.Join([]string{sGUID, oGUID}, ":") m.rwmu.RLock() preds := make(chan *predicate.Predicate, len(m.idxSO[soIdx])) go func() { ckr := newChecker(lo) for _, t := range m.idxSO[soIdx] { if ckr.CheckAndUpdate(t.P()) { preds <- t.P() } } m.rwmu.RUnlock() close(preds) }() return preds, nil }
// Objects returns the objects for the give object and predicate. func (m *memory) Objects(ctx context.Context, s *node.Node, p *predicate.Predicate, lo *storage.LookupOptions) (storage.Objects, error) { sGUID := s.GUID() pGUID := p.GUID() spIdx := strings.Join([]string{sGUID, pGUID}, ":") m.rwmu.RLock() objs := make(chan *triple.Object, len(m.idxSP[spIdx])) go func() { ckr := newChecker(lo) for _, t := range m.idxSP[spIdx] { if ckr.CheckAndUpdate(t.Predicate()) { objs <- t.Object() } } m.rwmu.RUnlock() close(objs) }() return objs, nil }