Skip to content
Open
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
18 changes: 9 additions & 9 deletions R/aaa-cliques.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ cliques_impl <- function(
max
)
if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}
res
}
Expand Down Expand Up @@ -163,7 +163,7 @@ largest_cliques_impl <- function(
graph
)
if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}
res
}
Expand Down Expand Up @@ -303,7 +303,7 @@ maximal_cliques_impl <- function(
max_size
)
if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}
res
}
Expand Down Expand Up @@ -338,7 +338,7 @@ maximal_cliques_subset_impl <- function(
max_size
)
if (igraph_opt("return.vs.es")) {
res$res <- lapply(res$res, unsafe_create_vs, graph = graph, verts = V(graph))
res$res <- create_vs_list(graph, res$res)
}
if (!details) {
res <- res$res
Expand Down Expand Up @@ -383,7 +383,7 @@ independent_vertex_sets_impl <- function(
max_size
)
if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}
res
}
Expand Down Expand Up @@ -420,7 +420,7 @@ largest_independent_vertex_sets_impl <- function(
graph
)
if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}
res
}
Expand All @@ -438,7 +438,7 @@ maximal_independent_vertex_sets_impl <- function(
graph
)
if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}
res
}
Expand Down Expand Up @@ -468,7 +468,7 @@ largest_weighted_cliques_impl <- function(
vertex_weights
)
if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}
res
}
Expand Down Expand Up @@ -531,7 +531,7 @@ weighted_cliques_impl <- function(
maximal
)
if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}
res
}
2 changes: 1 addition & 1 deletion R/aaa-cycles.R
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ simple_cycles_impl <- function(
max_cycle_length
)
if (igraph_opt("return.vs.es")) {
res$vertices <- lapply(res$vertices, unsafe_create_vs, graph = graph, verts = V(graph))
res$vertices <- create_vs_list(graph, res$vertices)
}
if (igraph_opt("return.vs.es")) {
res$edges <- lapply(res$edges, unsafe_create_es, graph = graph, es = E(graph))
Expand Down
6 changes: 3 additions & 3 deletions R/aaa-flows.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cohesive_blocks_impl <- function(
graph
)
if (igraph_opt("return.vs.es")) {
res$blocks <- lapply(res$blocks, unsafe_create_vs, graph = graph, verts = V(graph))
res$blocks <- create_vs_list(graph, res$blocks)
}
class(res) <- "cohesiveBlocks"
res
Expand Down Expand Up @@ -176,7 +176,7 @@ all_st_cuts_impl <- function(
res$cuts <- lapply(res$cuts, unsafe_create_es, graph = graph, es = E(graph))
}
if (igraph_opt("return.vs.es")) {
res$partition1s <- lapply(res$partition1s, unsafe_create_vs, graph = graph, verts = V(graph))
res$partition1s <- create_vs_list(graph, res$partition1s)
}
res
}
Expand Down Expand Up @@ -225,7 +225,7 @@ all_st_mincuts_impl <- function(
res$cuts <- lapply(res$cuts, unsafe_create_es, graph = graph, es = E(graph))
}
if (igraph_opt("return.vs.es")) {
res$partition1s <- lapply(res$partition1s, unsafe_create_vs, graph = graph, verts = V(graph))
res$partition1s <- create_vs_list(graph, res$partition1s)
}
res
}
Expand Down
4 changes: 2 additions & 2 deletions R/aaa-graphlets.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ graphlets_candidate_basis_impl <- function(
weights
)
if (igraph_opt("return.vs.es")) {
res$cliques <- lapply(res$cliques, unsafe_create_vs, graph = graph, verts = V(graph))
res$cliques <- create_vs_list(graph, res$cliques)
}
res
}
Expand Down Expand Up @@ -57,7 +57,7 @@ graphlets_impl <- function(
niter
)
if (igraph_opt("return.vs.es")) {
res$cliques <- lapply(res$cliques, unsafe_create_vs, graph = graph, verts = V(graph))
res$cliques <- create_vs_list(graph, res$cliques)
}
res
}
Expand Down
2 changes: 1 addition & 1 deletion R/aaa-isomorphism.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ automorphism_group_impl <- function(
sh
)
if (igraph_opt("return.vs.es")) {
res$generators <- lapply(res$generators, unsafe_create_vs, graph = graph, verts = V(graph))
res$generators <- create_vs_list(graph, res$generators)
}
if (!details) {
res <- res$generators
Expand Down
14 changes: 7 additions & 7 deletions R/aaa-paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ get_all_shortest_paths_dijkstra_impl <- function(
mode
)
if (igraph_opt("return.vs.es")) {
res$vpaths <- lapply(res$vpaths, unsafe_create_vs, graph = graph, verts = V(graph))
res$vpaths <- create_vs_list(graph, res$vpaths)
}
if (igraph_opt("return.vs.es")) {
res$epaths <- lapply(res$epaths, unsafe_create_es, graph = graph, es = E(graph))
Expand Down Expand Up @@ -826,7 +826,7 @@ get_all_shortest_paths_impl <- function(
mode
)
if (igraph_opt("return.vs.es")) {
res$vpaths <- lapply(res$vpaths, unsafe_create_vs, graph = graph, verts = V(graph))
res$vpaths <- create_vs_list(graph, res$vpaths)
}
if (igraph_opt("return.vs.es")) {
res$epaths <- lapply(res$epaths, unsafe_create_es, graph = graph, es = E(graph))
Expand Down Expand Up @@ -931,7 +931,7 @@ get_k_shortest_paths_impl <- function(
mode
)
if (igraph_opt("return.vs.es")) {
res$vpaths <- lapply(res$vpaths, unsafe_create_vs, graph = graph, verts = V(graph))
res$vpaths <- create_vs_list(graph, res$vpaths)
}
if (igraph_opt("return.vs.es")) {
res$epaths <- lapply(res$epaths, unsafe_create_es, graph = graph, es = E(graph))
Expand Down Expand Up @@ -1206,7 +1206,7 @@ get_shortest_paths_bellman_ford_impl <- function(
mode
)
if (igraph_opt("return.vs.es")) {
res$vertices <- lapply(res$vertices, unsafe_create_vs, graph = graph, verts = V(graph))
res$vertices <- create_vs_list(graph, res$vertices)
}
if (igraph_opt("return.vs.es")) {
res$edges <- lapply(res$edges, unsafe_create_es, graph = graph, es = E(graph))
Expand Down Expand Up @@ -1258,7 +1258,7 @@ get_shortest_paths_dijkstra_impl <- function(
mode
)
if (igraph_opt("return.vs.es")) {
res$vertices <- lapply(res$vertices, unsafe_create_vs, graph = graph, verts = V(graph))
res$vertices <- create_vs_list(graph, res$vertices)
}
if (igraph_opt("return.vs.es")) {
res$edges <- lapply(res$edges, unsafe_create_es, graph = graph, es = E(graph))
Expand Down Expand Up @@ -1300,7 +1300,7 @@ get_shortest_paths_impl <- function(
mode
)
if (igraph_opt("return.vs.es")) {
res$vertices <- lapply(res$vertices, unsafe_create_vs, graph = graph, verts = V(graph))
res$vertices <- create_vs_list(graph, res$vertices)
}
if (igraph_opt("return.vs.es")) {
res$edges <- lapply(res$edges, unsafe_create_es, graph = graph, es = E(graph))
Expand Down Expand Up @@ -1453,7 +1453,7 @@ get_widest_paths_impl <- function(
mode
)
if (igraph_opt("return.vs.es")) {
res$vertices <- lapply(res$vertices, unsafe_create_vs, graph = graph, verts = V(graph))
res$vertices <- create_vs_list(graph, res$vertices)
}
if (igraph_opt("return.vs.es")) {
res$edges <- lapply(res$edges, unsafe_create_es, graph = graph, es = E(graph))
Expand Down
4 changes: 2 additions & 2 deletions R/aaa-separators.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ all_minimal_st_separators_impl <- function(
graph
)
if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}
res
}
Expand Down Expand Up @@ -86,7 +86,7 @@ minimum_size_separators_impl <- function(
graph
)
if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}
res
}
4 changes: 2 additions & 2 deletions R/aaa-structural.R
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ biconnected_components_impl <- function(
res$component_edges <- lapply(res$component_edges, unsafe_create_es, graph = graph, es = E(graph))
}
if (igraph_opt("return.vs.es")) {
res$components <- lapply(res$components, unsafe_create_vs, graph = graph, verts = V(graph))
res$components <- create_vs_list(graph, res$components)
}
if (igraph_opt("return.vs.es")) {
res$articulation_points <- create_vs(graph, res$articulation_points)
Expand Down Expand Up @@ -1290,7 +1290,7 @@ neighborhood_impl <- function(
mindist
)
if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}
res
}
Expand Down
4 changes: 2 additions & 2 deletions R/cliques.R
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ max_cliques <- function(
res <- lapply(res, function(x) x + 1)

if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}

res
Expand Down Expand Up @@ -749,7 +749,7 @@ ivs <- function(graph, min = NULL, max = NULL) {
res <- lapply(res, `+`, 1)

if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}

res
Expand Down
7 changes: 1 addition & 6 deletions R/cohesive.blocks.R
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,7 @@ cohesive_blocks <- function(
res$labels <- V(graph)$name
}
if (igraph_opt("return.vs.es")) {
res$blocks <- lapply(
res$blocks,
unsafe_create_vs,
graph = graph,
verts = V(graph)
)
res$blocks <- create_vs_list(graph, res$blocks)
}

res$vcount <- vcount(graph)
Expand Down
7 changes: 1 addition & 6 deletions R/components.R
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,7 @@ biconnected_components <- function(graph) {
res$component.edges <- res$component_edges
}
if (igraph_opt("return.vs.es")) {
res$components <- lapply(
res$components,
unsafe_create_vs,
graph = graph,
verts = V(graph)
)
res$components <- create_vs_list(graph, res$components)
}
if (igraph_opt("return.vs.es")) {
res$articulation_points <- create_vs(graph, res$articulation_points)
Expand Down
2 changes: 1 addition & 1 deletion R/conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ as_adj_list <- function(
res <- .Call(Rx_igraph_get_adjlist, graph, mode, loops, multiple)
res <- lapply(res, `+`, 1)
if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}
if (is_named(graph)) {
names(res) <- V(graph)$name
Expand Down
2 changes: 1 addition & 1 deletion R/interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ adjacent_vertices <- function(
res <- lapply(res, `+`, 1)

if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}

if (is_named(graph)) {
Expand Down
41 changes: 41 additions & 0 deletions R/iterators.R
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,47 @@ unsafe_create_vs <- function(graph, idx, verts = NULL) {
res
}

# Build a list of vertex sequences from a list of vertex-ID vectors.
#
# This is the batch form of `unsafe_create_vs()` and replaces the
# `lapply(idx_list, unsafe_create_vs, graph = graph, verts = V(graph))`
# pattern. All the per-graph work -- `V(graph)`, the shared weak reference,
# the graph id and the vertex-name source -- is hoisted out of the loop, so
# each sequence costs one `as.integer()`, one name subset and one
# `attributes<-` instead of a closure call that re-reads all of it.
#
# Having a single named entry point for "turn this list of ID vectors into a
# list of vertex sequences" also means the construction loop can be moved
# wholesale (e.g. into C) without touching any of the ~37 call sites.
create_vs_list <- function(graph, idx_list) {
verts <- V(graph)
vs_env <- attr(verts, "env")
vs_graph <- attr(verts, "graph")
vertex_names <- attr(verts, "names")
if (is.null(vertex_names)) {
lapply(idx_list, function(idx) {
res <- as.integer(idx)
attributes(res) <- list(
class = "igraph.vs",
env = vs_env,
graph = vs_graph
)
res
})
} else {
lapply(idx_list, function(idx) {
res <- as.integer(idx)
attributes(res) <- list(
names = vertex_names[res],
class = "igraph.vs",
env = vs_env,
graph = vs_graph
)
res
})
}
}

# Internal function to quickly convert integer vectors to igraph.es
# for use after C code, when NA and bounds checking is unnecessary
# Also allows us to construct V(graph) outside the function call in
Expand Down
2 changes: 1 addition & 1 deletion R/paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ all_simple_paths <- function(
res <- get.all.simple.paths.pp(res)

if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
res <- create_vs_list(graph, res)
}
res
}
Expand Down
Loading
Loading