예제 #1
0
파일: memory.go 프로젝트: rtu/badwolf
// 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
}
예제 #2
0
파일: memory.go 프로젝트: defrager/badwolf
// 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
}
예제 #3
0
파일: memory.go 프로젝트: rtu/badwolf
// 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
}
예제 #4
0
파일: memory.go 프로젝트: rtu/badwolf
// 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
파일: memory.go 프로젝트: rtu/badwolf
// 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
}