pub struct DirectoryGraph<O> {
graph: DiGraph<Option<Directory>, Option<EdgeWeight>>,
digest_to_node_ix: HashMap<B3Digest, NodeIndex>,
order_validator: O,
}
Expand description
This can be used to validate and/or re-order a Directory closure (DAG of connected Directories), and their insertion order.
The DirectoryGraph is parametrized on the insertion order, and can be
constructed using the Default trait, or using with_order
if the
OrderValidator needs to be customized.
If the user is receiving directories from canonical protobuf encoding in
root-to-leaves order, and parsing them, she can call digest_allowed
before parsing the protobuf record and then add it with add_unchecked
.
All other users insert the directories via add
, in their specified order.
During insertion, we validate as much as we can at that time:
- individual validation of Directory messages
- validation of insertion order
- validation of size fields of referred Directories
Internally it keeps all received Directories in a directed graph, with node weights being the Directories and edges pointing to child/parent directories.
Once all Directories have been inserted, a validate function can be
called to perform a check for graph connectivity and ensure there’s no
disconnected components or missing nodes.
Finally, the drain_leaves_to_root
or drain_root_to_leaves
can be
chained on validate to get an iterator over the (deduplicated and)
validated list of directories in either order.
Fields§
§graph: DiGraph<Option<Directory>, Option<EdgeWeight>>
§digest_to_node_ix: HashMap<B3Digest, NodeIndex>
§order_validator: O
Implementations§
source§impl DirectoryGraph<RootToLeavesValidator>
impl DirectoryGraph<RootToLeavesValidator>
sourcepub fn digest_allowed(&self, digest: B3Digest) -> bool
pub fn digest_allowed(&self, digest: B3Digest) -> bool
If the user is parsing directories from canonical protobuf encoding, she can
call digest_allowed
before parsing the protobuf record and then add it
with add_unchecked
.
source§impl<O: OrderValidator> DirectoryGraph<O>
impl<O: OrderValidator> DirectoryGraph<O>
sourcepub fn with_order(order_validator: O) -> Self
pub fn with_order(order_validator: O) -> Self
Customize the ordering, i.e. for pre-setting the root of the RootToLeavesValidator
sourcepub fn add_order_unchecked(&mut self, directory: Directory) -> Result<(), Error>
pub fn add_order_unchecked(&mut self, directory: Directory) -> Result<(), Error>
Adds a directory which has already been confirmed to be in-order to the graph
pub fn validate(self) -> Result<ValidatedDirectoryGraph, Error>
Trait Implementations§
source§impl<O: Default> Default for DirectoryGraph<O>
impl<O: Default> Default for DirectoryGraph<O>
source§fn default() -> DirectoryGraph<O>
fn default() -> DirectoryGraph<O>
Auto Trait Implementations§
impl<O> Freeze for DirectoryGraph<O>where
O: Freeze,
impl<O> RefUnwindSafe for DirectoryGraph<O>where
O: RefUnwindSafe,
impl<O> Send for DirectoryGraph<O>where
O: Send,
impl<O> Sync for DirectoryGraph<O>where
O: Sync,
impl<O> Unpin for DirectoryGraph<O>where
O: Unpin,
impl<O> UnwindSafe for DirectoryGraph<O>where
O: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request