leveled iterator range use close interval
This commit is contained in:
parent
0eb5881662
commit
09923bdf6a
|
@ -134,19 +134,18 @@ func (db *DB) NewWriteBatch() *WriteBatch {
|
|||
return wb
|
||||
}
|
||||
|
||||
//like c++ iterator, [begin, end)
|
||||
//begin should less than end
|
||||
//[begin, end] close(inclusive) interval
|
||||
//if begin is nil, we will seek to first
|
||||
//if end is nil, we will next until read last
|
||||
//if end is nil, we will seek to last
|
||||
//limit <= 0, no limit
|
||||
func (db *DB) Iterator(begin []byte, end []byte, limit int) *Iterator {
|
||||
return newIterator(db, db.iteratorOpts, begin, end, limit, forward)
|
||||
}
|
||||
|
||||
//like c++ reverse_iterator, [rbegin, rend)
|
||||
//[rbegin, rend] close(inclusive) interval
|
||||
//rbegin should bigger than rend
|
||||
//if rbegin is nil, we will seek to last
|
||||
//if end is nil, we will next until read first
|
||||
//if end is nil, we will seek to first
|
||||
//limit <= 0, no limit
|
||||
func (db *DB) ReverseIterator(rbegin []byte, rend []byte, limit int) *Iterator {
|
||||
return newIterator(db, db.iteratorOpts, rbegin, rend, limit, backward)
|
||||
|
|
|
@ -62,11 +62,11 @@ func (it *Iterator) Valid() bool {
|
|||
}
|
||||
|
||||
if it.direction == forward {
|
||||
if it.stop != nil && bytes.Compare(it.Key(), it.stop) >= 0 {
|
||||
if it.stop != nil && bytes.Compare(it.Key(), it.stop) > 0 {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
if it.stop != nil && bytes.Compare(it.Key(), it.stop) <= 0 {
|
||||
if it.stop != nil && bytes.Compare(it.Key(), it.stop) < 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ func TestIterator(t *testing.T) {
|
|||
}
|
||||
it.Close()
|
||||
|
||||
if step != 5 {
|
||||
if step != 6 {
|
||||
t.Fatal("invalid step", step)
|
||||
}
|
||||
|
||||
|
@ -245,7 +245,7 @@ func TestIterator(t *testing.T) {
|
|||
}
|
||||
it.Close()
|
||||
|
||||
if step != 2 {
|
||||
if step != 1 {
|
||||
t.Fatal("invalid step", step)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue