Translated myintersect()
This commit is contained in:
parent
35bb795dbe
commit
e60e40b21c
1 changed files with 29 additions and 1 deletions
|
|
@ -1 +1,29 @@
|
||||||
myintersect <- function(A, B) {}
|
myintersect <- function(A, B) {
|
||||||
|
# MYINTERSECT Intersection of two sets of positive integers (much faster than built - in intersect)
|
||||||
|
# C <- myintersect(A, B)
|
||||||
|
|
||||||
|
A <- t(A)
|
||||||
|
B <- t(B)
|
||||||
|
|
||||||
|
if (is.null(A)) {
|
||||||
|
ma <- 0
|
||||||
|
} else {
|
||||||
|
ma <- max(A)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is.null(B)) {
|
||||||
|
mb <- 0
|
||||||
|
} else {
|
||||||
|
mb <- max(B)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ma == 0 | mb == 0) {
|
||||||
|
C <- vector()
|
||||||
|
} else {
|
||||||
|
# bits <- sparse(1, max(ma, mb))
|
||||||
|
bits <- zeros(1, max(ma, mb))
|
||||||
|
bits[A] <- 1
|
||||||
|
C <- B[as.logical(bits[B])]
|
||||||
|
}
|
||||||
|
return(C)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue