本文整理匯總了Golang中github.com/jmhodges/levigo.DB.NewIterator方法的典型用法代碼示例。如果您正苦於以下問題:Golang DB.NewIterator方法的具體用法?Golang DB.NewIterator怎麽用?Golang DB.NewIterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/jmhodges/levigo.DB
的用法示例。
在下文中一共展示了DB.NewIterator方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AddressFirstSeen
// Timestamp of the block an address was first confirmed in
func AddressFirstSeen(db *levigo.DB, addr string) (timestamp uint, err error) {
timestamp = uint(0)
ro := levigo.NewReadOptions()
defer ro.Close()
it := db.NewIterator(ro)
defer it.Close()
it.Seek([]byte(fmt.Sprintf("%s-txo!", addr)))
if it.Valid() {
k := string(it.Key()[:])
data := strings.Split(k, "!")
r, _ := db.Get(ro, []byte(fmt.Sprintf("tx!%s", data[1])))
data = strings.Split(string(r[:]), ":")
ts, _ := strconv.Atoi(data[0])
timestamp = uint(ts)
return
} else {
err = errors.New("Address not found")
return
}
}
示例2: GetRange
func GetRange(db *levigo.DB, kStart []byte, kEnd []byte) (values []*KeyValue, err error) {
ro := levigo.NewReadOptions()
defer ro.Close()
it := db.NewIterator(ro)
defer it.Close()
it.Seek(kStart)
endBytes := kEnd
for {
if it.Valid() {
if bytes.Compare(it.Key(), endBytes) > 0 {
return
}
values = append(values, &KeyValue{string(it.Key()[:]), string(it.Value()[:])})
it.Next()
} else {
err = it.GetError()
return
}
}
return
}
示例3: NewIterator
func NewIterator(db *levigo.DB) *Iterator {
it := db.NewIterator(levigo.NewReadOptions())
return &Iterator{it}
}