Skip to content

Commit

Permalink
Merge pull request #20 from andyquinterom/T19
Browse files Browse the repository at this point in the history
Updates to orbweaver-rs 0.2.1
  • Loading branch information
pierina-ixpantia authored May 24, 2024
2 parents 76d823e + 051a6b5 commit 9163977
Show file tree
Hide file tree
Showing 89 changed files with 2,054 additions and 1,049 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
^check$

^update_authors\.R$
^src/\.cargo$
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ src/rust/.cargo
src/rust/vendor/

docs
.vscode
.vscode
src/rust/vendor
12 changes: 8 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: orbweaver
Title: Fast and Efficient Graph Data Structures
Version: 0.0.3
Version: 0.2.1
Authors@R:
c(person(given = "ixpantia, SRL",
role = "cph",
Expand All @@ -23,9 +23,13 @@ BugReports: https://github.com/ixpantia/orbweaver/issues
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Config/rextendr/version: 0.3.1
RoxygenNote: 7.3.1
Config/rextendr/version: 0.3.1.9000
SystemRequirements: Cargo (Rust's package manager), rustc
Imports:
glue,
rlang
Suggests:
testthat (>= 3.0.0)
testthat (>= 3.0.0),
tibble
Config/testthat/edition: 3
48 changes: 38 additions & 10 deletions LICENSE.note
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ the licenses are the same as listed here.

===============================

Name: either
Files: vendor/either/*
Authors: bluss
License: MIT OR Apache-2.0

------------------------------

Name: extendr-api
Files: vendor/extendr-api/*
Authors: andy-thomason, Thomas Down, Mossa Merhi Reimert, Claus O. Wilke, Hiroaki Yutani, Ilia A. Kosenkov, Michael Milton
Expand All @@ -36,9 +29,9 @@ License: MIT

------------------------------

Name: itertools
Files: vendor/itertools/*
Authors: bluss
Name: itoa
Files: vendor/itoa/*
Authors: David Tolnay
License: MIT OR Apache-2.0

------------------------------
Expand All @@ -57,6 +50,13 @@ License: MIT OR Apache-2.0

------------------------------

Name: orbweaver
Files: vendor/orbweaver/*
Authors: ixpantia, Andrés F. Quintero
License: MIT

------------------------------

Name: paste
Files: vendor/paste/*
Authors: David Tolnay
Expand All @@ -78,6 +78,34 @@ License: MIT OR Apache-2.0

------------------------------

Name: ryu
Files: vendor/ryu/*
Authors: David Tolnay
License: Apache-2.0 OR BSL-1.0

------------------------------

Name: serde_derive
Files: vendor/serde_derive/*
Authors: Erick Tryzelaar, David Tolnay
License: MIT OR Apache-2.0

------------------------------

Name: serde_json
Files: vendor/serde_json/*
Authors: Erick Tryzelaar, David Tolnay
License: MIT OR Apache-2.0

------------------------------

Name: serde
Files: vendor/serde/*
Authors: Erick Tryzelaar, David Tolnay
License: MIT OR Apache-2.0

------------------------------

Name: syn
Files: vendor/syn/*
Authors: David Tolnay
Expand Down
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.PHONY: vendor document

vendor:
$(MAKE) -C src/rust vendor

document:
Rscript -e "rextendr::document()"

install: document
Rscript -e "devtools::install()"

test:
Rscript -e "devtools::test()"

89 changes: 76 additions & 13 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,20 +1,83 @@
# Generated by roxygen2: do not edit by hand

S3method("$",AcyclicGraph)
S3method("[[",AcyclicGraph)
S3method(as.list,AcyclicGraph)
S3method(as_graph,data.frame)
export(add_child)
S3method("$",DirectedAcyclicGraph)
S3method("$",DirectedGraph)
S3method("$",Node)
S3method("[[",DirectedAcyclicGraph)
S3method("[[",DirectedGraph)
S3method("[[",Node)
S3method(add_edge,DirectedAcyclicGraph)
S3method(add_edge,DirectedGraph)
S3method(add_node,DirectedAcyclicGraph)
S3method(add_node,DirectedGraph)
S3method(add_path,DirectedAcyclicGraph)
S3method(add_path,DirectedGraph)
S3method(clear_edges,DirectedAcyclicGraph)
S3method(clear_edges,DirectedGraph)
S3method(deep_clone,DirectedAcyclicGraph)
S3method(deep_clone,DirectedGraph)
S3method(edge_exists,DirectedAcyclicGraph)
S3method(edge_exists,DirectedGraph)
S3method(find_all_paths,DirectedAcyclicGraph)
S3method(find_all_paths,DirectedGraph)
S3method(find_path,DirectedAcyclicGraph)
S3method(find_path,DirectedGraph)
S3method(get_children,DirectedAcyclicGraph)
S3method(get_children,DirectedGraph)
S3method(get_leaves,DirectedGraph)
S3method(get_node,DirectedAcyclicGraph)
S3method(get_node,DirectedGraph)
S3method(get_node_data,Node)
S3method(get_nodes,DirectedAcyclicGraph)
S3method(get_nodes,DirectedGraph)
S3method(get_parents,DirectedAcyclicGraph)
S3method(get_parents,DirectedGraph)
S3method(graph_to_json,DirectedAcyclicGraph)
S3method(graph_to_json,DirectedGraph)
S3method(has_children,DirectedAcyclicGraph)
S3method(has_children,DirectedGraph)
S3method(has_parents,DirectedAcyclicGraph)
S3method(has_parents,DirectedGraph)
S3method(into_dag,DirectedAcyclicGraph)
S3method(into_dag,DirectedGraph)
S3method(into_directed,DirectedAcyclicGraph)
S3method(into_directed,DirectedGraph)
S3method(least_common_parents,AcyclicDirectedGraph)
S3method(least_common_parents,DirectedGraph)
S3method(populate_edges,DirectedAcyclicGraph)
S3method(populate_edges,DirectedGraph)
S3method(populate_nodes,DirectedAcyclicGraph)
S3method(populate_nodes,DirectedGraph)
S3method(remove_edge,DirectedAcyclicGraph)
S3method(remove_edge,DirectedGraph)
S3method(remove_node,DirectedAcyclicGraph)
S3method(remove_node,DirectedGraph)
S3method(set_node_data,Node)
export(add_edge)
export(add_node)
export(as_graph)
export(clone_graph)
export(filter_tree)
export(add_path)
export(clear_edges)
export(deep_clone)
export(edge_exists)
export(find_all_paths)
export(find_least_common_parents)
export(find_leaves)
export(find_roots)
export(find_path)
export(get_children)
export(get_leaves)
export(get_node)
export(get_node_data)
export(get_nodes)
export(get_parents)
export(new_graph)
export(search_for_node)
export(graph_from_json)
export(graph_to_json)
export(has_children)
export(has_parents)
export(into_dag)
export(into_directed)
export(least_common_parents)
export(new_directed_graph)
export(populate_edges)
export(populate_nodes)
export(remove_edge)
export(remove_node)
export(set_node_data)
useDynLib(orbweaver, .registration = TRUE)
27 changes: 27 additions & 0 deletions R/add_edge.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#' @title Add an edge to a graph
#'
#' @description
#' Adds an edge from one node to another in a
#' a directed graph.
#'
#' NOTE: Not all graphs are able to be modified.
#'
#' @param graph A graph object
#' @param from The id of the `from` node.
#' @param to The id of the `to` node.
#' @return The updated graph object
#' @export
add_edge <- function(graph, from, to) {
UseMethod("add_edge")
}

#' @export
add_edge.DirectedGraph <- function(graph, from, to) {
graph$add_edge(from, to)
return(graph)
}

#' @export
add_edge.DirectedAcyclicGraph <- function(graph, from, to) {
rlang::abort(err_unable_to_modify_dag)
}
27 changes: 27 additions & 0 deletions R/add_node.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#' @title Add a new node to a graph
#'
#' @description
#' Appends a new node to the graph in-place with
#' some arbitrary data.
#'
#' NOTE: Not all graphs are able to be modified.
#'
#' @param graph A graph object
#' @param node_id The unique id of the node to be added
#' @param data R object to be used as the data for the node
#' @return The updated graph object
#' @export
add_node <- function(graph, node_id, data = NULL) {
UseMethod("add_node")
}

#' @export
add_node.DirectedGraph <- function(graph, node_id, data = NULL) {
graph$add_node(node_id, data)
return(graph)
}

#' @export
add_node.DirectedAcyclicGraph <- function(graph, node_id, data = NULL) {
rlang::abort(err_unable_to_modify_dag)
}
26 changes: 26 additions & 0 deletions R/add_path.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#' @title Add a path to a graph
#'
#' @description
#' Adds all of the edges that make up the given
#' path to the graph.
#'
#' NOTE: Not all graphs are able to be modified.
#'
#' @param graph A graph object
#' @param path A character vector that describes the path
#' @return The updated graph object
#' @export
add_path <- function(graph, path) {
UseMethod("add_path")
}

#' @export
add_path.DirectedGraph <- function(graph, path) {
graph$add_path(path)
return(graph)
}

#' @export
add_path.DirectedAcyclicGraph <- function(graph, path) {
rlang::abort(err_unable_to_modify_dag)
}
1 change: 1 addition & 0 deletions R/asserts.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

68 changes: 68 additions & 0 deletions R/building.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#' @title Populates the edges of a graph from a `tibble`
#' @description Adds a set of edges from a `tibble` to a graph
#' @param graph A graph object
#' @param edges_df A `tibble` with a parent and child variable
#' @param parent_col The name of the column containing the parents
#' @param child_col The name of the column containing the children
#' @return The updated graph object
#' @export
populate_edges <- function(graph, edges_df, parent_col, child_col) {
UseMethod("populate_edges")
}

#' @export
populate_edges.DirectedGraph <- function(graph, edges_df, parent_col, child_col) {

parent_iter <- edges_df[[parent_col]]
if (!is.character(parent_iter)) {
rlang::abort(glue::glue("Column {parent_col} is not of class `character`"))
}

child_iter <- edges_df[[child_col]]
if (!is.character(child_iter)) {
rlang::abort(glue::glue("Column {child_col} is not of class `character`"))
}

rs_populate_edges_directed_graph(graph, parent_iter, child_iter)
return(graph)
}

#' @export
populate_edges.DirectedAcyclicGraph <- function(graph, edges_df, parent_col, child_col) {
rlang::abort(err_unable_to_modify_dag)
}

#' @title Populates the nodes of a graph from a `tibble`
#' @description Adds a set of nodes from a `tibble` to a graph
#' @param graph A graph object
#' @param nodes_df A `tibble` with a node id and data column
#' @param node_id_col The name of the column containing the node ids
#' @param data_col The name of the column containing the data of the nodes
#' @return The updated graph object
#' @export
populate_nodes <- function(graph, nodes_df, node_id_col, data_col = NULL) {
UseMethod("populate_nodes")
}

#' @export
populate_nodes.DirectedGraph <- function(graph, nodes_df, node_id_col, data_col = NULL) {

node_ids <- nodes_df[[node_id_col]]
if (!is.character(node_ids)) {
rlang::abort(glue::glue("Column {node_id_col} is not of class `character`"))
}

data_iter <- NULL

if (!is.null(data_col)) {
data_iter <- as.list(nodes_df[[data_col]])
}

rs_populate_nodes_directed_graph(graph, node_ids, data_iter)
return(graph)
}

#' @export
populate_nodes.DirectedAcyclicGraph <- function(graph, nodes_df, node_id_col, data_col = NULL) {
rlang::abort(err_unable_to_modify_dag)
}
Loading

0 comments on commit 9163977

Please sign in to comment.