Пример #1
0
// TriplesForPredicate returns all triples available for the given predicate.
func (m *memory) TriplesForPredicate(p *predicate.Predicate, lo *storage.LookupOptions) (storage.Triples, error) {
	pGUID := p.GUID()
	m.rwmu.RLock()
	triples := make(chan *triple.Triple, len(m.idxP[pGUID]))
	go func() {
		ckr := newChecker(lo)
		for _, t := range m.idxP[pGUID] {
			if ckr.CheckAndUpdate(t.Predicate()) {
				triples <- t
			}
		}
		m.rwmu.RUnlock()
		close(triples)
	}()
	return triples, nil
}
Пример #2
0
// 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
}
Пример #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
// 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
}
Пример #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
}