From 66e2c75b16f4d7f1402581645b98ad1f9b0fcc38 Mon Sep 17 00:00:00 2001 From: Gabor Csardi Date: Fri, 26 Jun 2015 23:43:05 +0200 Subject: [PATCH] Speed up special cases in vertex set indexing --- R/iterators.R | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/R/iterators.R b/R/iterators.R index 223193a6e1..684b802d86 100644 --- a/R/iterators.R +++ b/R/iterators.R @@ -378,14 +378,31 @@ simple_vs_index <- function(x, i, na_ok = FALSE) { args <- lazy_dots(..., .follow_symbols = FALSE) ## If indexing has no argument at all, then we still get one, - ## but it is "empty", a name that is "" + ## but it is "empty", a name that is "" + ## Special case, no argument (but we might get an artificial + ## empty one if (length(args) < 1 || (length(args) == 1 && class(args[[1]]$expr) == "name" && as.character(args[[1]]$expr) == "")) { return(x) } + ## Special case: single numeric argument + if (length(args) == 1 && class(args[[1]]$expr) == "numeric") { + res <- simple_vs_index(x, args[[1]]$expr) + return (add_vses_graph_ref(res, get_vs_graph(x))) + } + + ## Special case: single symbol argument, no such attribute + if (length(args) == 1 && class(args[[1]]$expr) == "name") { + graph <- get_vs_graph(x) + if (! (as.character(args[[1]]$expr) %in% vertex_attr_names(graph))) { + res <- simple_vs_index(x, lazy_eval(args[[1]])) + return (add_vses_graph_ref(res, graph)) + } + } + nei <- function(v, mode=c("all", "in", "out", "total")) { ## TRUE iff the vertex is a neighbor (any type) ## of at least one vertex in v