示例#1
0
func NewMongoIterator(ts *MongoTripleStore, collection string, dir string, val graph.TSVal) *MongoIterator {
	var m MongoIterator
	graph.BaseIteratorInit(&m.BaseIterator)

	m.name = ts.GetNameFor(val)
	m.collection = collection
	switch dir {

	case "s":
		m.constraint = bson.M{"Sub": m.name}
	case "p":
		m.constraint = bson.M{"Pred": m.name}
	case "o":
		m.constraint = bson.M{"Obj": m.name}
	case "c":
		m.constraint = bson.M{"Provenance": m.name}
	}

	m.ts = ts
	m.dir = dir
	m.iter = ts.db.C(collection).Find(m.constraint).Iter()
	size, err := ts.db.C(collection).Find(m.constraint).Count()
	if err != nil {
		glog.Errorln("Trouble getting size for iterator! ", err)
		return nil
	}
	m.size = int64(size)
	m.hash = val.(string)
	m.isAll = false
	return &m
}
示例#2
0
func NewLlrbIterator(tree *llrb.LLRB, data string) *LlrbIterator {
	var it LlrbIterator
	graph.BaseIteratorInit(&it.BaseIterator)
	it.tree = tree
	it.iterLast = Int64(-1)
	it.data = data
	return &it
}
示例#3
0
func NewLevelDBAllIterator(prefix, dir string, ts *LevelDBTripleStore) *LevelDBAllIterator {
	var it LevelDBAllIterator
	graph.BaseIteratorInit(&it.BaseIterator)
	it.ro = &leveldb_opt.ReadOptions{}
	it.ro.DontFillCache = true
	it.it = ts.db.NewIterator(nil, it.ro)
	it.prefix = []byte(prefix)
	it.dir = dir
	it.open = true
	it.ts = ts
	it.it.Seek(it.prefix)
	if !it.it.Valid() {
		it.open = false
		it.it.Release()
	}
	return &it
}
示例#4
0
func NewLevelDBIterator(prefix, dir string, value graph.TSVal, ts *LevelDBTripleStore) *LevelDBIterator {
	var it LevelDBIterator
	graph.BaseIteratorInit(&it.BaseIterator)
	it.checkId = value.([]byte)
	it.dir = dir
	it.originalPrefix = prefix
	it.nextPrefix = make([]byte, 0, 2+ts.hasher.Size())
	it.nextPrefix = append(it.nextPrefix, []byte(prefix)...)
	it.nextPrefix = append(it.nextPrefix, []byte(it.checkId[1:])...)
	it.ro = &leveldb_opt.ReadOptions{}
	it.ro.DontFillCache = true
	it.it = ts.db.NewIterator(nil, it.ro)
	it.open = true
	it.ts = ts
	ok := it.it.Seek(it.nextPrefix)
	if !ok {
		it.open = false
		it.it.Release()
	}
	return &it
}