• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang iterator.Iterator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/syndtr/goleveldb/leveldb/iterator.Iterator的典型用法代码示例。如果您正苦于以下问题:Golang Iterator类的具体用法?Golang Iterator怎么用?Golang Iterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Iterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: isExpireT

//Function: isExpireT
//Checkes whether the file is expired or not. If expired delete the file.
//Parameters:
//    fileName - file name
//    iterT - pointer database location
// Return:
//	  true - file expired
//	  false - file alive
func isExpireT(fileName string, iterT iterator.Iterator) bool {

	var expFlag int = 0
	var flag int = 0
	var f3 DBData

	key1 := iterT.Key()

	if string(key1) == fileName {
		flag = 1
	}

	if flag == 1 {
		tmp := iterT.Value()
		json.Unmarshal(tmp, &f3)
		var flagT1 int = f3.TFlag

		if flagT1 == 1 {
			timeT := f3.Life
			now := time.Now()
			tmp := timeT.Before(now)
			if tmp {
				expFlag = 1
			}
		} else {
			expFlag = 0
		}
	}

	if expFlag == 1 {
		return true
	} else {
		return false
	}
}
开发者ID:saurabhjambhule,项目名称:cs733,代码行数:43,代码来源:server.go


示例2: eoi

func (h *blockHarness) eoi(pref string, iter iterator.Iterator) {
	if iter.Next() {
		h.t.Fatalf("block: %sNext: expect eoi", pref)
	} else if err := iter.Error(); err != nil {
		h.t.Fatalf("block: %sNext: expect eoi but got error, err=%v", pref, err)
	}
}
开发者ID:pombredanne,项目名称:goleveldb,代码行数:7,代码来源:table_test.go


示例3: newUnionIter

func newUnionIter(dirtyIt iterator.Iterator, snapshotIt Iterator) *UnionIter {
	it := &UnionIter{
		dirtyIt:    dirtyIt,
		snapshotIt: snapshotIt,
		// leveldb use next for checking valid...
		dirtyValid:    dirtyIt.Next(),
		snapshotValid: snapshotIt.Valid(),
	}
	it.updateCur()
	return it
}
开发者ID:ninefive,项目名称:tidb,代码行数:11,代码来源:union_iter.go


示例4: createFrom

// Builds table from src iterator.
func (t *tOps) createFrom(src iterator.Iterator) (f *tFile, n int, err error) {
	w, err := t.create()
	if err != nil {
		return
	}

	defer func() {
		if err != nil {
			w.drop()
		}
	}()

	for src.Next() {
		err = w.append(src.Key(), src.Value())
		if err != nil {
			return
		}
	}
	err = src.Error()
	if err != nil {
		return
	}

	n = w.tw.EntriesLen()
	f, err = w.finish()
	return
}
开发者ID:KosyanMedia,项目名称:burlesque,代码行数:28,代码来源:table.go


示例5: testKV

func (h *blockHarness) testKV(act string, iter iterator.Iterator, i int) {
	key, value := h.kv[i], h.kv[i+1]
	if !bytes.Equal(iter.Key(), key) {
		h.t.Fatalf("block: %s: key invalid, want=%q got=%q", act, key, iter.Key())
	}
	if !bytes.Equal(iter.Value(), value) {
		h.t.Fatalf("block: %s: value invalid, want=%q got=%q", act, value, iter.Value())
	}
}
开发者ID:pombredanne,项目名称:goleveldb,代码行数:9,代码来源:table_test.go


示例6: list

func list(c *cli.Context) {

	dbPath := c.GlobalString("path")

	pwd, err := os.Getwd()
	dbPath = path.Join(pwd, dbPath)

	options := &opt.Options{ErrorIfMissing: true}

	db, err := leveldb.OpenFile(dbPath, options)

	if err != nil {
		msg := fmt.Sprintf("%s %s", err, dbPath)
		panic(msg)
	}

	fmt.Println("using database:", dbPath)

	defer db.Close()

	var iter iterator.Iterator

	fmt.Println("Listing reading keys...")

	iter = db.NewIterator(&dbutil.Range{Start: []byte("/reading/RF12:"), Limit: []byte("/reading/RF12~")}, nil)
	for iter.Next() {
		key := string(iter.Key())
		fmt.Println(key)
	}
	iter.Release()

	//err = iter.Error()

}
开发者ID:TheDistractor,项目名称:convert-rf-readings,代码行数:34,代码来源:main.go


示例7: last

func (h *blockHarness) last(iter iterator.Iterator) {
	if len(h.kv) == 0 {
		if iter.Last() {
			h.t.Fatalf("block: Last: expect eoi, key=%q", iter.Key())
		}
	} else {
		if !iter.Last() {
			h.t.Fatalf("block: Last: eoi, err=%v", iter.Error())
		}
	}
}
开发者ID:pombredanne,项目名称:goleveldb,代码行数:11,代码来源:table_test.go


示例8: Get

// Get lookup for given key on the table. Get returns errors.ErrNotFound if
// given key did not exist.
func (t *Reader) Get(key []byte, ro opt.ReadOptionsGetter) (rkey, rvalue []byte, err error) {
	// create an iterator of index block
	index_iter := t.indexBlock.NewIterator()
	if !index_iter.Seek(key) {
		err = index_iter.Error()
		if err == nil {
			err = errors.ErrNotFound
		}
		return
	}

	// decode data block info
	bi := new(bInfo)
	_, err = bi.decodeFrom(index_iter.Value())
	if err != nil {
		return
	}

	// get the data block
	if t.filterBlock == nil || t.filterBlock.KeyMayMatch(uint(bi.offset), key) {
		var it iterator.Iterator
		var cache cache.Object
		it, cache, err = t.getDataIter(bi, ro)
		if err != nil {
			return
		}
		if cache != nil {
			defer cache.Release()
		}

		// seek to key
		if !it.Seek(key) {
			err = it.Error()
			if err == nil {
				err = errors.ErrNotFound
			}
			return
		}
		rkey, rvalue = it.Key(), it.Value()
	} else {
		err = errors.ErrNotFound
	}
	return
}
开发者ID:29n,项目名称:goleveldb,代码行数:46,代码来源:reader.go


示例9: safeQuery

// Make the actual query. Sanity checks of the iterator i is expected to
// have been done before calling this function.
func safeQuery(i iter.Iterator, req QueryRequest, res chan StoredEvent) {
	defer close(res)
	for i.Valid() {
		curKey, err := newEventStoreKey(i.Key())
		if err != nil {
			log.Println("A key could not be deserialized:")
			// Panicing here, because this error most
			// certainly needs to be looked at by a
			// an operator.
			log.Panicln(string(i.Key()))
		}

		if bytes.Compare(curKey.groupKey, eventPrefix) != 0 {
			break
		}
		if bytes.Compare(curKey.key, req.Stream) != 0 {
			break
		}

		resEvent := StoredEvent{
			curKey.keyId.toBytes(),
			Event{
				curKey.key,
				[]byte(i.Value()),
			},
		}
		res <- resEvent

		keyId := curKey.keyId.toBytes()
		if req.ToId != nil && bytes.Compare(req.ToId, keyId) == 0 {
			break
		}

		i.Next()
	}
}
开发者ID:JensRantil,项目名称:gorewind,代码行数:38,代码来源:eventstore.go


示例10: nextNode

// reads the next node record from the iterator, skipping over other
// database entries.
func nextNode(it iterator.Iterator) *Node {
	for end := false; !end; end = !it.Next() {
		id, field := splitKey(it.Key())
		if field != nodeDBDiscoverRoot {
			continue
		}
		var n Node
		if err := rlp.DecodeBytes(it.Value(), &n); err != nil {
			if glog.V(logger.Warn) {
				glog.Errorf("invalid node %x: %v", id, err)
			}
			continue
		}
		return &n
	}
	return nil
}
开发者ID:j4ustin,项目名称:go-ethereum,代码行数:19,代码来源:database.go


示例11: prev

func (h *blockHarness) prev(pref string, iter iterator.Iterator) {
	if !iter.Prev() {
		h.t.Fatalf("block: %sPrev: eoi, err=%v", pref, iter.Error())
	}
}
开发者ID:pombredanne,项目名称:goleveldb,代码行数:5,代码来源:table_test.go


示例12: next

func (h *blockHarness) next(pref string, iter iterator.Iterator) {
	if !iter.Next() {
		h.t.Fatalf("block: %sNext: eoi, err=%v", pref, iter.Error())
	}
}
开发者ID:pombredanne,项目名称:goleveldb,代码行数:5,代码来源:table_test.go


示例13: TestDb_ClosedIsClosed

func TestDb_ClosedIsClosed(t *testing.T) {
	h := newDbHarness(t)
	db := h.db

	var iter, iter2 iterator.Iterator
	var snap *Snapshot
	func() {
		defer h.close()

		h.put("k", "v")
		h.getVal("k", "v")

		iter = db.NewIterator(nil, h.ro)
		iter.Seek([]byte("k"))
		testKeyVal(t, iter, "k->v")

		var err error
		snap, err = db.GetSnapshot()
		if err != nil {
			t.Fatal("GetSnapshot: got error: ", err)
		}

		h.getValr(snap, "k", "v")

		iter2 = snap.NewIterator(nil, h.ro)
		iter2.Seek([]byte("k"))
		testKeyVal(t, iter2, "k->v")

		h.put("foo", "v2")
		h.delete("foo")

		// closing DB
		iter.Release()
		iter2.Release()
	}()

	assertErr(t, db.Put([]byte("x"), []byte("y"), h.wo), true)
	_, err := db.Get([]byte("k"), h.ro)
	assertErr(t, err, true)

	if iter.Valid() {
		t.Errorf("iter.Valid should false")
	}
	assertErr(t, iter.Error(), false)
	testKeyVal(t, iter, "->")
	if iter.Seek([]byte("k")) {
		t.Errorf("iter.Seek should false")
	}
	assertErr(t, iter.Error(), true)

	assertErr(t, iter2.Error(), false)

	_, err = snap.Get([]byte("k"), h.ro)
	assertErr(t, err, true)

	_, err = db.GetSnapshot()
	assertErr(t, err, true)

	iter3 := db.NewIterator(nil, h.ro)
	assertErr(t, iter3.Error(), true)

	iter3 = snap.NewIterator(nil, h.ro)
	assertErr(t, iter3.Error(), true)

	assertErr(t, db.Delete([]byte("k"), h.wo), true)

	_, err = db.GetProperty("leveldb.stats")
	assertErr(t, err, true)

	_, err = db.SizeOf([]util.Range{{[]byte("a"), []byte("z")}})
	assertErr(t, err, true)

	assertErr(t, db.CompactRange(util.Range{}), true)

	assertErr(t, db.Close(), true)
}
开发者ID:baa-archieve,项目名称:syncthing,代码行数:76,代码来源:db_test.go


示例14: makeItemIterator

func makeItemIterator(iter iterator.Iterator, prefix []byte) *LevelDbItemIterator {
	iter.Seek(prefix)
	return &LevelDbItemIterator{iter, prefix, nil, nil, nil}
}
开发者ID:vburenin,项目名称:firempq,代码行数:4,代码来源:iterator.go


示例15: convertFrom

func convertFrom(c *cli.Context) {
	success := true
	defaultBand := c.GlobalString("band")
	dbPath := c.GlobalString("path")

	pwd, err := os.Getwd()
	dbPath = path.Join(pwd, dbPath)

	options := &opt.Options{ErrorIfMissing: true}

	db, err := leveldb.OpenFile(dbPath, options)

	if err != nil {
		msg := fmt.Sprintf("%s %s", err, dbPath)
		panic(msg)
	}

	fmt.Println("using database:", dbPath)

	defer db.Close()

	var iter iterator.Iterator

	fmt.Println("Converting FROM band format...")

	iter = db.NewIterator(&dbutil.Range{Start: []byte("/reading/RF12:"), Limit: []byte("/reading/RF12~")}, nil)
	for iter.Next() {
		key := string(iter.Key())
		rval := iter.Value()

		kparts := strings.Split(key, "/")

		rfnet := kparts[len(kparts)-1:]
		rfparts := strings.Split(rfnet[0], ":")

		if len(rfparts) == 4 { //its an new format with band

			if rfparts[1] == defaultBand {
				fmt.Println("INFO:Downgrading:", key)

				//remove band
				copy(rfparts[1:], rfparts[1+1:])
				rfparts[len(rfparts)-1] = ""
				rfparts = rfparts[:len(rfparts)-1]

				//adjust the json structure
				var reading Reading
				err := json.Unmarshal(rval, &reading)
				if err == nil {
					id := fmt.Sprintf("%s", strings.Join(rfparts, ":"))
					reading.Id = id
					fmt.Println("INFO:New reading:", reading)
					data, err := json.Marshal(reading)
					if err == nil {

						//write a new key
						newkey := "/reading/" + id

						err = db.Put([]byte(newkey), []byte(data), nil)
						if err != nil {
							fmt.Println("ERR:Write failed for:", newkey)
							success = false
							continue
						}

						fmt.Println("INFO:New Reading Stored:", newkey)

						//remove old key
						err = db.Delete([]byte(key), nil)

						if err != nil {
							success = false
							fmt.Println("WARN: could not remove old key:", key)
						}

					}

				} else {
					fmt.Println("Err:Failed to unmarshal data:", err)
					success = false
				}

			}

		}

	}
	iter.Release()
	err = iter.Error()
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println("Downgrade finished")
	if !success {
		fmt.Println("problems detected, please review screen")
	}

}
开发者ID:TheDistractor,项目名称:convert-rf-readings,代码行数:99,代码来源:main.go



注:本文中的github.com/syndtr/goleveldb/leveldb/iterator.Iterator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap