Esempio n. 1
0
func (it *Iterator) Contains(v graph.Value) bool {
	graph.ContainsLogIn(it, v)
	if it.isAll {
		// The result needs to be set, so when contains is called, the result can be retrieved
		it.result = v
		return graph.ContainsLogOut(it, v, true)
	}
	t := v.(*Token)
	if t == nil {
		glog.Error("Could not cast to token")
		return graph.ContainsLogOut(it, v, false)
	}
	if t.Kind == nodeKind {
		glog.Error("Contains does not work with node values")
		return graph.ContainsLogOut(it, v, false)
	}
	// Contains is for when you want to know that an iterator refers to a quad
	var offset int
	switch it.dir {
	case quad.Subject:
		offset = 0
	case quad.Predicate:
		offset = (hashSize * 2)
	case quad.Object:
		offset = (hashSize * 2) * 2
	case quad.Label:
		offset = (hashSize * 2) * 3
	}
	val := t.Hash[offset : offset+(hashSize*2)]
	if val == it.hash {
		return graph.ContainsLogOut(it, v, true)
	}
	return graph.ContainsLogOut(it, v, false)
}
Esempio n. 2
0
func (it *Iterator) Contains(v graph.Value) bool {
	graph.ContainsLogIn(it, v)
	if _, ok := it.tree.Get(v.(int64)); ok {
		it.result = v
		return graph.ContainsLogOut(it, v, true)
	}
	return graph.ContainsLogOut(it, v, false)
}
Esempio n. 3
0
func (it *Iterator) Contains(v graph.Value) bool {
	graph.ContainsLogIn(it, v)
	if it.tree.Has(Int64(v.(int64))) {
		it.result = v
		return graph.ContainsLogOut(it, v, true)
	}
	return graph.ContainsLogOut(it, v, false)
}
Esempio n. 4
0
// Check a value against the entire graph.iterator, in order.
func (it *Or) Contains(val graph.Value) bool {
	graph.ContainsLogIn(it, val)
	anyGood := it.subItsContain(val)
	if !anyGood {
		return graph.ContainsLogOut(it, val, false)
	}
	it.result = val
	return graph.ContainsLogOut(it, val, true)
}
Esempio n. 5
0
// If it checks in the right direction for the subiterator, it is a valid link
// for the LinksTo.
func (it *LinksTo) Contains(val graph.Value) bool {
	graph.ContainsLogIn(it, val)
	node := it.ts.TripleDirection(val, it.dir)
	if it.primaryIt.Contains(node) {
		it.result = val
		return graph.ContainsLogOut(it, val, true)
	}
	return graph.ContainsLogOut(it, val, false)
}
Esempio n. 6
0
// Contains() for an Int64 is merely seeing if the passed value is
// withing the range, assuming the value is an int64.
func (it *Int64) Contains(tsv graph.Value) bool {
	graph.ContainsLogIn(it, tsv)
	v := tsv.(int64)
	if it.min <= v && v <= it.max {
		it.result = v
		return graph.ContainsLogOut(it, v, true)
	}
	return graph.ContainsLogOut(it, v, false)
}
Esempio n. 7
0
// If it checks in the right direction for the subiterator, it is a valid link
// for the LinksTo.
func (it *LinksTo) Contains(val graph.Value) bool {
	graph.ContainsLogIn(it, val)
	it.runstats.Contains += 1
	node := it.qs.QuadDirection(val, it.dir)
	if it.primaryIt.Contains(node) {
		it.result = val
		return graph.ContainsLogOut(it, val, true)
	}
	return graph.ContainsLogOut(it, val, false)
}
Esempio n. 8
0
// Check a value against the entire graph.iterator, in order.
func (it *Or) Contains(val graph.Value) bool {
	graph.ContainsLogIn(it, val)
	anyGood, err := it.subItsContain(val)
	if err != nil {
		it.err = err
		return false
	} else if !anyGood {
		return graph.ContainsLogOut(it, val, false)
	}
	it.result = val
	return graph.ContainsLogOut(it, val, true)
}
Esempio n. 9
0
// Check if the passed value is equal to one of the values stored in the iterator.
func (it *Fixed) Contains(v graph.Value) bool {
	// Could be optimized by keeping it sorted or using a better datastructure.
	// However, for fixed iterators, which are by definition kind of tiny, this
	// isn't a big issue.
	graph.ContainsLogIn(it, v)
	for _, x := range it.values {
		if it.cmp(x, v) {
			it.result = x
			return graph.ContainsLogOut(it, v, true)
		}
	}
	return graph.ContainsLogOut(it, v, false)
}
Esempio n. 10
0
func (it *Iterator) Contains(v graph.Value) bool {
	graph.ContainsLogIn(it, v)
	if it.isAll {
		it.result = v
		return graph.ContainsLogOut(it, v, true)
	}
	val := NodeHash(v.(QuadHash).Get(it.dir))
	if val == it.hash {
		it.result = v
		return graph.ContainsLogOut(it, v, true)
	}
	return graph.ContainsLogOut(it, v, false)
}
Esempio n. 11
0
// Contains() for an Int64 is merely seeing if the passed value is
// withing the range, assuming the value is an int64.
func (it *Int64) Contains(tsv graph.Value) bool {
	graph.ContainsLogIn(it, tsv)
	it.runstats.Contains += 1
	var v int64
	if tsv.IsNode() {
		v = int64(tsv.(Int64Node))
	} else {
		v = int64(tsv.(Int64Quad))
	}
	if it.min <= v && v <= it.max {
		it.result = v
		return graph.ContainsLogOut(it, it.toValue(v), true)
	}
	return graph.ContainsLogOut(it, it.toValue(v), false)
}
Esempio n. 12
0
// Check a value against the entire iterator, in order.
func (it *And) Contains(val graph.Value) bool {
	graph.ContainsLogIn(it, val)
	if it.checkList != nil {
		return it.checkContainsList(val)
	}
	mainGood := it.primaryIt.Contains(val)
	if !mainGood {
		return graph.ContainsLogOut(it, val, false)
	}
	othersGood := it.subItsContain(val)
	if !othersGood {
		return graph.ContainsLogOut(it, val, false)
	}
	it.result = val
	return graph.ContainsLogOut(it, val, true)
}
Esempio n. 13
0
// Contains ???
// BUG(bmatsuo):
// Contains is surely broken. It just looks for v in the given database.  It
// seems like it should buffer the output, or run the iteration again.
func (it *AllIterator) Contains(v graph.Value) (ok bool) {
	graph.ContainsLogIn(it, v)
	defer func() { graph.ContainsLogOut(it, v, ok) }()

	tok, ok := v.(*Token)
	if !ok {
		return false
	}
	if tok.db != it.db {
		return false
	}

	err := it.qs.env.View(func(tx *lmdb.Txn) (err error) {
		tx.RawRead = true
		_, err = tx.Get(it.qs.dbis[tok.db], tok.key)
		ok = !lmdb.IsNotFound(err)
		return err
	})
	if err != nil {
		return false
	}
	if ok {
		it.result = tok
	}
	return ok

}
Esempio n. 14
0
func (it *And) checkContainsList(val graph.Value, lastResult graph.Value) bool {
	ok := true
	for i, c := range it.checkList {
		ok = c.Contains(val)
		if !ok {
			it.err = c.Err()
			if it.err != nil {
				return false
			}

			if lastResult != nil {
				for j := 0; j < i; j++ {
					// One of the iterators has determined that this value doesn't
					// match. However, the iterators that came before in the list
					// may have returned "ok" to Contains().  We need to set all
					// the tags back to what the previous result was -- effectively
					// seeking back exactly one -- so we check all the prior iterators
					// with the (already verified) result and throw away the result,
					// which will be 'true'
					it.checkList[j].Contains(lastResult)

					it.err = it.checkList[j].Err()
					if it.err != nil {
						return false
					}
				}
			}
			break
		}
	}
	if ok {
		it.result = val
	}
	return graph.ContainsLogOut(it, val, ok)
}
Esempio n. 15
0
// Contains checks whether the passed value is part of the primary iterator's
// complement. For a valid value, it updates the Result returned by the iterator
// to the value itself.
func (it *Not) Contains(val graph.Value) bool {
	graph.ContainsLogIn(it, val)
	it.runstats.Contains += 1

	if it.primaryIt.Contains(val) {
		return graph.ContainsLogOut(it, val, false)
	}

	it.err = it.primaryIt.Err()
	if it.err != nil {
		// Explicitly return 'false', since an error occurred.
		return false
	}

	it.result = val
	return graph.ContainsLogOut(it, val, true)
}
Esempio n. 16
0
func (it *Materialize) Contains(v graph.Value) bool {
	graph.ContainsLogIn(it, v)
	if !it.hasRun {
		it.materializeSet()
	}
	if it.aborted {
		return it.subIt.Contains(v)
	}
	key := v
	if h, ok := v.(Keyer); ok {
		key = h.Key()
	}
	if i, ok := it.containsMap[key]; ok {
		it.index = i
		it.subindex = 0
		return graph.ContainsLogOut(it, v, true)
	}
	return graph.ContainsLogOut(it, v, false)
}
Esempio n. 17
0
func (it *LinksTo) Contains(val graph.Value) bool {
	graph.ContainsLogIn(it, val)
	it.runstats.Contains += 1

	for _, link := range it.lset {
		dval := it.qs.QuadDirection(val, link.Dir)
		if dval != link.Value {
			return graph.ContainsLogOut(it, val, false)
		}
	}

	node := it.qs.QuadDirection(val, it.dir)
	if it.primaryIt.Contains(node) {
		it.result = val
		return graph.ContainsLogOut(it, val, true)
	}
	it.err = it.primaryIt.Err()
	return graph.ContainsLogOut(it, val, false)
}
Esempio n. 18
0
func (it *Iterator) Contains(v graph.Value) bool {
	graph.ContainsLogIn(it, v)
	if v == nil {
		return graph.ContainsLogOut(it, v, false)
	} else if it.nodes != v.IsNode() {
		return graph.ContainsLogOut(it, v, false)
	}
	var vi int64
	if it.nodes {
		vi = int64(v.(iterator.Int64Node))
	} else {
		vi = int64(v.(iterator.Int64Quad))
	}
	if it.tree.Contains(vi) {
		it.result = vi
		return graph.ContainsLogOut(it, v, true)
	}
	return graph.ContainsLogOut(it, v, false)
}
Esempio n. 19
0
func (it *Materialize) Contains(v graph.Value) bool {
	graph.ContainsLogIn(it, v)
	it.runstats.Contains += 1
	if !it.hasRun {
		it.materializeSet()
	}
	if it.err != nil {
		return false
	}
	if it.aborted {
		return it.subIt.Contains(v)
	}
	key := graph.ToKey(v)
	if i, ok := it.containsMap[key]; ok {
		it.index = i
		it.subindex = 0
		return graph.ContainsLogOut(it, v, true)
	}
	return graph.ContainsLogOut(it, v, false)
}
Esempio n. 20
0
// Check a value against the entire iterator, in order.
func (it *And) Contains(val graph.Value) bool {
	graph.ContainsLogIn(it, val)
	it.runstats.Contains += 1
	lastResult := it.result
	if it.checkList != nil {
		return it.checkContainsList(val, lastResult)
	}
	mainGood := it.primaryIt.Contains(val)
	if mainGood {
		othersGood := it.subItsContain(val, lastResult)
		if othersGood {
			it.result = val
			return graph.ContainsLogOut(it, val, true)
		}
	}
	if lastResult != nil {
		it.primaryIt.Contains(lastResult)
	}
	return graph.ContainsLogOut(it, val, false)
}
Esempio n. 21
0
// Check a value against our internal iterator. In order to do this, we must first open a new
// iterator of "triples that have `val` in our direction", given to us by the triple store,
// and then Next() values out of that iterator and Contains() them against our subiterator.
func (it *HasA) Contains(val graph.Value) bool {
	graph.ContainsLogIn(it, val)
	if glog.V(4) {
		glog.V(4).Infoln("Id is", it.ts.NameOf(val))
	}
	// TODO(barakmich): Optimize this
	if it.resultIt != nil {
		it.resultIt.Close()
	}
	it.resultIt = it.ts.TripleIterator(it.dir, val)
	return graph.ContainsLogOut(it, val, it.NextContains())
}
Esempio n. 22
0
func (it *And) checkContainsList(val graph.Value) bool {
	ok := true
	for _, c := range it.checkList {
		ok = c.Contains(val)
		if !ok {
			break
		}
	}
	if ok {
		it.result = val
	}
	return graph.ContainsLogOut(it, val, ok)
}
Esempio n. 23
0
func (it *Iterator) Contains(v graph.Value) bool {
	graph.ContainsLogIn(it, v)
	if it.isAll {
		it.result = v
		return graph.ContainsLogOut(it, v, true)
	}
	var offset int
	switch it.dir {
	case quad.Subject:
		offset = 0
	case quad.Predicate:
		offset = (hashSize * 2)
	case quad.Object:
		offset = (hashSize * 2) * 2
	case quad.Label:
		offset = (hashSize * 2) * 3
	}
	val := v.(string)[offset : hashSize*2+offset]
	if val == it.hash {
		it.result = v
		return graph.ContainsLogOut(it, v, true)
	}
	return graph.ContainsLogOut(it, v, false)
}
Esempio n. 24
0
// Check a value against our internal iterator. In order to do this, we must first open a new
// iterator of "quads that have `val` in our direction", given to us by the quad store,
// and then Next() values out of that iterator and Contains() them against our subiterator.
func (it *HasA) Contains(val graph.Value) bool {
	graph.ContainsLogIn(it, val)
	it.runstats.Contains += 1
	if glog.V(4) {
		glog.V(4).Infoln("Id is", it.qs.NameOf(val))
	}
	// TODO(barakmich): Optimize this
	if it.resultIt != nil {
		it.resultIt.Close()
	}
	it.resultIt = it.qs.QuadIterator(it.dir, val)
	ok := it.NextContains()
	if it.err != nil {
		return false
	}
	return graph.ContainsLogOut(it, val, ok)
}
Esempio n. 25
0
func (it *And) checkContainsList(val graph.Value, lastResult graph.Value) bool {
	ok := true
	for i, c := range it.checkList {
		ok = c.Contains(val)
		if !ok {
			if lastResult != nil {
				for j := 0; j < i; j++ {
					it.checkList[j].Contains(lastResult)
				}
			}
			break
		}
	}
	if ok {
		it.result = val
	}
	return graph.ContainsLogOut(it, val, ok)
}
Esempio n. 26
0
func (it *AllIterator) Contains(v graph.Value) bool {
	graph.ContainsLogIn(it, v)
	it.result = v
	return graph.ContainsLogOut(it, v, true)
}