R Under development (unstable) (2023-04-23 r84305 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > library(rcdd) If you want correct answers, use rational arithmetic. See the Warnings sections in help pages for functions that do computational geometry. > > .Call(rcdd:::C_test_my_subset, integer(0), as.integer(1:3), as.integer(3)) [1] TRUE > > .Call(rcdd:::C_test_my_subset, as.integer(1:3), integer(0), as.integer(4)) [1] FALSE > > .Call(rcdd:::C_test_my_subset, as.integer(1:3), as.integer(1), as.integer(5)) [1] FALSE > > .Call(rcdd:::C_test_my_subset, as.integer(1:3), as.integer(1:3), as.integer(6)) [1] TRUE > > .Call(rcdd:::C_test_my_subset, as.integer(1:2), as.integer(1:3), as.integer(7)) [1] TRUE > > #### need to test for collisions > > pow2 <- 5 > hashsize <- 2^pow2 > > i <- seq(1:1000) > hashi <- (2654435761 * i) %% hashsize > hash1 <- i[hashi == hashi[1]] > > set2 <- hash1[1:10] > print(set2) [1] 1 33 65 97 129 161 193 225 257 289 > > set1 <- sample(set2, 4) > > .Call(rcdd:::C_test_my_subset, as.integer(set1), as.integer(set2), as.integer(pow2)) [1] TRUE > > set1 <- sample(set2, 4) > > .Call(rcdd:::C_test_my_subset, as.integer(set1), as.integer(set2), as.integer(pow2)) [1] TRUE > > set1 <- union(set1, 1001) > > .Call(rcdd:::C_test_my_subset, as.integer(set1), as.integer(set2), as.integer(pow2)) [1] FALSE > > options(error=dump.frames) > > .Call(rcdd:::C_test_my_subset, as.integer(set1), as.integer(hash1), as.integer(pow2)) Error: too many collisions in hash table, increase table size > > .Call(rcdd:::C_test_my_subset, as.integer(set1), as.integer(hash1), + as.integer(pow2 + 3)) [1] FALSE > > options(error=NULL) > > sets <- list(1, 2, c(1, 2), 3, 4, 5, c(4, 5), c(4, 5, 6), c(1, 3, 5)) > sets <- lapply(sets, as.integer) > > .Call(rcdd:::C_nonred, sets, as.integer(pow2)) [1] FALSE FALSE TRUE FALSE FALSE FALSE FALSE TRUE TRUE > > maximal(sets) [1] FALSE FALSE TRUE FALSE FALSE FALSE FALSE TRUE TRUE > > ##### intersections ##### > > .Call(rcdd:::C_all_intersect, sets, as.integer(pow2)) [[1]] integer(0) [[2]] [1] 1 [[3]] integer(0) [[4]] integer(0) [[5]] integer(0) [[6]] integer(0) [[7]] integer(0) [[8]] [1] 1 [[9]] [1] 2 [[10]] integer(0) [[11]] integer(0) [[12]] integer(0) [[13]] integer(0) [[14]] integer(0) [[15]] integer(0) [[16]] integer(0) [[17]] integer(0) [[18]] integer(0) [[19]] integer(0) [[20]] integer(0) [[21]] [1] 1 [[22]] integer(0) [[23]] integer(0) [[24]] integer(0) [[25]] integer(0) [[26]] [1] 3 [[27]] integer(0) [[28]] [1] 4 [[29]] [1] 4 [[30]] integer(0) [[31]] [1] 5 [[32]] [1] 5 [[33]] [1] 5 [[34]] [1] 4 5 [[35]] [1] 5 [[36]] [1] 5 > > sets <- list(c(1, 2, 3), c(2, 3, 4), c(3, 4, 5), c(4, 5, 1), c(5, 1, 2)) > sets <- lapply(sets, as.integer) > > .Call(rcdd:::C_all_intersect, sets, as.integer(pow2)) [[1]] [1] 2 3 [[2]] [1] 3 [[3]] [1] 1 [[4]] [1] 1 2 [[5]] [1] 3 4 [[6]] [1] 4 [[7]] [1] 2 [[8]] [1] 4 5 [[9]] [1] 5 [[10]] [1] 5 1 > > allIntersect(sets) [[1]] [1] 2 3 [[2]] [1] 3 [[3]] [1] 1 [[4]] [1] 1 2 [[5]] [1] 3 4 [[6]] [1] 4 [[7]] [1] 2 [[8]] [1] 4 5 [[9]] [1] 5 [[10]] [1] 5 1 > > ##### unions ##### > > .Call(rcdd:::C_all_union, sets, as.integer(pow2)) [[1]] [1] 1 2 3 4 [[2]] [1] 1 2 3 4 5 [[3]] [1] 1 2 3 4 5 [[4]] [1] 1 2 3 5 [[5]] [1] 2 3 4 5 [[6]] [1] 2 3 4 5 1 [[7]] [1] 2 3 4 5 1 [[8]] [1] 3 4 5 1 [[9]] [1] 3 4 5 1 2 [[10]] [1] 4 5 1 2 > > sets <- list(1, 2, c(3, 4), c(1, 3), 5) > sets <- lapply(sets, as.integer) > > .Call(rcdd:::C_all_union, sets, as.integer(pow2)) [[1]] [1] 1 2 [[2]] [1] 1 3 4 [[3]] [1] 1 3 [[4]] [1] 1 5 [[5]] [1] 2 3 4 [[6]] [1] 2 1 3 [[7]] [1] 2 5 [[8]] [1] 3 4 1 [[9]] [1] 3 4 5 [[10]] [1] 1 3 5 > > allUnion(sets) [[1]] [1] 1 2 [[2]] [1] 1 3 4 [[3]] [1] 1 3 [[4]] [1] 1 5 [[5]] [1] 2 3 4 [[6]] [1] 2 1 3 [[7]] [1] 2 5 [[8]] [1] 3 4 1 [[9]] [1] 3 4 5 [[10]] [1] 1 3 5 > > > proc.time() user system elapsed 0.23 0.09 0.28