// TriplesForObject returns all triples available for a given object. func (m *memory) TriplesForObject(o *triple.Object, lo *storage.LookupOptions) (storage.Triples, error) { oGUID := o.GUID() m.rwmu.RLock() triples := make(chan *triple.Triple, len(m.idxO[oGUID])) go func() { ckr := newChecker(lo) for _, t := range m.idxO[oGUID] { if ckr.CheckAndUpdate(t.P()) { triples <- t } } m.rwmu.RUnlock() close(triples) }() return triples, nil }
// PredicatesForObject returns all the predicates known for the given object. func (m *memory) PredicatesForObject(o *triple.Object, lo *storage.LookupOptions) (storage.Predicates, error) { oGUID := o.GUID() m.rwmu.RLock() preds := make(chan *predicate.Predicate, len(m.idxO[oGUID])) go func() { ckr := newChecker(lo) for _, t := range m.idxO[oGUID] { if ckr.CheckAndUpdate(t.Predicate()) { preds <- t.Predicate() } } m.rwmu.RUnlock() close(preds) }() return preds, nil }
// TriplesForPredicateAndObject returns all triples available for the given // predicate and object. func (m *memory) TriplesForPredicateAndObject(p *predicate.Predicate, o *triple.Object, lo *storage.LookupOptions) (storage.Triples, error) { pGUID := p.GUID() oGUID := o.GUID() poIdx := strings.Join([]string{pGUID, oGUID}, ":") m.rwmu.RLock() triples := make(chan *triple.Triple, len(m.idxPO[poIdx])) go func() { ckr := newChecker(lo) for _, t := range m.idxPO[poIdx] { 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 }
// Subject returns the subjects for the give predicate and object. func (m *memory) Subjects(p *predicate.Predicate, o *triple.Object, lo *storage.LookupOptions) (storage.Nodes, error) { pGUID := p.GUID() oGUID := o.GUID() poIdx := strings.Join([]string{pGUID, oGUID}, ":") m.rwmu.RLock() subs := make(chan *node.Node, len(m.idxPO[poIdx])) go func() { ckr := newChecker(lo) for _, t := range m.idxPO[poIdx] { if ckr.CheckAndUpdate(t.P()) { subs <- t.S() } } m.rwmu.RUnlock() close(subs) }() return subs, nil }