2023-08-10 20:01:28 +00:00
|
|
|
# Nimbus - Types, data structures and shared utilities used in network sync
|
|
|
|
#
|
|
|
|
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
## Iterators for non-persistent backend of the Aristo DB
|
|
|
|
## =====================================================
|
|
|
|
##
|
|
|
|
import
|
2023-08-25 22:53:59 +00:00
|
|
|
../aristo_init/[memory_db, memory_only],
|
2023-08-10 20:01:28 +00:00
|
|
|
".."/[aristo_desc, aristo_init],
|
2023-08-25 22:53:59 +00:00
|
|
|
./walk_private
|
2023-09-18 20:20:28 +00:00
|
|
|
|
2023-08-10 20:01:28 +00:00
|
|
|
export
|
2023-08-25 22:53:59 +00:00
|
|
|
memory_db,
|
2023-08-10 20:01:28 +00:00
|
|
|
memory_only
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public iterators (all in one)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-08-11 17:23:57 +00:00
|
|
|
iterator walkVtxBe*[T: MemBackendRef|VoidBackendRef](
|
2023-08-10 20:01:28 +00:00
|
|
|
_: type T;
|
|
|
|
db: AristoDbRef;
|
|
|
|
): tuple[n: int, vid: VertexID, vtx: VertexRef] =
|
|
|
|
## Iterate over filtered memory backend or backend-less vertices. This
|
|
|
|
## function depends on the particular backend type name which must match
|
|
|
|
## the backend descriptor.
|
2023-09-15 15:23:53 +00:00
|
|
|
for (n,vid,vtx) in walkVtxBeImpl[T](db):
|
2023-08-10 20:01:28 +00:00
|
|
|
yield (n,vid,vtx)
|
|
|
|
|
2023-08-11 17:23:57 +00:00
|
|
|
iterator walkKeyBe*[T: MemBackendRef|VoidBackendRef](
|
2023-08-10 20:01:28 +00:00
|
|
|
_: type T;
|
|
|
|
db: AristoDbRef;
|
|
|
|
): tuple[n: int, vid: VertexID, key: HashKey] =
|
|
|
|
## Similar to `walkVtxBe()` but for keys.
|
2023-09-15 15:23:53 +00:00
|
|
|
for (n,vid,key) in walkKeyBeImpl[T](db):
|
2023-08-10 20:01:28 +00:00
|
|
|
yield (n,vid,key)
|
|
|
|
|
2023-09-15 15:23:53 +00:00
|
|
|
iterator walkFilBe*[T: MemBackendRef|VoidBackendRef](
|
|
|
|
be: T;
|
2023-08-25 22:53:59 +00:00
|
|
|
): tuple[n: int, qid: QueueID, filter: FilterRef] =
|
2023-09-05 13:57:20 +00:00
|
|
|
## Iterate over backend filters.
|
2023-09-15 15:23:53 +00:00
|
|
|
for (n,qid,filter) in walkFilBeImpl[T](be):
|
2023-08-25 22:53:59 +00:00
|
|
|
yield (n,qid,filter)
|
2023-08-22 18:44:54 +00:00
|
|
|
|
2023-09-15 15:23:53 +00:00
|
|
|
iterator walkFifoBe*[T: MemBackendRef|VoidBackendRef](
|
|
|
|
be: T;
|
|
|
|
): tuple[qid: QueueID, fid: FilterRef] =
|
2023-09-05 13:57:20 +00:00
|
|
|
## Walk filter slots in fifo order.
|
2023-09-15 15:23:53 +00:00
|
|
|
for (qid,filter) in walkFifoBeImpl[T](be):
|
2023-09-05 13:57:20 +00:00
|
|
|
yield (qid,filter)
|
|
|
|
|
2023-09-15 15:23:53 +00:00
|
|
|
# -----------
|
|
|
|
|
|
|
|
iterator walkPairs*[T: MemBackendRef|VoidBackendRef](
|
|
|
|
_: type T;
|
|
|
|
db: AristoDbRef;
|
|
|
|
): tuple[vid: VertexID, vtx: VertexRef] =
|
|
|
|
## Walk over all `(VertexID,VertexRef)` in the database. Note that entries
|
|
|
|
## are unsorted.
|
|
|
|
for (vid,vtx) in walkPairsImpl[T](db):
|
|
|
|
yield (vid,vtx)
|
|
|
|
|
2023-09-18 20:20:28 +00:00
|
|
|
iterator replicate*[T: MemBackendRef|VoidBackendRef](
|
|
|
|
_: type T;
|
|
|
|
db: AristoDbRef;
|
|
|
|
): tuple[vid: VertexID, key: HashKey, vtx: VertexRef, node: NodeRef] =
|
|
|
|
## Variant of `walkPairsImpl()` for legacy applications.
|
|
|
|
for (vid,key,vtx,node) in replicateImpl[T](db):
|
|
|
|
yield (vid,key,vtx,node)
|
|
|
|
|
2023-08-10 20:01:28 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|