2023-12-19 12:39:23 +00:00
|
|
|
# Nimbus-eth1
|
|
|
|
# Copyright (c) 2023 Status Research & Development GmbH
|
2023-09-18 20:20:28 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or
|
|
|
|
# distributed except according to those terms.
|
|
|
|
|
|
|
|
import
|
2023-12-20 16:19:00 +00:00
|
|
|
std/[sets, tables],
|
2023-09-18 20:20:28 +00:00
|
|
|
eth/common,
|
2023-12-20 16:19:00 +00:00
|
|
|
".."/[kvt_desc, kvt_init, kvt_layers]
|
2023-09-18 20:20:28 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public generic iterators
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
iterator walkPairsImpl*[T](
|
|
|
|
db: KvtDbRef; # Database with top layer & backend filter
|
2023-12-20 16:19:00 +00:00
|
|
|
): tuple[key: Blob, data: Blob] =
|
2023-09-18 20:20:28 +00:00
|
|
|
## Walk over all `(VertexID,VertexRef)` in the database. Note that entries
|
|
|
|
## are unsorted.
|
2023-12-20 16:19:00 +00:00
|
|
|
var seen: HashSet[Blob]
|
|
|
|
for (key,data) in db.layersWalk seen:
|
2023-09-18 20:20:28 +00:00
|
|
|
if data.isValid:
|
2023-12-20 16:19:00 +00:00
|
|
|
yield (key,data)
|
2023-09-18 20:20:28 +00:00
|
|
|
|
|
|
|
when T isnot VoidBackendRef:
|
|
|
|
mixin walk
|
|
|
|
|
2023-12-20 16:19:00 +00:00
|
|
|
for (_,key,data) in db.backend.T.walk:
|
2023-12-19 12:39:23 +00:00
|
|
|
if key notin seen and data.isValid:
|
2023-12-20 16:19:00 +00:00
|
|
|
yield (key,data)
|
2023-09-18 20:20:28 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|