예제 #1
0
파일: iterator.go 프로젝트: lytics/cayley
func NewIterator(prefix string, d quad.Direction, value graph.Value, qs *QuadStore) *Iterator {
	vb := value.(Token)
	p := make([]byte, 0, 2+hashSize)
	p = append(p, []byte(prefix)...)
	p = append(p, []byte(vb[1:])...)

	opts := &opt.ReadOptions{
		DontFillCache: true,
	}

	it := Iterator{
		uid:            iterator.NextUID(),
		nextPrefix:     p,
		checkID:        vb,
		dir:            d,
		originalPrefix: prefix,
		ro:             opts,
		iter:           qs.db.NewIterator(nil, opts),
		open:           true,
		qs:             qs,
	}

	ok := it.iter.Seek(it.nextPrefix)
	if !ok {
		it.open = false
		it.iter.Release()
		glog.Error("Opening LevelDB iterator couldn't seek to location ", it.nextPrefix)
	}

	return &it
}
예제 #2
0
파일: iterator.go 프로젝트: lytics/cayley
func NewAllIterator(qs *QuadStore, kind string) *Iterator {
	if kind != nodeKind && kind != quadKind {
		glog.Error("Cannot create iterator for an unknown kind")
		return &Iterator{done: true}
	}
	if qs.context == nil {
		glog.Error("Cannot create iterator without a valid context")
		return &Iterator{done: true}
	}

	var size int64
	if kind == nodeKind {
		size = qs.NodeSize()
	} else {
		size = qs.Size()
	}

	return &Iterator{
		uid:   iterator.NextUID(),
		qs:    qs,
		size:  size,
		dir:   quad.Any,
		isAll: true,
		kind:  kind,
		done:  false,
	}
}
예제 #3
0
파일: iterator.go 프로젝트: lytics/cayley
func (it *Iterator) Clone() graph.Iterator {
	var iter *b.Enumerator
	if it.result != nil {
		var ok bool
		iter, ok = it.tree.Seek(it.result.(int64))
		if !ok {
			panic("value unexpectedly missing")
		}
	} else {
		var err error
		iter, err = it.tree.SeekFirst()
		if err != nil {
			iter = nil
		}
	}

	m := &Iterator{
		uid:  iterator.NextUID(),
		qs:   it.qs,
		tree: it.tree,
		iter: iter,
		data: it.data,
	}
	m.tags.CopyFrom(it)

	return m
}
예제 #4
0
func NewAllIterator(bucket []byte, d quad.Direction, qs *QuadStore) *AllIterator {
	return &AllIterator{
		uid:    iterator.NextUID(),
		bucket: bucket,
		dir:    d,
		qs:     qs,
	}
}
예제 #5
0
파일: iterator.go 프로젝트: lytics/cayley
func NewAllIterator(qs *QuadStore, collection string) *Iterator {
	return &Iterator{
		uid:        iterator.NextUID(),
		qs:         qs,
		dir:        quad.Any,
		constraint: nil,
		collection: collection,
		iter:       nil,
		size:       -1,
		hash:       "",
		isAll:      true,
	}
}
예제 #6
0
파일: iterator.go 프로젝트: lytics/cayley
func NewIterator(tree *b.Tree, data string, qs *QuadStore) *Iterator {
	iter, err := tree.SeekFirst()
	if err != nil {
		iter = nil
	}
	return &Iterator{
		uid:  iterator.NextUID(),
		qs:   qs,
		tree: tree,
		iter: iter,
		data: data,
	}
}
예제 #7
0
파일: iterator.go 프로젝트: lytics/cayley
func NewIterator(qs *QuadStore, collection string, d quad.Direction, val graph.Value) *Iterator {
	name := qs.NameOf(val)

	constraint := bson.M{d.String(): name}

	return &Iterator{
		uid:        iterator.NextUID(),
		name:       name,
		constraint: constraint,
		collection: collection,
		qs:         qs,
		dir:        d,
		iter:       nil,
		size:       -1,
		hash:       val.(string),
		isAll:      false,
	}
}
예제 #8
0
파일: iterator.go 프로젝트: lytics/cayley
func NewIterator(bucket []byte, d quad.Direction, value graph.Value, qs *QuadStore) *Iterator {
	tok := value.(*Token)
	if !bytes.Equal(tok.bucket, nodeBucket) {
		glog.Error("creating an iterator from a non-node value")
		return &Iterator{done: true}
	}

	it := Iterator{
		uid:    iterator.NextUID(),
		bucket: bucket,
		dir:    d,
		qs:     qs,
		size:   qs.SizeOf(value),
	}

	it.checkID = make([]byte, len(tok.key))
	copy(it.checkID, tok.key)

	return &it
}
예제 #9
0
파일: iterator.go 프로젝트: lytics/cayley
func NewIterator(qs *QuadStore, k string, d quad.Direction, val graph.Value) *Iterator {
	t := val.(*Token)
	if t == nil {
		glog.Error("Token == nil")
	}
	if t.Kind != nodeKind {
		glog.Error("Cannot create an iterator from a non-node value")
		return &Iterator{done: true}
	}
	if k != nodeKind && k != quadKind {
		glog.Error("Cannot create iterator for unknown kind")
		return &Iterator{done: true}
	}
	if qs.context == nil {
		glog.Error("Cannot create iterator without a valid context")
		return &Iterator{done: true}
	}
	name := qs.NameOf(t)

	// The number of references to this node is held in the nodes entity
	key := qs.createKeyFromToken(t)
	foundNode := new(NodeEntry)
	err := datastore.Get(qs.context, key, foundNode)
	if err != nil && err != datastore.ErrNoSuchEntity {
		glog.Errorf("Error: %v", err)
		return &Iterator{done: true}
	}
	size := foundNode.Size

	return &Iterator{
		uid:   iterator.NextUID(),
		name:  name,
		dir:   d,
		qs:    qs,
		size:  size,
		isAll: false,
		kind:  k,
		hash:  t.Hash,
		done:  false,
	}
}