Пример #1
0
// 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
// 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
// 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
// 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
// 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
}
Пример #6
0
// objectToCell returns a cell containing the data boxed in the object.
func objectToCell(o *triple.Object) (*table.Cell, error) {
	c := &table.Cell{}
	if n, err := o.Node(); err == nil {
		c.N = n
		return c, nil
	}
	if p, err := o.Predicate(); err == nil {
		c.P = p
		return c, nil
	}
	if l, err := o.Literal(); err == nil {
		c.L = l
		return c, nil
	}
	return nil, fmt.Errorf("unknown object type in object %q", o)
}