all: simplify and fix database iteration with prefix/start (#20808)
* core/state/snapshot: start fixing disk iterator seek * ethdb, rawdb, leveldb, memorydb: implement iterators with prefix and start * les, core/state/snapshot: iterator fixes * all: remove two iterator methods * all: rename Iteratee.NewIteratorWith -> NewIterator * ethdb: fix review concerns
This commit is contained in:
committed by
GitHub
parent
00064ddcfb
commit
6402c42b67
@ -183,23 +183,11 @@ func (db *Database) NewBatch() ethdb.Batch {
|
||||
}
|
||||
}
|
||||
|
||||
// NewIterator creates a binary-alphabetical iterator over the entire keyspace
|
||||
// contained within the leveldb database.
|
||||
func (db *Database) NewIterator() ethdb.Iterator {
|
||||
return db.db.NewIterator(new(util.Range), nil)
|
||||
}
|
||||
|
||||
// NewIteratorWithStart creates a binary-alphabetical iterator over a subset of
|
||||
// database content starting at a particular initial key (or after, if it does
|
||||
// not exist).
|
||||
func (db *Database) NewIteratorWithStart(start []byte) ethdb.Iterator {
|
||||
return db.db.NewIterator(&util.Range{Start: start}, nil)
|
||||
}
|
||||
|
||||
// NewIteratorWithPrefix creates a binary-alphabetical iterator over a subset
|
||||
// of database content with a particular key prefix.
|
||||
func (db *Database) NewIteratorWithPrefix(prefix []byte) ethdb.Iterator {
|
||||
return db.db.NewIterator(util.BytesPrefix(prefix), nil)
|
||||
// NewIterator creates a binary-alphabetical iterator over a subset
|
||||
// of database content with a particular key prefix, starting at a particular
|
||||
// initial key (or after, if it does not exist).
|
||||
func (db *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
|
||||
return db.db.NewIterator(bytesPrefixRange(prefix, start), nil)
|
||||
}
|
||||
|
||||
// Stat returns a particular internal stat of the database.
|
||||
@ -488,3 +476,12 @@ func (r *replayer) Delete(key []byte) {
|
||||
}
|
||||
r.failure = r.writer.Delete(key)
|
||||
}
|
||||
|
||||
// bytesPrefixRange returns key range that satisfy
|
||||
// - the given prefix, and
|
||||
// - the given seek position
|
||||
func bytesPrefixRange(prefix, start []byte) *util.Range {
|
||||
r := util.BytesPrefix(prefix)
|
||||
r.Start = append(r.Start, start...)
|
||||
return r
|
||||
}
|
||||
|
Reference in New Issue
Block a user