2023-12-19 12:39:23 +00:00
|
|
|
# nimbus-eth1
|
Core db update storage root management for sub tries (#1964)
* Aristo: Re-phrase `LayerDelta` and `LayerFinal` as object references
why:
Avoids copying in some cases
* Fix copyright header
* Aristo: Verify `leafTie.root` function argument for `merge()` proc
why:
Zero root will lead to inconsistent DB entry
* Aristo: Update failure condition for hash labels compiler `hashify()`
why:
Node need not be rejected as long as links are on the schedule. In
that case, `redo[]` is to become `wff.base[]` at a later stage.
This amends an earlier fix, part of #1952 by also testing against
the target nodes of the `wff.base[]` sets.
* Aristo: Add storage root glue record to `hashify()` schedule
why:
An account leaf node might refer to a non-resolvable storage root ID.
Storage root node chains will end up at the storage root. So the link
`storage-root->account-leaf` needs an extra item in the schedule.
* Aristo: fix error code returned by `fetchPayload()`
details:
Final error code is implied by the error code form the `hikeUp()`
function.
* CoreDb: Discard `createOk` argument in API `getRoot()` function
why:
Not needed for the legacy DB. For the `Arsto` DB, a lazy approach is
implemented where a stprage root node is created on-the-fly.
* CoreDb: Prevent `$$` logging in some cases
why:
Logging the function `$$` is not useful when it is used for internal
use, i.e. retrieving an an error text for logging.
* CoreDb: Add `tryHashFn()` to API for pretty printing
why:
Pretty printing must not change the hashification status for the
`Aristo` DB. So there is an independent API wrapper for getting the
node hash which never updated the hashes.
* CoreDb: Discard `update` argument in API `hash()` function
why:
When calling the API function `hash()`, the latest state is always
wanted. For a version that uses the current state as-is without checking,
the function `tryHash()` was added to the backend.
* CoreDb: Update opaque vertex ID objects for the `Aristo` backend
why:
For `Aristo`, vID objects encapsulate a numeric `VertexID`
referencing a vertex (rather than a node hash as used on the
legacy backend.) For storage sub-tries, there might be no initial
vertex known when the descriptor is created. So opaque vertex ID
objects are supported without a valid `VertexID` which will be
initalised on-the-fly when the first item is merged.
* CoreDb: Add pretty printer for opaque vertex ID objects
* Cosmetics, printing profiling data
* CoreDb: Fix segfault in `Aristo` backend when creating MPT descriptor
why:
Missing initialisation error
* CoreDb: Allow MPT to inherit shared context on `Aristo` backend
why:
Creates descriptors with different storage roots for the same
shared `Aristo` DB descriptor.
* Cosmetics, update diagnostic message items for `Aristo` backend
* Fix Copyright year
2024-01-11 19:11:38 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-12-19 12:39:23 +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.
|
|
|
|
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
|
|
|
std/[algorithm, sequtils, sets, tables],
|
|
|
|
eth/common,
|
|
|
|
results,
|
|
|
|
./aristo_desc
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Private functions
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
func dup(sTab: Table[VertexID,VertexRef]): Table[VertexID,VertexRef] =
|
|
|
|
## Explicit dup for `VertexRef` values
|
|
|
|
for (k,v) in sTab.pairs:
|
|
|
|
result[k] = v.dup
|
|
|
|
|
2024-02-14 19:11:59 +00:00
|
|
|
func getLebalOrVoid(stack: seq[LayerRef]; key: HashKey): HashSet[VertexID] =
|
2023-12-19 12:39:23 +00:00
|
|
|
# Helper: get next set of vertex IDs from stack.
|
2023-12-20 16:19:00 +00:00
|
|
|
for w in stack.reversed:
|
2024-02-14 19:11:59 +00:00
|
|
|
w.delta.pAmk.withValue(key,value):
|
2023-12-19 12:39:23 +00:00
|
|
|
return value[]
|
|
|
|
|
2023-12-20 16:19:00 +00:00
|
|
|
proc recalcLebal(layer: var LayerObj) =
|
|
|
|
## Calculate reverse `kMap[]` for final (aka zero) layer
|
|
|
|
layer.delta.pAmk.clear
|
2024-02-14 19:11:59 +00:00
|
|
|
for (vid,key) in layer.delta.kMap.pairs:
|
|
|
|
if key.isValid:
|
|
|
|
layer.delta.pAmk.withValue(key, value):
|
2023-12-20 16:19:00 +00:00
|
|
|
value[].incl vid
|
|
|
|
do:
|
2024-02-14 19:11:59 +00:00
|
|
|
layer.delta.pAmk[key] = @[vid].toHashSet
|
2023-12-20 16:19:00 +00:00
|
|
|
|
2023-12-19 12:39:23 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public getters: lazy value lookup for read only versions
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
func lTab*(db: AristoDbRef): Table[LeafTie,VertexID] =
|
|
|
|
db.top.final.lTab
|
|
|
|
|
|
|
|
func pPrf*(db: AristoDbRef): HashSet[VertexID] =
|
|
|
|
db.top.final.pPrf
|
|
|
|
|
|
|
|
func vGen*(db: AristoDbRef): seq[VertexID] =
|
|
|
|
db.top.final.vGen
|
|
|
|
|
|
|
|
func dirty*(db: AristoDbRef): bool =
|
|
|
|
db.top.final.dirty
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public getters/helpers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
func nLayersVtx*(db: AristoDbRef): int =
|
2024-02-14 19:11:59 +00:00
|
|
|
## Number of vertex ID/vertex entries on the cache layers. This is an upper bound
|
|
|
|
## for the number of effective vertex ID mappings held on the cache layers as
|
|
|
|
## there might be duplicate entries for the same vertex ID on different layers.
|
|
|
|
##
|
2023-12-19 12:39:23 +00:00
|
|
|
db.stack.mapIt(it.delta.sTab.len).foldl(a + b, db.top.delta.sTab.len)
|
|
|
|
|
2024-02-14 19:11:59 +00:00
|
|
|
func nLayersKey*(db: AristoDbRef): int =
|
|
|
|
## Number of vertex ID/key entries on the cache layers. This is an upper bound
|
|
|
|
## for the number of effective vertex ID mappingss held on the cache layers as
|
|
|
|
## there might be duplicate entries for the same vertex ID on different layers.
|
|
|
|
##
|
2023-12-19 12:39:23 +00:00
|
|
|
db.stack.mapIt(it.delta.kMap.len).foldl(a + b, db.top.delta.kMap.len)
|
|
|
|
|
2024-02-14 19:11:59 +00:00
|
|
|
func nLayersYek*(db: AristoDbRef): int =
|
|
|
|
## Number of key/vertex IDs reverse lookup entries on the cache layers. This
|
|
|
|
## is an upper bound for the number of effective key mappingss held on the
|
|
|
|
## cache layers as there might be duplicate entries for the same key on
|
|
|
|
## different layers.
|
|
|
|
##
|
2023-12-19 12:39:23 +00:00
|
|
|
db.stack.mapIt(it.delta.pAmk.len).foldl(a + b, db.top.delta.pAmk.len)
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions: get variants
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc layersGetVtx*(db: AristoDbRef; vid: VertexID): Result[VertexRef,void] =
|
|
|
|
## Find a vertex on the cache layers. An `ok()` result might contain a
|
|
|
|
## `nil` vertex if it is stored on the cache that way.
|
|
|
|
##
|
|
|
|
if db.top.delta.sTab.hasKey vid:
|
|
|
|
return ok(db.top.delta.sTab.getOrVoid vid)
|
|
|
|
|
|
|
|
for w in db.stack.reversed:
|
|
|
|
if w.delta.sTab.hasKey vid:
|
|
|
|
return ok(w.delta.sTab.getOrVoid vid)
|
|
|
|
|
|
|
|
err()
|
|
|
|
|
|
|
|
proc layersGetVtxOrVoid*(db: AristoDbRef; vid: VertexID): VertexRef =
|
|
|
|
## Simplified version of `layersGetVtx()`
|
|
|
|
db.layersGetVtx(vid).valueOr: VertexRef(nil)
|
|
|
|
|
|
|
|
|
2024-02-14 19:11:59 +00:00
|
|
|
proc layersGetKey*(db: AristoDbRef; vid: VertexID): Result[HashKey,void] =
|
|
|
|
## Find a hash key on the cache layers. An `ok()` result might contain a void
|
|
|
|
## hash key if it is stored on the cache that way.
|
2023-12-19 12:39:23 +00:00
|
|
|
##
|
|
|
|
if db.top.delta.kMap.hasKey vid:
|
2024-02-01 21:27:48 +00:00
|
|
|
# This is ok regardless of the `dirty` flag. If this vertex has become
|
|
|
|
# dirty, there is an empty `kMap[]` entry on this layer.
|
2023-12-19 12:39:23 +00:00
|
|
|
return ok(db.top.delta.kMap.getOrVoid vid)
|
|
|
|
|
|
|
|
for w in db.stack.reversed:
|
|
|
|
if w.delta.kMap.hasKey vid:
|
2024-02-01 21:27:48 +00:00
|
|
|
# Same reasoning as above regarding the `dirty` flag.
|
2023-12-19 12:39:23 +00:00
|
|
|
return ok(w.delta.kMap.getOrVoid vid)
|
|
|
|
|
|
|
|
err()
|
|
|
|
|
|
|
|
proc layersGetKeyOrVoid*(db: AristoDbRef; vid: VertexID): HashKey =
|
2024-02-14 19:11:59 +00:00
|
|
|
## Simplified version of `layersGetkey()`
|
2023-12-19 12:39:23 +00:00
|
|
|
db.layersGetKey(vid).valueOr: VOID_HASH_KEY
|
|
|
|
|
|
|
|
|
2024-02-14 19:11:59 +00:00
|
|
|
proc layersGetYek*(
|
2023-12-19 12:39:23 +00:00
|
|
|
db: AristoDbRef;
|
2024-02-14 19:11:59 +00:00
|
|
|
key: HashKey;
|
2023-12-19 12:39:23 +00:00
|
|
|
): Result[HashSet[VertexID],void] =
|
2024-02-14 19:11:59 +00:00
|
|
|
## Inverse of `layersGetKey()`. For a given argumnt `key`, finds all vertex IDs
|
|
|
|
## that have `layersGetKey()` return this very `key` value for the argument
|
2023-12-19 12:39:23 +00:00
|
|
|
## vertex IDs.
|
2024-02-14 19:11:59 +00:00
|
|
|
if db.top.delta.pAmk.hasKey key:
|
|
|
|
return ok(db.top.delta.pAmk.getOrVoid key)
|
2023-12-19 12:39:23 +00:00
|
|
|
|
|
|
|
for w in db.stack.reversed:
|
2024-02-14 19:11:59 +00:00
|
|
|
if w.delta.pAmk.hasKey key:
|
|
|
|
return ok(w.delta.pAmk.getOrVoid key)
|
2023-12-19 12:39:23 +00:00
|
|
|
|
|
|
|
err()
|
|
|
|
|
2024-02-14 19:11:59 +00:00
|
|
|
proc layersGetYekOrVoid*(db: AristoDbRef; key: HashKey): HashSet[VertexID] =
|
2023-12-19 12:39:23 +00:00
|
|
|
## Simplified version of `layersGetVidsOrVoid()`
|
2024-02-14 19:11:59 +00:00
|
|
|
db.layersGetYek(key).valueOr: EmptyVidSet
|
2023-12-19 12:39:23 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions: put variants
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc layersPutVtx*(db: AristoDbRef; vid: VertexID; vtx: VertexRef) =
|
|
|
|
## Store a (potentally empty) vertex on the top layer
|
|
|
|
db.top.delta.sTab[vid] = vtx
|
|
|
|
db.top.final.dirty = true # Modified top cache layers
|
|
|
|
|
|
|
|
proc layersResVtx*(db: AristoDbRef; vid: VertexID) =
|
|
|
|
## Shortcut for `db.layersPutVtx(vid, VertexRef(nil))`. It is sort of the
|
|
|
|
## equivalent of a delete function.
|
|
|
|
db.layersPutVtx(vid, VertexRef(nil))
|
|
|
|
|
|
|
|
|
2024-02-14 19:11:59 +00:00
|
|
|
proc layersPutKey*(db: AristoDbRef; vid: VertexID; key: HashKey) =
|
|
|
|
## Store a (potentally void) hash key on the top layer
|
2023-12-19 12:39:23 +00:00
|
|
|
|
2024-02-14 19:11:59 +00:00
|
|
|
# Get previous key
|
|
|
|
let prvKey = db.top.delta.kMap.getOrVoid vid
|
|
|
|
|
|
|
|
# Update key on `kMap:key->vid` mapping table
|
|
|
|
db.top.delta.kMap[vid] = key
|
2023-12-19 12:39:23 +00:00
|
|
|
db.top.final.dirty = true # Modified top cache layers
|
|
|
|
|
|
|
|
# Clear previous value on reverse table if it has changed
|
2024-02-14 19:11:59 +00:00
|
|
|
if prvKey.isValid and prvKey != key:
|
2023-12-20 16:19:00 +00:00
|
|
|
var vidsLen = -1
|
2024-02-14 19:11:59 +00:00
|
|
|
db.top.delta.pAmk.withValue(prvKey, value):
|
2023-12-19 12:39:23 +00:00
|
|
|
value[].excl vid
|
2023-12-20 16:19:00 +00:00
|
|
|
vidsLen = value[].len
|
2023-12-19 12:39:23 +00:00
|
|
|
do: # provide empty lookup
|
2024-02-14 19:11:59 +00:00
|
|
|
let vids = db.stack.getLebalOrVoid(prvKey)
|
2023-12-20 16:19:00 +00:00
|
|
|
if vids.isValid and vid in vids:
|
|
|
|
# This entry supersedes non-emtpty changed ones from lower levels
|
2024-02-14 19:11:59 +00:00
|
|
|
db.top.delta.pAmk[prvKey] = vids - @[vid].toHashSet
|
|
|
|
if vidsLen == 0 and not db.stack.getLebalOrVoid(prvKey).isValid:
|
2023-12-20 16:19:00 +00:00
|
|
|
# There is no non-emtpty entry on lower levels, so ledete this one
|
2024-02-14 19:11:59 +00:00
|
|
|
db.top.delta.pAmk.del prvKey
|
2023-12-19 12:39:23 +00:00
|
|
|
|
|
|
|
# Add updated value on reverse table if non-zero
|
2024-02-14 19:11:59 +00:00
|
|
|
if key.isValid:
|
|
|
|
db.top.delta.pAmk.withValue(key, value):
|
2023-12-19 12:39:23 +00:00
|
|
|
value[].incl vid
|
|
|
|
do: # else if not found: need to merge with value set from lower layer
|
2024-02-14 19:11:59 +00:00
|
|
|
db.top.delta.pAmk[key] = db.stack.getLebalOrVoid(key) + @[vid].toHashSet
|
2023-12-19 12:39:23 +00:00
|
|
|
|
|
|
|
|
2024-02-14 19:11:59 +00:00
|
|
|
proc layersResKey*(db: AristoDbRef; vid: VertexID) =
|
|
|
|
## Shortcut for `db.layersPutKey(vid, VOID_HASH_KEY)`. It is sort of the
|
2023-12-19 12:39:23 +00:00
|
|
|
## equivalent of a delete function.
|
2024-02-14 19:11:59 +00:00
|
|
|
db.layersPutKey(vid, VOID_HASH_KEY)
|
2023-12-19 12:39:23 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-12-20 16:19:00 +00:00
|
|
|
proc layersMergeOnto*(src: LayerRef; trg: var LayerObj; stack: seq[LayerRef]) =
|
2023-12-19 12:39:23 +00:00
|
|
|
## Merges the argument `src` into the argument `trg` and returns `trg`. For
|
|
|
|
## the result layer, the `txUid` value set to `0`.
|
2023-12-20 16:19:00 +00:00
|
|
|
##
|
2023-12-19 12:39:23 +00:00
|
|
|
trg.final = src.final
|
|
|
|
trg.txUid = 0
|
|
|
|
|
|
|
|
for (vid,vtx) in src.delta.sTab.pairs:
|
|
|
|
trg.delta.sTab[vid] = vtx
|
2024-02-14 19:11:59 +00:00
|
|
|
for (vid,key) in src.delta.kMap.pairs:
|
|
|
|
trg.delta.kMap[vid] = key
|
2023-12-19 12:39:23 +00:00
|
|
|
|
2023-12-20 16:19:00 +00:00
|
|
|
if stack.len == 0:
|
|
|
|
# Re-calculate `pAmk[]`
|
|
|
|
trg.recalcLebal()
|
|
|
|
else:
|
2024-02-14 19:11:59 +00:00
|
|
|
# Merge reverse `kMap[]` layers. Empty key set images are ignored unless
|
2023-12-20 16:19:00 +00:00
|
|
|
# they supersede non-empty values on the argument `stack[]`.
|
2024-02-14 19:11:59 +00:00
|
|
|
for (key,vids) in src.delta.pAmk.pairs:
|
|
|
|
if 0 < vids.len or stack.getLebalOrVoid(key).isValid:
|
|
|
|
trg.delta.pAmk[key] = vids
|
2023-12-19 12:39:23 +00:00
|
|
|
|
|
|
|
|
2023-12-20 16:19:00 +00:00
|
|
|
func layersCc*(db: AristoDbRef; level = high(int)): LayerRef =
|
2023-12-19 12:39:23 +00:00
|
|
|
## Provide a collapsed copy of layers up to a particular transaction level.
|
|
|
|
## If the `level` argument is too large, the maximum transaction level is
|
|
|
|
## returned. For the result layer, the `txUid` value set to `0`.
|
2023-12-20 16:19:00 +00:00
|
|
|
##
|
|
|
|
let layers = if db.stack.len <= level: db.stack & @[db.top]
|
|
|
|
else: db.stack[0 .. level]
|
|
|
|
|
|
|
|
# Set up initial layer (bottom layer)
|
|
|
|
result = LayerRef(
|
Core db update storage root management for sub tries (#1964)
* Aristo: Re-phrase `LayerDelta` and `LayerFinal` as object references
why:
Avoids copying in some cases
* Fix copyright header
* Aristo: Verify `leafTie.root` function argument for `merge()` proc
why:
Zero root will lead to inconsistent DB entry
* Aristo: Update failure condition for hash labels compiler `hashify()`
why:
Node need not be rejected as long as links are on the schedule. In
that case, `redo[]` is to become `wff.base[]` at a later stage.
This amends an earlier fix, part of #1952 by also testing against
the target nodes of the `wff.base[]` sets.
* Aristo: Add storage root glue record to `hashify()` schedule
why:
An account leaf node might refer to a non-resolvable storage root ID.
Storage root node chains will end up at the storage root. So the link
`storage-root->account-leaf` needs an extra item in the schedule.
* Aristo: fix error code returned by `fetchPayload()`
details:
Final error code is implied by the error code form the `hikeUp()`
function.
* CoreDb: Discard `createOk` argument in API `getRoot()` function
why:
Not needed for the legacy DB. For the `Arsto` DB, a lazy approach is
implemented where a stprage root node is created on-the-fly.
* CoreDb: Prevent `$$` logging in some cases
why:
Logging the function `$$` is not useful when it is used for internal
use, i.e. retrieving an an error text for logging.
* CoreDb: Add `tryHashFn()` to API for pretty printing
why:
Pretty printing must not change the hashification status for the
`Aristo` DB. So there is an independent API wrapper for getting the
node hash which never updated the hashes.
* CoreDb: Discard `update` argument in API `hash()` function
why:
When calling the API function `hash()`, the latest state is always
wanted. For a version that uses the current state as-is without checking,
the function `tryHash()` was added to the backend.
* CoreDb: Update opaque vertex ID objects for the `Aristo` backend
why:
For `Aristo`, vID objects encapsulate a numeric `VertexID`
referencing a vertex (rather than a node hash as used on the
legacy backend.) For storage sub-tries, there might be no initial
vertex known when the descriptor is created. So opaque vertex ID
objects are supported without a valid `VertexID` which will be
initalised on-the-fly when the first item is merged.
* CoreDb: Add pretty printer for opaque vertex ID objects
* Cosmetics, printing profiling data
* CoreDb: Fix segfault in `Aristo` backend when creating MPT descriptor
why:
Missing initialisation error
* CoreDb: Allow MPT to inherit shared context on `Aristo` backend
why:
Creates descriptors with different storage roots for the same
shared `Aristo` DB descriptor.
* Cosmetics, update diagnostic message items for `Aristo` backend
* Fix Copyright year
2024-01-11 19:11:38 +00:00
|
|
|
final: layers[^1].final.dup, # Pre-merged/final values
|
|
|
|
delta: LayerDeltaRef(
|
2023-12-20 16:19:00 +00:00
|
|
|
sTab: layers[0].delta.sTab.dup, # explicit dup for ref values
|
|
|
|
kMap: layers[0].delta.kMap))
|
|
|
|
|
|
|
|
# Consecutively merge other layers on top
|
|
|
|
for n in 1 ..< layers.len:
|
|
|
|
for (vid,vtx) in layers[n].delta.sTab.pairs:
|
|
|
|
result.delta.sTab[vid] = vtx
|
2024-02-14 19:11:59 +00:00
|
|
|
for (vid,key) in layers[n].delta.kMap.pairs:
|
|
|
|
result.delta.kMap[vid] = key
|
2023-12-20 16:19:00 +00:00
|
|
|
|
|
|
|
# Re-calculate `pAmk[]`
|
|
|
|
result[].recalcLebal()
|
2023-12-19 12:39:23 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public iterators
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
iterator layersWalkVtx*(
|
|
|
|
db: AristoDbRef;
|
|
|
|
seen: var HashSet[VertexID];
|
|
|
|
): tuple[vid: VertexID, vtx: VertexRef] =
|
|
|
|
## Walk over all `(VertexID,VertexRef)` pairs on the cache layers. Note that
|
|
|
|
## entries are unsorted.
|
|
|
|
##
|
|
|
|
## The argument `seen` collects a set of all visited vertex IDs including
|
|
|
|
## the one with a zero vertex which are othewise skipped by the iterator.
|
|
|
|
## The `seen` argument must not be modified while the iterator is active.
|
|
|
|
##
|
|
|
|
for (vid,vtx) in db.top.delta.sTab.pairs:
|
|
|
|
yield (vid,vtx)
|
|
|
|
seen.incl vid
|
|
|
|
|
|
|
|
for w in db.stack.reversed:
|
|
|
|
for (vid,vtx) in w.delta.sTab.pairs:
|
|
|
|
if vid notin seen:
|
|
|
|
yield (vid,vtx)
|
|
|
|
seen.incl vid
|
|
|
|
|
|
|
|
iterator layersWalkVtx*(
|
|
|
|
db: AristoDbRef;
|
|
|
|
): tuple[vid: VertexID, vtx: VertexRef] =
|
|
|
|
## Variant of `layersWalkVtx()`.
|
|
|
|
var seen: HashSet[VertexID]
|
|
|
|
for (vid,vtx) in db.layersWalkVtx seen:
|
|
|
|
yield (vid,vtx)
|
|
|
|
|
|
|
|
|
2024-02-14 19:11:59 +00:00
|
|
|
iterator layersWalkKey*(
|
2023-12-19 12:39:23 +00:00
|
|
|
db: AristoDbRef;
|
2024-02-14 19:11:59 +00:00
|
|
|
): tuple[vid: VertexID, key: HashKey] =
|
|
|
|
## Walk over all `(VertexID,HashKey)` pairs on the cache layers. Note that
|
2023-12-19 12:39:23 +00:00
|
|
|
## entries are unsorted.
|
|
|
|
var seen: HashSet[VertexID]
|
2024-02-14 19:11:59 +00:00
|
|
|
for (vid,key) in db.top.delta.kMap.pairs:
|
|
|
|
yield (vid,key)
|
2023-12-19 12:39:23 +00:00
|
|
|
seen.incl vid
|
|
|
|
|
|
|
|
for w in db.stack.reversed:
|
2024-02-14 19:11:59 +00:00
|
|
|
for (vid,key) in w.delta.kMap.pairs:
|
2023-12-19 12:39:23 +00:00
|
|
|
if vid notin seen:
|
2024-02-14 19:11:59 +00:00
|
|
|
yield (vid,key)
|
2023-12-19 12:39:23 +00:00
|
|
|
seen.incl vid
|
|
|
|
|
|
|
|
|
2024-02-14 19:11:59 +00:00
|
|
|
iterator layersWalkYek*(
|
2023-12-19 12:39:23 +00:00
|
|
|
db: AristoDbRef;
|
2024-02-14 19:11:59 +00:00
|
|
|
): tuple[key: HashKey, vids: HashSet[VertexID]] =
|
|
|
|
## Walk over `(HashKey,HashSet[VertexID])` pairs.
|
|
|
|
var seen: HashSet[HashKey]
|
|
|
|
for (key,vids) in db.top.delta.pAmk.pairs:
|
|
|
|
yield (key,vids)
|
|
|
|
seen.incl key
|
2023-12-19 12:39:23 +00:00
|
|
|
|
|
|
|
for w in db.stack.reversed:
|
2024-02-14 19:11:59 +00:00
|
|
|
for (key,vids) in w.delta.pAmk.pairs:
|
|
|
|
if key notin seen:
|
|
|
|
yield (key,vids)
|
|
|
|
seen.incl key
|
2023-12-19 12:39:23 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|