Пример #1
0
// 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
}
Пример #2
0
// 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
}
Пример #3
0
// 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
}
Пример #4
0
// 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
}
Пример #5
0
// 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
}