Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "orbweaver"
version = "0.18.1"
version = "0.18.2"
edition = "2021"
authors = ["ixpantia <hola@ixpantia.com>", "Andrés F. Quintero <andres@ixpantia.com>"]
description = "Crate designed for effortless construction and analysis of graph data structures."
Expand Down
15 changes: 12 additions & 3 deletions src/directed/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::rc::Rc;
use crate::utils::{interner::InternerBuilder, node_map::NodeMap, sym::Sym};
use rayon::prelude::*;

use super::{DirectedAcyclicGraph, DirectedGraph, GraphHasCycle};
use super::{DirectedAcyclicGraph, DirectedGraph, GraphBuilderError, GraphHasCycle};

#[derive(Clone)]
pub struct DirectedGraphBuilder {
Expand Down Expand Up @@ -54,12 +54,21 @@ impl DirectedGraphBuilder {
self.children.push(to);
self
}
pub fn add_path(&mut self, path: impl IntoIterator<Item = impl AsRef<str>>) -> &mut Self {
pub fn add_path(
&mut self,
path: impl IntoIterator<Item = impl AsRef<str>>,
) -> Result<&mut Self, GraphBuilderError> {
let mut path = path.into_iter().peekable();

// if it's length 1 (if peek is None) we return an error
if path.peek().is_none() {
return Err(GraphBuilderError::LengthOnePath);
}

while let (Some(from), Some(to)) = (path.next(), path.peek()) {
self.add_edge(from.as_ref(), to.as_ref());
}
self
Ok(self)
}

pub fn build_directed(self) -> DirectedGraph {
Expand Down
Loading