Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Updates orbweaver to 0.5 #24

Merged
merged 1 commit into from
Jun 7, 2024
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 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.4.1
Version: 0.5.3
Authors@R:
c(person(given = "ixpantia, SRL",
role = "cph",
Expand Down
89 changes: 28 additions & 61 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,92 +2,59 @@

S3method("$",DirectedAcyclicGraph)
S3method("$",DirectedGraph)
S3method("$",Node)
S3method("$",DirectedGraphBuilder)
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("[[",DirectedGraphBuilder)
S3method(children,DirectedAcyclicGraph)
S3method(children,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_ids,DirectedAcyclicGraph)
S3method(get_node_ids,DirectedGraph)
S3method(get_nodes,DirectedAcyclicGraph)
S3method(get_nodes,DirectedGraph)
S3method(get_parents,DirectedAcyclicGraph)
S3method(get_parents,DirectedGraph)
S3method(get_roots,DirectedAcyclicGraph)
S3method(get_roots,DirectedGraph)
S3method(get_all_leaves,DirectedAcyclicGraph)
S3method(get_all_leaves,DirectedGraph)
S3method(get_all_roots,DirectedAcyclicGraph)
S3method(get_all_roots,DirectedGraph)
S3method(get_leaves_under,DirectedAcyclicGraph)
S3method(get_leaves_under,DirectedGraph)
S3method(get_roots_over,DirectedAcyclicGraph)
S3method(get_roots_over,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(length,DirectedAcyclicGraph)
S3method(length,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(subset_graph,DirectedAcyclicGraph)
S3method(subset_graph,DirectedGraph)
S3method(update_node_data,DirectedAcyclicGraph)
S3method(update_node_data,DirectedGraph)
S3method(length,DirectedGraphBuilder)
S3method(parents,DirectedAcyclicGraph)
S3method(parents,DirectedGraph)
S3method(print,DirectedAcyclicGraph)
S3method(print,DirectedGraph)
S3method(subset,DirectedAcyclicGraph)
S3method(subset,DirectedGraph)
export(add_edge)
export(add_node)
export(add_path)
export(clear_edges)
export(deep_clone)
export(edge_exists)
export(build_acyclic)
export(build_directed)
export(children)
export(find_all_paths)
export(find_path)
export(get_children)
export(get_leaves)
export(get_node)
export(get_node_ids)
export(get_nodes)
export(get_parents)
export(get_roots)
export(get_all_leaves)
export(get_all_roots)
export(get_leaves_under)
export(get_roots_over)
export(graph_builder)
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(parents)
export(populate_edges)
export(populate_nodes)
export(remove_edge)
export(remove_node)
export(subset_graph)
export(update_node_data)
useDynLib(orbweaver, .registration = TRUE)
27 changes: 0 additions & 27 deletions R/add_edge.R

This file was deleted.

27 changes: 0 additions & 27 deletions R/add_node.R

This file was deleted.

26 changes: 0 additions & 26 deletions R/add_path.R

This file was deleted.

88 changes: 88 additions & 0 deletions R/builder.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#' @export
graph_builder <- function(type = "directed") {
DirectedGraphBuilder$new()
}

#' @title Add an edge to a graph builder
#'
#' @description
#' Adds an edge from one node to another in a
#' a directed graph builder.
#'
#' @param graph_builder A graph builder_object
#' @param from The `from` node.
#' @param to The `to` node.
#' @return The updated graph builder object
#' @export
add_edge <- function(graph_builder, from, to) {
graph_builder$add_edge(from, to)
}

#' @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_builder A graph builder_object
#' @param path A character vector that describes the path
#' @return The updated graph builder object
#' @export
add_path <- function(graph_builder, path) {
graph_builder$add_path(path)
}

#' @title Builder into a Directed Graph

#' @description
#' Builds a graph builder into a new DirectedGraph
#' object.
#'
#' NOTE: This will consume the builder. It will leave an empty
#' builder in its place.
#' @param graph_builder A graph builder object
#' @return A DirectedGraph Object
#' @export
build_directed <- function(graph_builder) {
graph_builder$build_directed()
}

#' @description
#' Builds a graph builder into a new DirectedAcyclicGraph
#' object.
#'
#' NOTE: This will consume the builder. It will leave an empty
#' builder in its place.
#' @param graph_builder A graph builder object
#' @return A DirectedAcyclicGraph Object
#' @export
build_acyclic <- function(graph_builder) {
graph_builder$build_acyclic()
}

#' @title Populates the edges of a graph from a `tibble`
#' @description Adds a set of edges from a `tibble` to a graph
#' @param graph_builder A graph builder 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 builder object
#' @export
populate_edges <- function(graph_builder, edges_df, parent_col, child_col) {
parent_col <- as.character(rlang::ensym(parent_col))
child_col <- as.character(rlang::ensym(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_builder(graph_builder, parent_iter, child_iter)
return(graph_builder)
}
68 changes: 0 additions & 68 deletions R/building.R

This file was deleted.

14 changes: 7 additions & 7 deletions R/children.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
#' Get a list of the node ids of the children of
#' the provided node.
#' @param graph A graph object
#' @param node_id The id of the node
#' @param nodes A character vector of nodes to find children for
#' @return A character vector
#' @export
get_children <- function(graph, node_id) {
UseMethod("get_children")
children <- function(graph, nodes) {
UseMethod("children")
}

#' @export
get_children.DirectedGraph <- function(graph, node_id) {
graph$children(node_id)
children.DirectedGraph <- function(graph, nodes) {
graph$children(nodes)
}

#' @export
get_children.DirectedAcyclicGraph <- function(graph, node_id) {
graph$children(node_id)
children.DirectedAcyclicGraph <- function(graph, nodes) {
graph$children(nodes)
}
Loading
Loading