├── .Rbuildignore ├── .devcontainer ├── devcontainer.json ├── r-340 │ ├── .Rprofile │ ├── Dockerfile │ └── devcontainer.json ├── r-420 │ ├── Dockerfile │ └── devcontainer.json └── r-devel │ ├── Dockerfile │ └── setup_for_full_check.sh ├── .github ├── .gitignore └── workflows │ ├── R-CMD-check.yaml │ ├── lint.yaml │ ├── rhub.yaml │ └── test-coverage.yaml ├── .gitignore ├── .lintr.R ├── DESCRIPTION ├── NAMESPACE ├── NEWS.0 ├── NEWS.md ├── R ├── attrutil.R ├── bit-package.R ├── bit.R ├── bitsort.R ├── chunkutil.R ├── clone.R ├── generics.R ├── integerutil.R ├── merge.R ├── rle.R ├── timeutil.R └── zzz.R ├── README.md ├── bit.Rproj ├── codecov.yml ├── man ├── CoercionToStandard.Rd ├── Extract.Rd ├── Metadata.Rd ├── PhysVirt.Rd ├── Sorting.Rd ├── Summaries.Rd ├── as.bit.Rd ├── as.bitwhich.Rd ├── as.booltype.Rd ├── as.character.bit.Rd ├── as.character.bitwhich.Rd ├── as.ri.Rd ├── as.which.Rd ├── bbatch.Rd ├── bit-package.Rd ├── bit.Rd ├── bit_in.Rd ├── bit_init.Rd ├── bit_rangediff.Rd ├── bit_setops.Rd ├── bit_sort.Rd ├── bit_sort_unique.Rd ├── bit_unidup.Rd ├── bitsort.Rd ├── bitwhich.Rd ├── bitwhich_representation.Rd ├── booltype.Rd ├── booltypes.Rd ├── c.booltype.Rd ├── chunk.Rd ├── chunks.Rd ├── clone.Rd ├── copy_vector.Rd ├── countsort.Rd ├── firstNA.Rd ├── get_length.Rd ├── getsetattr.Rd ├── in.bitwhich.Rd ├── intrle.Rd ├── is.booltype.Rd ├── is.na.bit.Rd ├── length.bit.Rd ├── maxindex.Rd ├── merge_rev.Rd ├── print.bit.Rd ├── print.bitwhich.Rd ├── quicksort2.Rd ├── quicksort3.Rd ├── range_na.Rd ├── range_nanozero.Rd ├── range_sortna.Rd ├── rep.booltype.Rd ├── repeat.time.Rd ├── repfromto.Rd ├── rev.booltype.Rd ├── reverse_vector.Rd ├── ri.Rd ├── rlepack.Rd ├── still.identical.Rd ├── str.bit.Rd ├── str.bitwhich.Rd ├── symdiff.Rd ├── unattr.Rd ├── vecseq.Rd └── xor.Rd ├── src ├── Makevars ├── attrutil.c ├── bit.c ├── bit.dll ├── chunkutil.c ├── clone.c ├── init.c ├── integerutil.c ├── merge.c ├── merge.c.h ├── merge.h ├── range.c.h ├── rle.c ├── sort.c └── sort.h ├── tests ├── ff_tests.R ├── testthat.R └── testthat │ ├── test-bit.R │ ├── test-bitsort.R │ ├── test-merge.R │ ├── test-old-regtest.R │ └── test-rle.R └── vignettes ├── bit-demo.Rmd ├── bit-performance.Rmd └── bit-usage.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.github$ 2 | ^.gitignore$ 3 | \.Rproj$ 4 | ^\.Rproj\.user$ 5 | ^doc$ 6 | ^Meta$ 7 | ^NEWS\.0$ 8 | README.md 9 | ^codecov\.yml$ 10 | ^\.devcontainer$ 11 | ^\.lintr 12 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "build": { "dockerfile": "r-devel/Dockerfile", "context": ".."} 3 | } 4 | -------------------------------------------------------------------------------- /.devcontainer/r-340/.Rprofile: -------------------------------------------------------------------------------- 1 | # Minimal testthat masks for R before testthat support so that source(test_script) works 2 | 3 | test_that = function(desc, expr) tryCatch(expr, skip_error = identity) 4 | 5 | skip_if = function(cond, info) { 6 | if (!cond) return(invisible()) 7 | e = simpleError(paste("Skipping:", info)) 8 | class(e) = c("skip_error", class(e)) 9 | stop(e) 10 | } 11 | 12 | skip_if_not_installed = function(pkg) { 13 | skip_if(!requireNamespace(pkg), paste(pkg, "is not installed")) 14 | } 15 | 16 | expect_identical = function(x, y, tolerance = NULL, ignore_attr = NULL) { 17 | if (!is.null(ignore_attr)) { 18 | attributes(x) = attributes(x)[!names(attributes(x)) %in% ignore_attr] 19 | attributes(y) = attributes(y)[!names(attributes(y)) %in% ignore_attr] 20 | } 21 | if (is.null(tolerance)) { 22 | stopifnot(identical(x, y)) 23 | } else { 24 | stopifnot(isTRUE(all.equal(x, y, tolerance=tolerance))) 25 | } 26 | invisible(x) 27 | } 28 | 29 | expect_true = function(x) expect_identical(x, TRUE) 30 | expect_false = function(x) expect_identical(x, FALSE) 31 | 32 | # NB: this doesn't really work like expect_warning does, to be revisited... 33 | expect_warning = function(expr, msg, ...) { 34 | e = new.env() 35 | withCallingHandlers( 36 | warning = function(w) { e$msg = conditionMessage(w); invokeRestart("muffleWarning") }, 37 | expr 38 | ) 39 | stopifnot(grepl(msg, e$msg, ...)) 40 | invisible(x) 41 | } 42 | # overwrite by automatically passing these tests for now 43 | expect_warning = function(...) invisible() 44 | 45 | expect_error = function(expr, msg, ...) { 46 | val = tryCatch(expr, error = identity) 47 | stopifnot(inherits(val, "error") && grepl(msg, conditionMessage(val), ...)) 48 | } 49 | 50 | expect_s3_class = function(x, kls) stopifnot(inherits(x, kls)) 51 | expect_length = function(x, l) expect_identical(length(x), l) 52 | 53 | expect_output = function(expr, str, ...) { 54 | act = paste(capture.output(val <- expr), collapse="\n") 55 | stopifnot(grepl(str, act, ...)) 56 | invisible(val) 57 | } 58 | 59 | expect_match = function(x, pattern, ..., all=TRUE) { 60 | agg = if (all) base::all else any 61 | stopifnot(agg(grepl(pattern, x, ...))) 62 | invisible(x) 63 | } 64 | 65 | expect_no_match = function(x, pattern, ...) { 66 | stopifnot(!any(grepl(pattern, x, ...))) 67 | invisible(x) 68 | } 69 | -------------------------------------------------------------------------------- /.devcontainer/r-340/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ghcr.io/r-hub/evercran/3.4.0 2 | 3 | RUN apt-get -qq update && \ 4 | apt-get install -y --no-install-recommends git 5 | 6 | COPY DESCRIPTION . 7 | 8 | RUN Rscript -e ' \ 9 | options(repos = "https://cloud.r-project.org"); \ 10 | dcf = read.dcf("DESCRIPTION", c("Depends", "Imports", "Suggests")); \ 11 | deps = names(tools:::.split_dependencies(dcf)); \ 12 | default_pkgs = tools:::.get_standard_package_names()$base; \ 13 | installable = setdiff(rownames(available.packages()), default_pkgs); \ 14 | message("All deps: ", toString(deps)); \ 15 | deps = intersect(deps, installable); \ 16 | message("Installing: ", toString(deps)); \ 17 | install.packages(deps); \ 18 | ' 19 | 20 | # Needed for testthat equivalency on pre-testthat R 21 | WORKDIR /root 22 | COPY .devcontainer/r-340/.Rprofile . 23 | -------------------------------------------------------------------------------- /.devcontainer/r-340/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "build": { "dockerfile": "Dockerfile", "context": "../.." } 3 | } 4 | -------------------------------------------------------------------------------- /.devcontainer/r-420/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ghcr.io/r-hub/evercran/4.2.0 2 | 3 | RUN apt-get -qq update && \ 4 | apt-get install -y --no-install-recommends git 5 | 6 | COPY DESCRIPTION . 7 | 8 | RUN Rscript -e ' \ 9 | install.packages("remotes"); \ 10 | remotes::install_deps(dependencies = c( \ 11 | "Depends", \ 12 | "Imports", \ 13 | "Config/needs/development" \ 14 | )) \ 15 | ' 16 | -------------------------------------------------------------------------------- /.devcontainer/r-420/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "build": { "dockerfile": "Dockerfile", "context": "../.." } 3 | } 4 | -------------------------------------------------------------------------------- /.devcontainer/r-devel/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rocker/r-base 2 | 3 | RUN apt-get -qq update && \ 4 | apt-get install -y --no-install-recommends git 5 | 6 | COPY DESCRIPTION . 7 | 8 | RUN Rscript -e ' \ 9 | install.packages("remotes"); \ 10 | remotes::install_deps(dependencies = c( \ 11 | "Depends", \ 12 | "Imports", \ 13 | "Config/needs/development" \ 14 | )) \ 15 | ' 16 | -------------------------------------------------------------------------------- /.devcontainer/r-devel/setup_for_full_check.sh: -------------------------------------------------------------------------------- 1 | # These commands extend the base image so that devtools::check(remote = TRUE, manual = TRUE) works 2 | apt-get install libxml2-dev libfontconfig1-dev libssl-dev libcurl4-openssl-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev tidy 3 | apt install texlive-latex-base texlive-fonts-recommended texlive-fonts-extra 4 | # mktexlsr (maybe?) 5 | tlmgr init-usertree 6 | tlmgr install xkeyval etoolbox 7 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | 9 | name: R-CMD-check.yaml 10 | 11 | permissions: read-all 12 | 13 | jobs: 14 | R-CMD-check: 15 | runs-on: ${{ matrix.config.os }} 16 | 17 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 18 | 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | config: 23 | - {os: macos-latest, r: 'release'} 24 | - {os: windows-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 26 | - {os: ubuntu-latest, r: 'release'} 27 | - {os: ubuntu-latest, r: 'oldrel-1'} 28 | - {os: ubuntu-latest, r: '3.6'} 29 | 30 | env: 31 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 32 | R_KEEP_PKG_SOURCE: yes 33 | 34 | steps: 35 | - uses: actions/checkout@v4 36 | 37 | - uses: r-lib/actions/setup-pandoc@v2 38 | 39 | - uses: r-lib/actions/setup-r@v2 40 | with: 41 | r-version: ${{ matrix.config.r }} 42 | http-user-agent: ${{ matrix.config.http-user-agent }} 43 | use-public-rspm: true 44 | 45 | - uses: r-lib/actions/setup-r-dependencies@v2 46 | with: 47 | extra-packages: any::rcmdcheck 48 | needs: check 49 | 50 | - uses: r-lib/actions/check-r-package@v2 51 | with: 52 | upload-snapshots: true 53 | -------------------------------------------------------------------------------- /.github/workflows/lint.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: [main] 4 | pull_request: 5 | branches: [main] 6 | 7 | name: lint 8 | 9 | jobs: 10 | lint: 11 | runs-on: ubuntu-latest 12 | env: 13 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 14 | steps: 15 | - uses: actions/checkout@v4 16 | 17 | - uses: r-lib/actions/setup-r@v2 18 | with: 19 | use-public-rspm: true 20 | 21 | - uses: r-lib/actions/setup-r-dependencies@v2 22 | with: 23 | extra-packages: | 24 | r-lib/lintr 25 | local::. 26 | needs: lint 27 | 28 | - name: Lint 29 | run: lintr::lint_package() 30 | shell: Rscript {0} 31 | env: 32 | LINTR_ERROR_ON_LINT: true 33 | -------------------------------------------------------------------------------- /.github/workflows/rhub.yaml: -------------------------------------------------------------------------------- 1 | # R-hub's generic GitHub Actions workflow file. It's canonical location is at 2 | # https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml 3 | # You can update this file to a newer version using the rhub2 package: 4 | # 5 | # rhub::rhub_setup() 6 | # 7 | # It is unlikely that you need to modify this file manually. 8 | 9 | name: R-hub 10 | run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}" 11 | 12 | on: 13 | workflow_dispatch: 14 | inputs: 15 | config: 16 | description: 'A comma separated list of R-hub platforms to use.' 17 | type: string 18 | default: 'linux,windows,macos' 19 | name: 20 | description: 'Run name. You can leave this empty now.' 21 | type: string 22 | id: 23 | description: 'Unique ID. You can leave this empty now.' 24 | type: string 25 | 26 | jobs: 27 | 28 | setup: 29 | runs-on: ubuntu-latest 30 | outputs: 31 | containers: ${{ steps.rhub-setup.outputs.containers }} 32 | platforms: ${{ steps.rhub-setup.outputs.platforms }} 33 | 34 | steps: 35 | # NO NEED TO CHECKOUT HERE 36 | - uses: r-hub/actions/setup@v1 37 | with: 38 | config: ${{ github.event.inputs.config }} 39 | id: rhub-setup 40 | 41 | linux-containers: 42 | needs: setup 43 | if: ${{ needs.setup.outputs.containers != '[]' }} 44 | runs-on: ubuntu-latest 45 | name: ${{ matrix.config.label }} 46 | strategy: 47 | fail-fast: false 48 | matrix: 49 | config: ${{ fromJson(needs.setup.outputs.containers) }} 50 | container: 51 | image: ${{ matrix.config.container }} 52 | 53 | steps: 54 | - uses: r-hub/actions/checkout@v1 55 | - uses: r-hub/actions/platform-info@v1 56 | with: 57 | token: ${{ secrets.RHUB_TOKEN }} 58 | job-config: ${{ matrix.config.job-config }} 59 | - uses: r-hub/actions/setup-deps@v1 60 | with: 61 | token: ${{ secrets.RHUB_TOKEN }} 62 | job-config: ${{ matrix.config.job-config }} 63 | - uses: r-hub/actions/run-check@v1 64 | with: 65 | token: ${{ secrets.RHUB_TOKEN }} 66 | job-config: ${{ matrix.config.job-config }} 67 | 68 | other-platforms: 69 | needs: setup 70 | if: ${{ needs.setup.outputs.platforms != '[]' }} 71 | runs-on: ${{ matrix.config.os }} 72 | name: ${{ matrix.config.label }} 73 | strategy: 74 | fail-fast: false 75 | matrix: 76 | config: ${{ fromJson(needs.setup.outputs.platforms) }} 77 | 78 | steps: 79 | - uses: r-hub/actions/checkout@v1 80 | - uses: r-hub/actions/setup-r@v1 81 | with: 82 | job-config: ${{ matrix.config.job-config }} 83 | token: ${{ secrets.RHUB_TOKEN }} 84 | - uses: r-hub/actions/platform-info@v1 85 | with: 86 | token: ${{ secrets.RHUB_TOKEN }} 87 | job-config: ${{ matrix.config.job-config }} 88 | - uses: r-hub/actions/setup-deps@v1 89 | with: 90 | job-config: ${{ matrix.config.job-config }} 91 | token: ${{ secrets.RHUB_TOKEN }} 92 | - uses: r-hub/actions/run-check@v1 93 | with: 94 | job-config: ${{ matrix.config.job-config }} 95 | token: ${{ secrets.RHUB_TOKEN }} 96 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: test-coverage.yaml 10 | 11 | permissions: read-all 12 | 13 | jobs: 14 | test-coverage: 15 | runs-on: ubuntu-latest 16 | env: 17 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 18 | 19 | steps: 20 | - uses: actions/checkout@v4 21 | 22 | - uses: r-lib/actions/setup-r@v2 23 | with: 24 | use-public-rspm: true 25 | 26 | - uses: r-lib/actions/setup-r-dependencies@v2 27 | with: 28 | extra-packages: any::covr, any::xml2 29 | needs: coverage 30 | 31 | - name: Test coverage 32 | run: | 33 | cov <- covr::package_coverage( 34 | quiet = FALSE, 35 | clean = FALSE, 36 | install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") 37 | ) 38 | covr::to_cobertura(cov) 39 | shell: Rscript {0} 40 | 41 | - uses: codecov/codecov-action@v4 42 | with: 43 | fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }} 44 | file: ./cobertura.xml 45 | plugin: noop 46 | disable_search: true 47 | token: ${{ secrets.CODECOV_TOKEN }} 48 | 49 | - name: Show testthat output 50 | if: always() 51 | run: | 52 | ## -------------------------------------------------------------------- 53 | find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true 54 | shell: bash 55 | 56 | - name: Upload test results 57 | if: failure() 58 | uses: actions/upload-artifact@v4 59 | with: 60 | name: coverage-test-failures 61 | path: ${{ runner.temp }}/package 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | .Rhistory 3 | .Rapp.history 4 | 5 | # Session Data files 6 | .RData 7 | 8 | # User-specific files 9 | .Ruserdata 10 | 11 | # Example code in package build process 12 | *-Ex.R 13 | 14 | # Output files from R CMD build 15 | /*.tar.gz 16 | 17 | # Output files from R CMD check 18 | /*.Rcheck/ 19 | 20 | # RStudio files 21 | .Rproj.user/ 22 | 23 | # produced vignettes 24 | vignettes/*.html 25 | vignettes/*.pdf 26 | 27 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 28 | .httr-oauth 29 | 30 | # knitr and R markdown default cache directories 31 | *_cache/ 32 | /cache/ 33 | 34 | # Temporary files created by R markdown 35 | *.utf8.md 36 | *.knit.md 37 | 38 | # R Environment Variables 39 | .Renviron 40 | 41 | # Object-files 42 | src/*.o 43 | src/*.so 44 | src/*.dll 45 | doc 46 | Meta 47 | -------------------------------------------------------------------------------- /.lintr.R: -------------------------------------------------------------------------------- 1 | linters = all_linters( 2 | packages = "lintr", 3 | infix_spaces_linter(exclude_operators=c('EQ_SUB', 'EQ_FORMALS')), 4 | line_length_linter(100L), 5 | # TODO(org/repo#000) or TODO(#000) allowed as canonical TODO comments. 6 | todo_comment_linter(except_regex = "TODO\\((?:[a-zA-Z0-9-]+/[a-zA-Z0-9._-]+)?#[0-9]+\\)"), 7 | commented_code_linter = NULL, 8 | condition_call_linter = NULL, 9 | # TODO(#34): Activate with limit of 25. 10 | cyclocomp_linter = NULL, 11 | function_argument_linter = NULL, 12 | nonportable_path_linter = NULL, 13 | object_name_linter = NULL, 14 | quotes_linter = NULL, 15 | # TODO(#19): Activate this; it's not trivial to replace on some old R versions. 16 | rep_len_linter = NULL, 17 | unreachable_code_linter = NULL, 18 | # TODO(#2441): Activate this when it supports = for assignments 19 | assignment_linter = NULL, 20 | # TODO(r-lib/lintr#2172): Exclude the below from vignettes/, enforce elsewhere 21 | # Finer-tuned handling for some of these. 22 | undesirable_function_linter(modify_defaults( 23 | defaults = default_undesirable_functions, 24 | library = NULL, 25 | options = NULL, 26 | par = NULL, 27 | sapply = NULL 28 | )), 29 | # Will be allow_scoped=TRUE 30 | implicit_assignment_linter = NULL, 31 | implicit_integer_linter = NULL, 32 | library_call_linter = NULL, 33 | sample_int_linter = NULL 34 | ) 35 | 36 | exclusions = list("tests/testthat.R") 37 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: bit 2 | Title: Classes and Methods for Fast Memory-Efficient Boolean Selections 3 | Version: 4.6.99 4 | Authors@R: c( 5 | person("Michael", "Chirico", email = "MichaelChirico4@gmail.com", role = c("aut", "cre")), 6 | person("Jens", "Oehlschlägel", role = "aut"), 7 | person("Brian", "Ripley", role = "ctb") 8 | ) 9 | Depends: 10 | R (>= 3.4.0) 11 | Suggests: 12 | testthat (>= 3.0.0), 13 | knitr, 14 | markdown, 15 | rmarkdown, 16 | microbenchmark, 17 | bit64 (>= 4.0.0), 18 | ff (>= 4.0.0) 19 | Description: Provided are classes for boolean and skewed boolean vectors, 20 | fast boolean methods, fast unique and non-unique integer sorting, 21 | fast set operations on sorted and unsorted sets of integers, and 22 | foundations for ff (range index, compression, chunked processing). 23 | License: GPL-2 | GPL-3 24 | LazyLoad: yes 25 | ByteCompile: yes 26 | Encoding: UTF-8 27 | URL: https://github.com/r-lib/bit 28 | VignetteBuilder: knitr, 29 | rmarkdown 30 | RoxygenNote: 7.3.2 31 | Roxygen: list(markdown = TRUE) 32 | Config/wants/development: roxygen2 33 | Config/testthat/edition: 3 34 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method("!",bit) 4 | S3method("!",bitwhich) 5 | S3method("!=",bit) 6 | S3method("!=",bitwhich) 7 | S3method("!=",booltype) 8 | S3method("&",bit) 9 | S3method("&",bitwhich) 10 | S3method("&",booltype) 11 | S3method("==",bit) 12 | S3method("==",bitwhich) 13 | S3method("==",booltype) 14 | S3method("[",bit) 15 | S3method("[",bitwhich) 16 | S3method("[<-",bit) 17 | S3method("[<-",bitwhich) 18 | S3method("[[",bit) 19 | S3method("[[",bitwhich) 20 | S3method("[[<-",bit) 21 | S3method("[[<-",bitwhich) 22 | S3method("length<-",bit) 23 | S3method("length<-",bitwhich) 24 | S3method("physical<-",default) 25 | S3method("virtual<-",default) 26 | S3method("|",bit) 27 | S3method("|",bitwhich) 28 | S3method("|",booltype) 29 | S3method(all,bit) 30 | S3method(all,bitwhich) 31 | S3method(all,booltype) 32 | S3method(all,ri) 33 | S3method(all,which) 34 | S3method(any,bit) 35 | S3method(any,bitwhich) 36 | S3method(any,booltype) 37 | S3method(any,ri) 38 | S3method(any,which) 39 | S3method(anyDuplicated,rlepack) 40 | S3method(anyNA,bit) 41 | S3method(anyNA,bitwhich) 42 | S3method(anyNA,booltype) 43 | S3method(anyNA,ri) 44 | S3method(anyNA,which) 45 | S3method(as.bit,"NULL") 46 | S3method(as.bit,bit) 47 | S3method(as.bit,bitwhich) 48 | S3method(as.bit,double) 49 | S3method(as.bit,integer) 50 | S3method(as.bit,logical) 51 | S3method(as.bit,ri) 52 | S3method(as.bit,which) 53 | S3method(as.bitwhich,"NULL") 54 | S3method(as.bitwhich,bit) 55 | S3method(as.bitwhich,bitwhich) 56 | S3method(as.bitwhich,double) 57 | S3method(as.bitwhich,integer) 58 | S3method(as.bitwhich,logical) 59 | S3method(as.bitwhich,ri) 60 | S3method(as.bitwhich,which) 61 | S3method(as.booltype,default) 62 | S3method(as.character,bit) 63 | S3method(as.character,bitwhich) 64 | S3method(as.double,bit) 65 | S3method(as.double,bitwhich) 66 | S3method(as.double,ri) 67 | S3method(as.integer,bit) 68 | S3method(as.integer,bitwhich) 69 | S3method(as.integer,ri) 70 | S3method(as.logical,bit) 71 | S3method(as.logical,bitwhich) 72 | S3method(as.logical,ri) 73 | S3method(as.logical,which) 74 | S3method(as.ri,default) 75 | S3method(as.ri,ri) 76 | S3method(as.which,"NULL") 77 | S3method(as.which,bit) 78 | S3method(as.which,bitwhich) 79 | S3method(as.which,integer) 80 | S3method(as.which,logical) 81 | S3method(as.which,numeric) 82 | S3method(as.which,ri) 83 | S3method(as.which,which) 84 | S3method(c,bit) 85 | S3method(c,bitwhich) 86 | S3method(c,booltype) 87 | S3method(chunk,default) 88 | S3method(clone,default) 89 | S3method(is.na,bitwhich) 90 | S3method(length,bit) 91 | S3method(length,bitwhich) 92 | S3method(length,ri) 93 | S3method(max,bit) 94 | S3method(max,bitwhich) 95 | S3method(max,booltype) 96 | S3method(max,ri) 97 | S3method(max,which) 98 | S3method(maxindex,bit) 99 | S3method(maxindex,bitwhich) 100 | S3method(maxindex,default) 101 | S3method(maxindex,logical) 102 | S3method(maxindex,ri) 103 | S3method(maxindex,which) 104 | S3method(min,bit) 105 | S3method(min,bitwhich) 106 | S3method(min,booltype) 107 | S3method(min,ri) 108 | S3method(min,which) 109 | S3method(physical,default) 110 | S3method(poslength,bit) 111 | S3method(poslength,bitwhich) 112 | S3method(poslength,default) 113 | S3method(poslength,logical) 114 | S3method(poslength,ri) 115 | S3method(poslength,which) 116 | S3method(print,bit) 117 | S3method(print,bitwhich) 118 | S3method(print,physical) 119 | S3method(print,ri) 120 | S3method(print,virtual) 121 | S3method(range,bit) 122 | S3method(range,bitwhich) 123 | S3method(range,booltype) 124 | S3method(range,ri) 125 | S3method(range,which) 126 | S3method(rep,bit) 127 | S3method(rep,bitwhich) 128 | S3method(rev,bit) 129 | S3method(rev,bitwhich) 130 | S3method(rev,rlepack) 131 | S3method(rlepack,integer) 132 | S3method(rleunpack,rlepack) 133 | S3method(str,bit) 134 | S3method(str,bitwhich) 135 | S3method(sum,bit) 136 | S3method(sum,bitwhich) 137 | S3method(sum,booltype) 138 | S3method(sum,ri) 139 | S3method(sum,which) 140 | S3method(summary,bit) 141 | S3method(summary,bitwhich) 142 | S3method(summary,booltype) 143 | S3method(summary,ri) 144 | S3method(summary,which) 145 | S3method(unique,rlepack) 146 | S3method(virtual,default) 147 | S3method(xor,bit) 148 | S3method(xor,bitwhich) 149 | S3method(xor,booltype) 150 | S3method(xor,default) 151 | S3method(xor,logical) 152 | export("!=.booltype") 153 | export("&.booltype") 154 | export("==.booltype") 155 | export("is.sorted<-") 156 | export("na.count<-") 157 | export("nties<-") 158 | export("nunique<-") 159 | export("physical<-") 160 | export("repfromto<-") 161 | export("virtual<-") 162 | export("|.booltype") 163 | export(.BITS) 164 | export(all.booltype) 165 | export(any.booltype) 166 | export(anyNA.booltype) 167 | export(as.bit) 168 | export(as.bitwhich) 169 | export(as.booltype) 170 | export(as.ri) 171 | export(as.which) 172 | export(bbatch) 173 | export(bit) 174 | export(bit_anyDuplicated) 175 | export(bit_done) 176 | export(bit_duplicated) 177 | export(bit_in) 178 | export(bit_init) 179 | export(bit_intersect) 180 | export(bit_rangediff) 181 | export(bit_setdiff) 182 | export(bit_setequal) 183 | export(bit_sort) 184 | export(bit_sort_unique) 185 | export(bit_sumDuplicated) 186 | export(bit_symdiff) 187 | export(bit_union) 188 | export(bit_unique) 189 | export(bitsort) 190 | export(bitwhich) 191 | export(bitwhich_representation) 192 | export(booltype) 193 | export(booltypes) 194 | export(c.booltype) 195 | export(chunk) 196 | export(chunks) 197 | export(clone) 198 | export(copy_vector) 199 | export(countsort) 200 | export(firstNA) 201 | export(get_length) 202 | export(getsetattr) 203 | export(in.bitwhich) 204 | export(intisasc) 205 | export(intisdesc) 206 | export(intrle) 207 | export(is.bit) 208 | export(is.bitwhich) 209 | export(is.booltype) 210 | export(is.hi) 211 | export(is.ri) 212 | export(is.sorted) 213 | export(is.which) 214 | export(keyorder) 215 | export(keysort) 216 | export(keysortorder) 217 | export(max.booltype) 218 | export(maxindex) 219 | export(merge_anyDuplicated) 220 | export(merge_duplicated) 221 | export(merge_first) 222 | export(merge_firstin) 223 | export(merge_firstnotin) 224 | export(merge_in) 225 | export(merge_intersect) 226 | export(merge_last) 227 | export(merge_lastin) 228 | export(merge_lastnotin) 229 | export(merge_match) 230 | export(merge_notin) 231 | export(merge_rangediff) 232 | export(merge_rangein) 233 | export(merge_rangenotin) 234 | export(merge_rangesect) 235 | export(merge_rev) 236 | export(merge_setdiff) 237 | export(merge_setequal) 238 | export(merge_sumDuplicated) 239 | export(merge_symdiff) 240 | export(merge_union) 241 | export(merge_unique) 242 | export(mergeorder) 243 | export(mergesort) 244 | export(mergesortorder) 245 | export(min.booltype) 246 | export(na.count) 247 | export(nties) 248 | export(nunique) 249 | export(nvalid) 250 | export(physical) 251 | export(poslength) 252 | export(quickorder) 253 | export(quicksort) 254 | export(quicksort2) 255 | export(quicksort3) 256 | export(quicksortorder) 257 | export(radixorder) 258 | export(radixsort) 259 | export(radixsortorder) 260 | export(ramorder) 261 | export(ramsort) 262 | export(ramsortorder) 263 | export(range.booltype) 264 | export(range_na) 265 | export(range_nanozero) 266 | export(range_sortna) 267 | export(repeat.time) 268 | export(repfromto) 269 | export(reverse_vector) 270 | export(ri) 271 | export(rlepack) 272 | export(rleunpack) 273 | export(setattr) 274 | export(setattributes) 275 | export(shellorder) 276 | export(shellsort) 277 | export(shellsortorder) 278 | export(still.identical) 279 | export(sum.booltype) 280 | export(summary.booltype) 281 | export(symdiff) 282 | export(unattr) 283 | export(vecseq) 284 | export(virtual) 285 | export(xor) 286 | export(xor.booltype) 287 | importFrom(utils,packageDescription) 288 | importFrom(utils,strOptions) 289 | useDynLib(bit, .registration = TRUE, .fixes = "C_") 290 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # bit 4.6.99 (in development) 2 | 3 | ## BUG FIXES 4 | 5 | 1. Avoid some 0-length accesses in coercions to/from bit, #44. 6 | 7 | # bit 4.6.0 8 | 9 | ## BUG FIXES 10 | 11 | 1. Corrected the function prototype for a C function, #36. Thanks @aitap for investigating and suggesting a fix. 12 | 13 | 1. `chunk()` works if {ff} is loaded but not attached, #3. Thanks @dschlaep for the report. 14 | 15 | ## NOTES 16 | 17 | 1. After creating, developing, and maintaining {bit} for about 16 years, Jens Oehlschlägel has decided to step down as maintainer of the package. As with {bit64}, Michael Chirico will take over in this duty. Thank you Jens for creating such a wonderful & important part of the R ecosystem! 18 | 19 | I don't have any major plans for new features, and mostly hope to keep the package running and up to date. Contributors most welcome! I am also trying to freshen up the code base to make contribution easier. 20 | 21 | # bit 4.5.0.1 22 | 23 | Patch change to fix r-devel failures, thank you Prof. Brian Ripley for the fix 24 | 25 | # bit NEWS for versions 1.1.0 through 4.5.0 are now in [NEWS.0](https://github.com/r-lib/bit/blob/master/NEWS.0) 26 | -------------------------------------------------------------------------------- /R/attrutil.R: -------------------------------------------------------------------------------- 1 | # attribute utilities for ff and bit 2 | # (c) 2010 Jens Oehlschlägel 3 | # Licence: GPL2 4 | # Provided 'as is', use at your own risk 5 | # Created: 2007-08-24 6 | # Last changed: 2007-10-25 7 | 8 | # WARNING: these functions are called for the side-effect of changing their arguments 9 | # this can save RAM and avoid unnecessary copying 10 | # but it can easily have unexpected effects 11 | # Only use them if you know what you do - and even then think twice 12 | 13 | #' Attribute setting by reference 14 | #' 15 | #' Function `setattr` sets a singe attribute and function 16 | #' `setattributes` sets a list of attributes. 17 | #' 18 | #' The attributes of 'x' are changed in place without copying x. function 19 | #' `setattributes` does only change the named attributes, it does not 20 | #' delete the non-names attributes like [attributes()] does. 21 | #' 22 | #' @param x an R object 23 | #' @param which name of the attribute 24 | #' @param value value of the attribute, use NULL to remove this attribute 25 | #' @param attributes a named list of attribute values 26 | #' @return invisible(), we do not return the changed object to remind you of 27 | #' the fact that this function is called for its side-effect of changing its 28 | #' input object. 29 | #' @author Jens Oehlschlägel 30 | #' @seealso [attr()] [unattr()] 31 | #' @references Writing R extensions -- System and foreign language interfaces 32 | #' -- Handling R objects in C -- Attributes (Version 2.11.1 (2010-06-03 ) R 33 | #' Development) 34 | #' @keywords attributes 35 | #' @examples 36 | #' 37 | #' x <- as.single(runif(10)) 38 | #' attr(x, "Csingle") 39 | #' 40 | #' f <- function(x) attr(x, "Csingle") <- NULL 41 | #' g <- function(x) setattr(x, "Csingle", NULL) 42 | #' 43 | #' f(x) 44 | #' x 45 | #' g(x) 46 | #' x 47 | #' 48 | #' \dontrun{ 49 | #' 50 | #' # restart R 51 | #' library(bit) 52 | #' 53 | #' mysingle <- function(length = 0) { 54 | #' ret <- double(length) 55 | #' setattr(ret, "Csingle", TRUE) 56 | #' ret 57 | #' } 58 | #' 59 | #' # show that mysinge gives exactly the same result as single 60 | #' identical(single(10), mysingle(10)) 61 | #' 62 | #' # look at the speedup and memory-savings of mysingle compared to single 63 | #' system.time(mysingle(1e7)) 64 | #' memory.size(max=TRUE) 65 | #' system.time(single(1e7)) 66 | #' memory.size(max=TRUE) 67 | #' 68 | #' # look at the memory limits 69 | #' # on my win32 machine the first line fails 70 | #' # because of not enough RAM, the second works 71 | #' x <- single(1e8) 72 | #' x <- mysingle(1e8) 73 | #' 74 | #' # .g. performance with factors 75 | #' x <- rep(factor(letters), length.out=1e7) 76 | #' x[1:10] 77 | #' # look how fast one can do this 78 | #' system.time(setattr(x, "levels", rev(letters))) 79 | #' x[1:10] 80 | #' # look at the performance loss in time caused by the non-needed copying 81 | #' system.time(levels(x) <- letters) 82 | #' x[1:10] 83 | #' 84 | #' 85 | #' # restart R 86 | #' library(bit) 87 | #' 88 | #' simplefactor <- function(n) { 89 | #' factor(rep(1:2, length.out=n)) 90 | #' } 91 | #' 92 | #' mysimplefactor <- function(n) { 93 | #' ret <- rep(1:2, length.out=n) 94 | #' setattr(ret, "levels", as.character(1:2)) 95 | #' setattr(ret, "class", "factor") 96 | #' ret 97 | #' } 98 | #' 99 | #' identical(simplefactor(10), mysimplefactor(10)) 100 | #' 101 | #' system.time(x <- mysimplefactor(1e7)) 102 | #' memory.size(max=TRUE) 103 | #' system.time(setattr(x, "levels", c("a", "b"))) 104 | #' memory.size(max=TRUE) 105 | #' x[1:4] 106 | #' memory.size(max=TRUE) 107 | #' rm(x) 108 | #' gc() 109 | #' 110 | #' system.time(x <- simplefactor(1e7)) 111 | #' memory.size(max=TRUE) 112 | #' system.time(levels(x) <- c("x", "y")) 113 | #' memory.size(max=TRUE) 114 | #' x[1:4] 115 | #' memory.size(max=TRUE) 116 | #' rm(x) 117 | #' gc() 118 | #' 119 | #' } 120 | #' 121 | #' 122 | #' @export 123 | getsetattr <- function(x, which, value) { 124 | ret <- copy_vector(attr(x, which)) 125 | .Call(C_R_bit_set_attr, x, which, value) 126 | ret 127 | } 128 | 129 | #' @rdname getsetattr 130 | #' @export 131 | setattr <- function(x, which, value) { 132 | .Call(C_R_bit_set_attr, x, which, value) 133 | invisible() 134 | } 135 | 136 | #' @rdname getsetattr 137 | #' @export 138 | setattributes <- function(x, attributes) { 139 | nam <- names(attributes) 140 | for (i in seq_along(attributes)) { 141 | .Call(C_R_bit_set_attr, x, nam[[i]], attributes[[i]]) 142 | } 143 | invisible() 144 | } 145 | 146 | #' Attribute removal 147 | #' 148 | #' Returns object with attributes removed 149 | #' 150 | #' attribute removal copies the object as usual 151 | #' 152 | #' @param x any R object 153 | #' @return a similar object with attributes removed 154 | #' @author Jens Oehlschlägel 155 | #' @seealso [attributes()], [setattributes()], 156 | #' [unclass()] 157 | #' @keywords attribute 158 | #' @examples 159 | #' 160 | #' bit(2)[] 161 | #' unattr(bit(2)[]) 162 | #' 163 | #' @export 164 | 165 | unattr <- function(x) { 166 | attributes(x) <- NULL 167 | x 168 | } 169 | -------------------------------------------------------------------------------- /R/bit-package.R: -------------------------------------------------------------------------------- 1 | # Package documentation 2 | # (c) 2008-2017 Jens Oehlschägel 3 | # Licence: GPL2 4 | # Provided 'as is', use at your own risk 5 | 6 | #' bit: Classes and methods for fast memory-efficient boolean selections 7 | #' 8 | #' Provided are classes for boolean and skewed boolean vectors, fast boolean 9 | #' methods, fast unique and non-unique integer sorting, fast set operations on 10 | #' sorted and unsorted sets of integers, and foundations for ff (range indices, 11 | #' compression, chunked processing). 12 | #' 13 | #' For details view the `vignette("bit-usage")` and `vignette("bit-performance")`. 14 | #' 15 | #'@name bit-package 16 | NULL 17 | 18 | # devtools::use_vignette("bit-usage") 19 | # devtools::use_vignette("bit-performance") 20 | 21 | # olddir <- "../revdepold" 22 | # newdir <- "../revdepnew" 23 | # tools::check_packages_in_dir(olddir, 24 | # check_args = c("--as-cran", ""), 25 | # reverse = list(repos = getOption("repos")["CRAN"])) 26 | # tools::check_packages_in_dir(newdir, old=olddir 27 | # check_args = c("--as-cran", ""), 28 | # reverse = list(repos = getOption("repos")["CRAN"])) 29 | # tools::summarize_check_packages_in_dir_results(newdir, all = FALSE, full = TRUE) 30 | # tools::check_packages_in_dir_changes(newdir, olddir, outputs = TRUE, sources = FALSE) 31 | -------------------------------------------------------------------------------- /R/clone.R: -------------------------------------------------------------------------------- 1 | # clone utilities for bit,bit64,ff 2 | # (c) 2014 Jens Oehlschlägel 3 | # Licence: GPL2 4 | # Provided 'as is', use at your own risk 5 | # Created: 2014-03-02 6 | 7 | 8 | #' Cloning ff and ram objects 9 | #' 10 | #' `clone` physically duplicates objects and can additionally change 11 | #' some features, e.g. length. 12 | #' 13 | #' `clone` is generic. `clone.default` handles ram objects. 14 | #' Further methods are provided in package 'ff'. 15 | #' `still.identical` returns TRUE if the two atomic arguments still 16 | #' point to the same memory. 17 | #' 18 | #' @param x `x` an R object 19 | #' @param ... further arguments to the generic 20 | #' @return an object that is a deep copy of x 21 | #' @author Jens Oehlschlägel 22 | #' @seealso `clone.ff`, [copy_vector()] 23 | #' @keywords IO data 24 | #' @examples 25 | #' 26 | #' x <- 1:12 27 | #' y <- x 28 | #' still.identical(x, y) 29 | #' y[1] <- y[1] 30 | #' still.identical(x, y) 31 | #' y <- clone(x) 32 | #' still.identical(x, y) 33 | #' rm(x, y); gc() 34 | #' 35 | #' @export 36 | clone <- function(x, ...) UseMethod("clone") 37 | 38 | #' @describeIn clone default method uses R's C-API 'duplicate()' 39 | #' @export 40 | clone.default <- function(x, ...) .Call(C_R_duplicate, x) 41 | -------------------------------------------------------------------------------- /R/integerutil.R: -------------------------------------------------------------------------------- 1 | # Integer utilities 2 | # (c) 2016-2017 Jens Oehlschägel 3 | # Licence: GPL2 4 | # Provided 'as is', use at your own risk 5 | 6 | ## Get C reference count of a vector 7 | ## 8 | ## Gets C reference count of a vector 9 | ## 10 | ## Queries the vector reference count using C-macro `NAMED` 11 | ## 12 | ## @param x a vector 13 | ## 14 | ## @return integer scalar 15 | ## @seealso [get_parent_refcnt()], [set_refcnt()] 16 | ## 17 | ## @examples 18 | ## x <- integer() 19 | ## get_refcnt(x) 20 | ## y <- x 21 | ## get_refcnt(x) 22 | ## z <- x 23 | ## get_refcnt(x) 24 | ## 25 | #get_refcnt <- function(x) { 26 | # y <- substitute(x) 27 | # if (is.name(y)) { 28 | # .Call(C_R_get_refcnt, get(as.character(y), envir=parent.frame())) 29 | # } else 30 | # stop("x must be the name of an object") 31 | #} 32 | 33 | ## Set C reference count of a vector 34 | ## 35 | ## Sets C reference count of a vector 36 | ## 37 | ## Manipulates the vector reference count using C-macro `SET_NAMED` 38 | ## 39 | ## @note Do use this only if you know what you do! Otherwise unexpected behaviour can result! 40 | ## 41 | ## @param x a vector 42 | ## @param refcnt integer scalar to be assigned (must be 1L or 2L) 43 | ## 44 | ## @return integer scalar 45 | ## @seealso @seealso [get_refcnt()], [get_parent_refcnt()] 46 | ## 47 | ## @examples 48 | ## x <- integer() 49 | ## get_refcnt(x) 50 | ## y <- x 51 | ## get_refcnt(x) 52 | ## z <- x 53 | ## get_refcnt(x) 54 | #set_refcnt <- function(x, refcnt=1L) { 55 | # invisible(.Call(C_R_set_refcnt, x, as.integer(refcnt))) 56 | #} 57 | 58 | ## Get C pareet reference count of a vector 59 | ## 60 | ## Gets C reference count of a vector in parent frame 61 | ## 62 | ## Queries the vector reference count using C-macro `NAMED` 63 | ## 64 | ## @param x a vector 65 | ## 66 | ## @return integer scalar 67 | ## @seealso [get_refcnt()], [set_refcnt()] 68 | ## 69 | ## @examples 70 | ## f <- function(x) c(refcnt=get_refcnt(x), parent_refcnt=get_parent_refcnt(x)) 71 | ## x <- integer() 72 | ## f(x) 73 | ## y <- x 74 | ## f(x) 75 | ## z <- x 76 | ## f(x) 77 | ## f(0) 78 | ## try(get_parent_refcnt(0)) 79 | #get_parent_refcnt <- function(x) { 80 | # y <- substitute(x) 81 | # if (is.name(y)) { 82 | # z <- eval(call("substitute", y), parent.frame()) 83 | # if (is.name(z)) { 84 | # .Call(C_R_get_refcnt, get(as.character(z), envir=parent.frame(2))) 85 | # } else 86 | # 0L 87 | # } else 88 | # stop("x must be the name of an object") 89 | #} 90 | 91 | # named <- function(x) 92 | # .Call(C_R_bit_named, x) 93 | 94 | 95 | 96 | #' Get C length of a vector 97 | #' 98 | #' Gets C length of a vector ignoring any length-methods dispatched by classes 99 | #' 100 | #' Queries the vector length using C-macro `LENGTH`, this can be substantially faster than 101 | #' `length(unclass(x))` 102 | #' 103 | #' @param x a vector 104 | #' @return integer scalar 105 | #' @examples 106 | #' length(bit(12)) 107 | #' get_length(bit(12)) 108 | #' @export 109 | get_length <- function(x) { 110 | .Call(C_R_get_length, x) 111 | } 112 | 113 | 114 | #' Test for C-level identity of two atomic vectors 115 | #' 116 | #' @param x an atomic vector 117 | #' @param y an atomic vector 118 | #' @return logical scalar 119 | #' @examples 120 | #' x <- 1:2 121 | #' y <- x 122 | #' z <- copy_vector(x) 123 | #' still.identical(y, x) 124 | #' still.identical(z, x) 125 | #' @export 126 | still.identical <- function(x, y) { 127 | .Call(C_R_still_identical, x = x, y = y) 128 | } 129 | 130 | #' Copy atomic R vector 131 | #' 132 | #' Creates a true copy of the underlying C-vector -- dropping all attributes -- and 133 | #' optionally reverses the direction of the elements. 134 | #' 135 | #' This can be substantially faster than `duplicate(as.vector(unclass(x)))` 136 | #' 137 | #' @param x an R vector 138 | #' @param revx default `FALSE`, set to `TRUE` to reverse the elements in 'x' 139 | #' @return copied R vector 140 | #' @seealso [clone()], [still.identical()], [reverse_vector()] 141 | #' @examples 142 | #' x <- factor(letters) 143 | #' y <- x 144 | #' z <- copy_vector(x) 145 | #' still.identical(x, y) 146 | #' still.identical(x, z) 147 | #' str(x) 148 | #' str(y) 149 | #' str(z) 150 | #' @export 151 | copy_vector <- function(x, revx=FALSE) { 152 | .Call(C_R_copy_vector, x, as.logical(revx)) 153 | } 154 | 155 | 156 | #' Reverse atomic vector 157 | #' 158 | #' Returns a reversed copy -- with attributes retained. 159 | #' 160 | #' This is substantially faster than [rev()] 161 | #' 162 | #' @param x an R vector 163 | #' @return a reversed vector 164 | #' @seealso [rev()], [copy_vector()] 165 | #' @examples 166 | #' x <- factor(letters) 167 | #' rev(x) 168 | #' reverse_vector(x) 169 | #' \dontrun{ 170 | #' x <- 1:1e7 171 | #' system.time(rev(x)) 172 | #' system.time(reverse_vector(x)) 173 | #' } 174 | #' @export 175 | reverse_vector <- function(x) { 176 | .Call(C_R_reverse_vector, x) 177 | } 178 | 179 | #' Position of first NA 180 | #' 181 | #' This is substantially faster than `which.max(is.na(x))` 182 | #' 183 | #' @param x an R vector 184 | #' @return a reversed vector 185 | #' @seealso [which.max()], [is.na()], [anyNA()], [anyDuplicated()], [bit_anyDuplicated()] 186 | #' @examples 187 | #' x <- c(FALSE, NA, TRUE) 188 | #' firstNA(x) 189 | #' reverse_vector(x) 190 | #' \dontrun{ 191 | #' x <- 1:1e7 192 | #' system.time(rev(x)) 193 | #' system.time(reverse_vector(x)) 194 | #' } 195 | #' @export 196 | firstNA <- function(x) { 197 | .Call(C_R_firstNA, x) 198 | } 199 | -------------------------------------------------------------------------------- /R/rle.R: -------------------------------------------------------------------------------- 1 | # rle utilities for bit and ff 2 | # (c) 2007-2009 Jens Oehlschägel 3 | # Licence: GPL2 4 | # Provided 'as is', use at your own risk 5 | # Created: 2007-09-03 6 | # Last changed: 2007-10-25 7 | 8 | # source("D:/mwp/eanalysis/bit/R/rle.R") 9 | 10 | #' Hybrid Index, C-coded utilities 11 | #' 12 | #' These C-coded utilitites speed up index preprocessing considerably. 13 | #' 14 | #' `intrle` is by factor 50 faster and needs less RAM (2x its input 15 | #' vector) compared to [rle()] which needs 9x the RAM of its input 16 | #' vector. This is achieved because we allow the C-code of `intrle` to 17 | #' break when it turns out, that rle-packing will not achieve a compression 18 | #' factor of 3 or better. 19 | #' 20 | #' `intisasc` is a faster version of [is.unsorted()]: it checks whether `x` is sorted. 21 | #' 22 | #' `intisdesc` checks for being sorted descending and by default default assumes that the 23 | #' input `x` contains no NAs. 24 | #' 25 | #' `na.method="none"` treats `NAs` (the smallest integer) like every other integer and 26 | #' hence returns either `TRUE` or `FALSE` `na.method="break"` checks for `NAs` and 27 | #' returns either `NA` as soon as `NA` is encountered. `na.method="skip"` checks for 28 | #' `NAs` and skips over them, hence decides the return value only on the basis of 29 | #' non-NA values. 30 | #' 31 | #' 32 | #' @param x an integer vector 33 | #' @param na.method one of "none", "break", "skip", see details. The strange defaults stem 34 | #' from the initial usage. 35 | #' @return 36 | #' - `intrle` returns an object of class [rle()] or NULL, if rle-compression is not 37 | #' efficient (compression factor <3 or `length(x) < 3`). 38 | #' - `intisasc` returns one of `FALSE, NA, TRUE` 39 | #' - `intisdesc` returns one of `FALSE, TRUE` (if the input contains NAs, the output is 40 | #' undefined) 41 | #' @author Jens Oehlschlägel 42 | #' @seealso [ff::hi()], [rle()], [is.unsorted()], 43 | #' [ff::is.sorted.default()] 44 | #' @keywords IO data 45 | #' @examples 46 | #' 47 | #' intrle(sample(1:10)) 48 | #' intrle(diff(1:10)) 49 | #' intisasc(1:10) 50 | #' intisasc(10:1) 51 | #' intisasc(c(NA, 1:10)) 52 | #' intisdesc(1:10) 53 | #' intisdesc(c(10:1, NA)) 54 | #' intisdesc(c(10:6, NA, 5:1)) 55 | #' intisdesc(c(10:6, NA, 5:1), na.method="skip") 56 | #' intisdesc(c(10:6, NA, 5:1), na.method="break") 57 | #' 58 | #' @export 59 | # -- fast and efficient rle ------------------ 60 | 61 | # integer only 62 | # returns rle object only if n>2 && rle is efficient 63 | # (length(values) + lengths(lengths)) <= length(x) 64 | # returns NULL if n<3 || rle is inefficient 65 | intrle <- function(x) { 66 | stopifnot(is.integer(x)) 67 | .Call(C_R_int_rle, x) 68 | } 69 | 70 | 71 | # -- check for sorting and NAs, 0s can be checked later when sorted ------------------ 72 | 73 | #' @describeIn intrle check whether integer vector is ascending 74 | #' @export 75 | intisasc <- function(x, na.method=c("none", "break", "skip")[2]) { 76 | stopifnot(is.integer(x)) 77 | if (na.method == "break") 78 | .Call(C_R_int_is_asc_break, x) 79 | else if (na.method == "none") 80 | .Call(C_R_int_is_asc_none, x) 81 | else 82 | .Call(C_R_int_is_asc_skip, x) 83 | } 84 | 85 | #' @describeIn intrle check whether integer vector is descending 86 | #' @export 87 | intisdesc <- function(x, na.method=c("none", "break", "skip")[1]) { 88 | stopifnot(is.integer(x)) 89 | if (na.method == "none") 90 | .Call(C_R_int_is_desc_none, x) 91 | else if (na.method == "break") 92 | .Call(C_R_int_is_desc_break, x) 93 | else 94 | .Call(C_R_int_is_desc_skip, x) 95 | } 96 | 97 | 98 | 99 | 100 | # -- basic sequence packing and unpacking --------------------------------------------------- 101 | 102 | #' Hybrid Index, rle-pack utilities 103 | #' 104 | #' Basic utilities for rle packing and unpacking and apropriate methods for 105 | #' [rev()] and [unique()]. 106 | #' 107 | #' 108 | #' @param x in 'rlepack' an integer vector, in the other functions an object of 109 | #' class 'rlepack' 110 | #' @param pack FALSE to suppress packing 111 | #' @param incomparables just to keep R CMD CHECK quiet (not used) 112 | #' @param ... just to keep R CMD CHECK quiet (not used) 113 | #' @return A list with components: 114 | #' - first: the first element of the packed sequence 115 | #' - dat: either an object of class [rle()] or the complete input vector `x` if 116 | #' rle-packing is not efficient 117 | #' - last: the last element of the packed sequence 118 | #' 119 | #' @author Jens Oehlschlägel 120 | #' @seealso [ff::hi()], [intrle()], [rle()], [rev()], [unique()] 121 | #' @keywords IO data 122 | #' @examples 123 | #' 124 | #' x <- rlepack(rep(0L, 10)) 125 | #' 126 | #' @export 127 | rlepack <- function(x, ...) UseMethod("rlepack") 128 | 129 | #' @rdname rlepack 130 | #' @export 131 | rlepack.integer <- function(x, pack = TRUE, ...) { 132 | stopifnot(is.integer(x)) 133 | n <- length(x) 134 | if (n > 1L) { 135 | if (pack) 136 | # returns NULL if rle is inefficient, old condition was 2*length(r$lengths) 21 | #' @seealso [system.time()] 22 | #' @keywords utilities 23 | #' @examples 24 | #' 25 | #' system.time(1 + 1) 26 | #' repeat.time(1 + 1) 27 | #' system.time(sort(runif(1e6))) 28 | #' repeat.time(sort(runif(1e6))) 29 | #' 30 | #' @export 31 | repeat.time <- function(expr, gcFirst = TRUE, minSec=0.5, envir=parent.frame()) { 32 | ppt <- function(y) { 33 | if (!is.na(y[4L])) 34 | y[1L] <- y[1L] + y[4L] 35 | if (!is.na(y[5L])) 36 | y[2L] <- y[2L] + y[5L] 37 | y[1L:3L] 38 | } 39 | if (!exists("proc.time")) 40 | return(rep(NA_real_, 5L)) 41 | if (gcFirst) 42 | gc(FALSE) 43 | time0 <- proc.time() 44 | on.exit(cat("Timing stopped at:", ppt(proc.time() - time0), "\n")) 45 | r <- 0L 46 | while ((proc.time()[3L] - time0[3L]) < minSec) { 47 | r <- r + 1L 48 | eval(substitute(expr), envir=envir) 49 | } 50 | new.time <- proc.time() 51 | on.exit() 52 | out = (new.time - time0) / r 53 | class(out) = "proc_time" 54 | out 55 | } 56 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | # Package intialization 2 | # (c) 2008-2017 Jens Oehlschägel 3 | # Licence: GPL2 4 | # Provided 'as is', use at your own risk 5 | 6 | # nolint next: coalesce_linter. obv ;-) 7 | if (!exists("%||%", "package:base")) `%||%` = function(x, y) if (is.null(x)) y else x 8 | 9 | #' @useDynLib bit, .registration = TRUE, .fixes = "C_" 10 | #' @importFrom utils packageDescription 11 | .onLoad <- function(lib, pkg) { 12 | bit_init() 13 | } 14 | 15 | .onUnload <- function(libpath) { 16 | bit_done() 17 | library.dynam.unload("bit", libpath) 18 | } 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bit 2 | R package with Classes and Methods for Fast Memory-Efficient Boolean Selections 3 | 4 | see [CRAN](https://cran.r-project.org/package=bit) 5 | -------------------------------------------------------------------------------- /bit.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | PackageRoxygenize: rd,collate,namespace 19 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | informational: true 10 | patch: 11 | default: 12 | target: auto 13 | threshold: 1% 14 | informational: true 15 | -------------------------------------------------------------------------------- /man/CoercionToStandard.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{CoercionToStandard} 4 | \alias{CoercionToStandard} 5 | \alias{as.logical.bit} 6 | \alias{as.integer.bit} 7 | \alias{as.double.bit} 8 | \alias{as.integer.bitwhich} 9 | \alias{as.double.bitwhich} 10 | \alias{as.logical.bitwhich} 11 | \alias{as.logical.ri} 12 | \alias{as.integer.ri} 13 | \alias{as.double.ri} 14 | \alias{as.logical.which} 15 | \title{Coercion from bit, bitwhich, which and ri to logical, integer, double} 16 | \usage{ 17 | \method{as.logical}{bit}(x, ...) 18 | 19 | \method{as.integer}{bit}(x, ...) 20 | 21 | \method{as.double}{bit}(x, ...) 22 | 23 | \method{as.integer}{bitwhich}(x, ...) 24 | 25 | \method{as.double}{bitwhich}(x, ...) 26 | 27 | \method{as.logical}{bitwhich}(x, ...) 28 | 29 | \method{as.logical}{ri}(x, ...) 30 | 31 | \method{as.integer}{ri}(x, ...) 32 | 33 | \method{as.double}{ri}(x, ...) 34 | 35 | \method{as.logical}{which}(x, length = attr(x, "maxindex"), ...) 36 | } 37 | \arguments{ 38 | \item{x}{an object of class \code{\link[=bit]{bit()}}, \code{\link[=bitwhich]{bitwhich()}} or 39 | \code{\link[=ri]{ri()}}} 40 | 41 | \item{...}{ignored} 42 | 43 | \item{length}{length of the boolean vector (required for \code{as.logical.which})} 44 | } 45 | \value{ 46 | \code{\link[=as.logical]{as.logical()}} returns a vector of \verb{FALSE, TRUE}, 47 | \code{\link[=as.integer]{as.integer()}} and \code{\link[=as.double]{as.double()}} return a vector of 48 | \verb{0,1}. 49 | } 50 | \description{ 51 | Coercion from bit is quite fast because we use a double loop that fixes each 52 | word in a processor register. 53 | } 54 | \examples{ 55 | 56 | x <- ri(2, 5, 10) 57 | y <- as.logical(x) 58 | y 59 | stopifnot(identical(y, as.logical(as.bit(x)))) 60 | stopifnot(identical(y, as.logical(as.bitwhich(x)))) 61 | 62 | y <- as.integer(x) 63 | y 64 | stopifnot(identical(y, as.integer(as.logical(x)))) 65 | stopifnot(identical(y, as.integer(as.bit(x)))) 66 | stopifnot(identical(y, as.integer(as.bitwhich(x)))) 67 | 68 | y <- as.double(x) 69 | y 70 | stopifnot(identical(y, as.double(as.logical(x)))) 71 | stopifnot(identical(y, as.double(as.bit(x)))) 72 | stopifnot(identical(y, as.double(as.bitwhich(x)))) 73 | } 74 | \seealso{ 75 | \code{\link{CoercionToStandard}}, \code{\link[=as.booltype]{as.booltype()}}, \code{\link[=as.bit]{as.bit()}}, 76 | \code{\link[=as.bitwhich]{as.bitwhich()}} , \code{\link[=as.which]{as.which()}}, \code{\link[=as.ri]{as.ri()}}, \code{\link[ff:as.hi]{ff::as.hi()}}, \code{\link[ff:as.ff]{ff::as.ff()}} 77 | } 78 | \author{ 79 | Jens Oehlschlägel 80 | } 81 | \keyword{classes} 82 | \keyword{logic} 83 | -------------------------------------------------------------------------------- /man/Extract.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{Extract} 4 | \alias{Extract} 5 | \alias{[[.bit} 6 | \alias{[[<-.bit} 7 | \alias{[.bit} 8 | \alias{[<-.bit} 9 | \alias{[[.bitwhich} 10 | \alias{[[<-.bitwhich} 11 | \alias{[.bitwhich} 12 | \alias{[<-.bitwhich} 13 | \title{Extract or replace part of an boolean vector} 14 | \usage{ 15 | \method{[[}{bit}(x, i) 16 | 17 | \method{[[}{bit}(x, i) <- value 18 | 19 | \method{[}{bit}(x, i) 20 | 21 | \method{[}{bit}(x, i) <- value 22 | 23 | \method{[[}{bitwhich}(x, i) 24 | 25 | \method{[[}{bitwhich}(x, i) <- value 26 | 27 | \method{[}{bitwhich}(x, i) 28 | 29 | \method{[}{bitwhich}(x, i) <- value 30 | } 31 | \arguments{ 32 | \item{x}{a \code{\link[=bit]{bit()}} or \code{\link[=bitwhich]{bitwhich()}} object} 33 | 34 | \item{i}{preferrably a positive integer subscript or a \code{\link[=ri]{ri()}}, see text} 35 | 36 | \item{value}{new logical or integer values} 37 | } 38 | \value{ 39 | The extractors \code{[[} and \code{[} return a logical scalar or 40 | vector. The replacment functions return an object of \code{class(x)}. 41 | } 42 | \description{ 43 | Operators acting on \code{\link[=bit]{bit()}} or \code{\link[=bitwhich]{bitwhich()}} objects to extract or replace parts. 44 | } 45 | \details{ 46 | The typical usecase for '[' and '[<-' is subscripting with positive integers, 47 | negative integers are allowed but slower, 48 | as logical subscripts only scalars are allowed. 49 | The subscript can be given as a \code{\link[=bitwhich]{bitwhich()}} object. 50 | Also \code{\link[=ri]{ri()}} can be used as subscript. 51 | 52 | Extracting from \code{\link[=bit]{bit()}} and \code{\link[=bitwhich]{bitwhich()}} is faster than from \code{\link[=logical]{logical()}} if positive 53 | subscripts are used. Unteger subscripts make sense. Negative subscripts are 54 | converted to positive ones, beware the RAM consumption. 55 | } 56 | \examples{ 57 | 58 | x <- as.bit(c(FALSE, NA, TRUE)) 59 | x[] <- c(FALSE, NA, TRUE) 60 | x[1:2] 61 | x[-3] 62 | x[ri(1, 2)] 63 | x[as.bitwhich(c(TRUE, TRUE, FALSE))] 64 | x[[1]] 65 | x[] <- TRUE 66 | x[1:2] <- FALSE 67 | x[[1]] <- TRUE 68 | 69 | } 70 | \seealso{ 71 | \code{\link[=bit]{bit()}}, \link[base:Extract]{`Extract``} 72 | } 73 | \author{ 74 | Jens Oehlschlägel 75 | } 76 | \keyword{classes} 77 | \keyword{logic} 78 | -------------------------------------------------------------------------------- /man/Metadata.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R 3 | \name{Metadata} 4 | \alias{Metadata} 5 | \alias{is.sorted} 6 | \alias{is.sorted<-} 7 | \alias{na.count} 8 | \alias{na.count<-} 9 | \alias{nvalid} 10 | \alias{nunique} 11 | \alias{nunique<-} 12 | \alias{nties} 13 | \alias{nties<-} 14 | \title{Generics related to cache access} 15 | \usage{ 16 | is.sorted(x, ...) 17 | 18 | is.sorted(x, ...) <- value 19 | 20 | na.count(x, ...) 21 | 22 | na.count(x, ...) <- value 23 | 24 | nvalid(x, ...) 25 | 26 | nunique(x, ...) 27 | 28 | nunique(x, ...) <- value 29 | 30 | nties(x, ...) 31 | 32 | nties(x, ...) <- value 33 | } 34 | \arguments{ 35 | \item{x}{some object} 36 | 37 | \item{...}{ignored} 38 | 39 | \item{value}{value assigned on responsibility of the user} 40 | } 41 | \value{ 42 | see help of the available methods 43 | } 44 | \description{ 45 | These generics are packaged here for methods in packages \code{bit64} and 46 | \code{ff}. 47 | } 48 | \details{ 49 | see help of the available methods 50 | } 51 | \examples{ 52 | methods("na.count") 53 | } 54 | \seealso{ 55 | \code{\link[bit64:is.sorted.integer64]{bit64::is.sorted.integer64()}}, \code{\link[bit64:is.sorted.integer64]{bit64::na.count.integer64()}}, 56 | \code{\link[bit64:is.sorted.integer64]{bit64::nvalid.integer64()}}, \code{\link[bit64:is.sorted.integer64]{bit64::nunique.integer64()}}, \code{\link[bit64:is.sorted.integer64]{bit64::nties.integer64()}} 57 | } 58 | \author{ 59 | Jens Oehlschlägel \href{mailto:Jens.Oehlschlaegel@truecluster.com}{Jens.Oehlschlaegel@truecluster.com} 60 | } 61 | \keyword{environment} 62 | \keyword{methods} 63 | -------------------------------------------------------------------------------- /man/PhysVirt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R, R/generics.R 3 | \name{physical.default} 4 | \alias{physical.default} 5 | \alias{physical<-.default} 6 | \alias{virtual.default} 7 | \alias{virtual<-.default} 8 | \alias{print.physical} 9 | \alias{print.virtual} 10 | \alias{PhysVirt} 11 | \alias{physical} 12 | \alias{physical<-} 13 | \alias{virtual} 14 | \alias{virtual<-} 15 | \title{Physical and virtual attributes} 16 | \usage{ 17 | \method{physical}{default}(x) 18 | 19 | \method{physical}{default}(x) <- value 20 | 21 | \method{virtual}{default}(x) 22 | 23 | \method{virtual}{default}(x) <- value 24 | 25 | \method{print}{physical}(x, ...) 26 | 27 | \method{print}{virtual}(x, ...) 28 | 29 | physical(x) 30 | 31 | physical(x) <- value 32 | 33 | virtual(x) 34 | 35 | virtual(x) <- value 36 | } 37 | \arguments{ 38 | \item{x}{a ff or ram object} 39 | 40 | \item{value}{a list with named elements} 41 | 42 | \item{...}{further arguments} 43 | } 44 | \value{ 45 | \code{physical} and \code{virtual} returns a list with named elements 46 | } 47 | \description{ 48 | Compatibility functions (to package ff) for getting and setting physical and 49 | virtual attributes. 50 | } 51 | \details{ 52 | ff objects have physical and virtual attributes, which have different 53 | copying semantics: physical attributes are shared between copies of ff 54 | objects while virtual attributes might differ between copies. 55 | \code{\link[ff:as.ff]{ff::as.ram()}} will retain some physical and virtual atrributes in 56 | the ram clone, such that \code{\link[ff:as.ff]{ff::as.ff()}} can restore an ff object 57 | with the same attributes. 58 | } 59 | \examples{ 60 | 61 | physical(bit(12)) 62 | virtual(bit(12)) 63 | } 64 | \seealso{ 65 | \code{\link[ff:physical.ff]{ff::physical.ff()}}, \code{\link[ff:physical.ffdf]{ff::physical.ffdf()}} 66 | } 67 | \author{ 68 | Jens Oehlschlägel 69 | } 70 | \keyword{IO} 71 | \keyword{attribute} 72 | \keyword{data} 73 | -------------------------------------------------------------------------------- /man/Sorting.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R 3 | \name{Sorting} 4 | \alias{Sorting} 5 | \alias{ramsort} 6 | \alias{ramorder} 7 | \alias{ramsortorder} 8 | \alias{mergesort} 9 | \alias{mergeorder} 10 | \alias{mergesortorder} 11 | \alias{quicksort} 12 | \alias{quickorder} 13 | \alias{quicksortorder} 14 | \alias{shellsort} 15 | \alias{shellorder} 16 | \alias{shellsortorder} 17 | \alias{radixsort} 18 | \alias{radixorder} 19 | \alias{radixsortorder} 20 | \alias{keysort} 21 | \alias{keyorder} 22 | \alias{keysortorder} 23 | \title{Generics for in-RAM sorting and ordering} 24 | \usage{ 25 | ramsort(x, ...) 26 | 27 | ramorder(x, i, ...) 28 | 29 | ramsortorder(x, i, ...) 30 | 31 | mergesort(x, ...) 32 | 33 | mergeorder(x, i, ...) 34 | 35 | mergesortorder(x, i, ...) 36 | 37 | quicksort(x, ...) 38 | 39 | quickorder(x, i, ...) 40 | 41 | quicksortorder(x, i, ...) 42 | 43 | shellsort(x, ...) 44 | 45 | shellorder(x, i, ...) 46 | 47 | shellsortorder(x, i, ...) 48 | 49 | radixsort(x, ...) 50 | 51 | radixorder(x, i, ...) 52 | 53 | radixsortorder(x, i, ...) 54 | 55 | keysort(x, ...) 56 | 57 | keyorder(x, i, ...) 58 | 59 | keysortorder(x, i, ...) 60 | } 61 | \arguments{ 62 | \item{x}{a vector to be sorted by \code{\link[=ramsort]{ramsort()}} and 63 | \code{\link[=ramsortorder]{ramsortorder()}}, i.e. the output of \code{\link[=sort]{sort()}}} 64 | 65 | \item{...}{further arguments to the sorting methods} 66 | 67 | \item{i}{integer positions to be modified by \code{\link[=ramorder]{ramorder()}} and 68 | \code{\link[=ramsortorder]{ramsortorder()}}, default is 1:n, in this case the output is 69 | similar to \code{\link[=order]{order()}}} 70 | } 71 | \value{ 72 | These functions return the number of \code{NAs} found or assumed 73 | during sorting 74 | } 75 | \description{ 76 | These are generic stubs for low-level sorting and ordering methods 77 | implemented in packages 'bit64' and 'ff'. The \code{..sortorder} methods do 78 | sorting and ordering at once, which requires more RAM than ordering but is 79 | (almost) as fast as as sorting. 80 | } 81 | \details{ 82 | The \code{sort} generics do sort their argument 'x', some methods need 83 | temporary RAM of the same size as 'x'. The \code{order} generics do order 84 | their argument 'i' leaving 'x' as it was, some methods need temporary RAM of 85 | the same size as 'i'. The \code{sortorder} generics do sort their argument 86 | 'x' and order their argument 'i', this way of ordering is much faster at the 87 | price of requiring temporary RAM for both, 'x' and 'i', if the method 88 | requires temporary RAM. The \code{ram} generics are high-level functions 89 | containing an optimizer that chooses the 'best' algorithms given some 90 | context. 91 | } 92 | \note{ 93 | Note that these methods purposely violate the functional programming 94 | paradigm: they are called for the side-effect of changing some of their 95 | arguments. The rationale behind this is that sorting is very RAM-intensive 96 | and in certain situations we might not want to allocate additional memory if 97 | not necessary to do so. The \code{sort}-methods change \code{x}, the 98 | \code{order}-methods change \code{i}, and the \code{sortoder}-methods change 99 | both \code{x} and \code{i} You as the user are responsible to create copies 100 | of the input data 'x' and 'i' if you need non-modified versions. 101 | } 102 | \section{Index of implemented methods}{ 103 | \tabular{rrl}{ 104 | \strong{generic} \tab \strong{ff} \tab \strong{bit64} \cr 105 | \code{ramsort} \tab \code{\link[ff:ramsort.default]{ff::ramsort.default()}} \tab \code{\link[bit64:ramsort.integer64]{bit64::ramsort.integer64()}} \cr 106 | \code{shellsort} \tab \code{\link[ff:ramsort.default]{ff::shellsort.default()}} \tab \code{\link[bit64:ramsort.integer64]{bit64::shellsort.integer64()}} \cr 107 | \code{quicksort} \tab \tab \code{\link[bit64:ramsort.integer64]{bit64::quicksort.integer64()}} \cr 108 | \code{mergesort} \tab \code{\link[ff:ramsort.default]{ff::mergesort.default()}} \tab \code{\link[bit64:ramsort.integer64]{bit64::mergesort.integer64()}} \cr 109 | \code{radixsort} \tab \code{\link[ff:ramsort.default]{ff::radixsort.default()}} \tab \code{\link[bit64:ramsort.integer64]{bit64::radixsort.integer64()}} \cr 110 | \code{keysort} \tab \code{\link[ff:ramsort.default]{ff::keysort.default()}} \tab \cr 111 | \code{ramorder} \tab \code{\link[ff:ramorder.default]{ff::ramorder.default()}} \tab \code{\link[bit64:ramsort.integer64]{bit64::ramorder.integer64()}} \cr 112 | \code{shellorder} \tab \code{\link[ff:ramorder.default]{ff::shellorder.default()}} \tab \code{\link[bit64:ramsort.integer64]{bit64::shellorder.integer64()}} \cr 113 | \code{quickorder} \tab \tab \code{\link[bit64:ramsort.integer64]{bit64::quickorder.integer64()}} \cr 114 | \code{mergeorder} \tab \code{\link[ff:ramorder.default]{ff::mergeorder.default()}} \tab \code{\link[bit64:ramsort.integer64]{bit64::mergeorder.integer64()}} \cr 115 | \code{radixorder} \tab \code{\link[ff:ramorder.default]{ff::radixorder.default()}} \tab \code{\link[bit64:ramsort.integer64]{bit64::radixorder.integer64()}} \cr 116 | \code{keyorder} \tab \code{\link[ff:ramorder.default]{ff::keyorder.default()}} \tab \cr 117 | \code{ramsortorder} \tab \tab \code{\link[bit64:ramsort.integer64]{bit64::ramsortorder.integer64()}} \cr 118 | \code{shellsortorder} \tab \tab \code{\link[bit64:ramsort.integer64]{bit64::shellsortorder.integer64()}} \cr 119 | \code{quicksortorder} \tab \tab \code{\link[bit64:ramsort.integer64]{bit64::quicksortorder.integer64()}} \cr 120 | \code{mergesortorder} \tab \tab \code{\link[bit64:ramsort.integer64]{bit64::mergesortorder.integer64()}} \cr 121 | \code{radixsortorder} \tab \tab \code{\link[bit64:ramsort.integer64]{bit64::radixsortorder.integer64()}} \cr 122 | \code{keysortorder} \tab \tab \cr 123 | } 124 | } 125 | 126 | \seealso{ 127 | \code{\link[=sort]{sort()}} and \code{\link[=order]{order()}} in base R, \code{\link[=bitsort]{bitsort()}} for faster inteer sorting 128 | } 129 | \author{ 130 | Jens Oehlschlägel \href{mailto:Jens.Oehlschlaegel@truecluster.com}{Jens.Oehlschlaegel@truecluster.com} 131 | } 132 | \keyword{arith} 133 | \keyword{manip} 134 | \keyword{univar} 135 | -------------------------------------------------------------------------------- /man/Summaries.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{Summaries} 4 | \alias{Summaries} 5 | \alias{all.bit} 6 | \alias{any.bit} 7 | \alias{anyNA.bit} 8 | \alias{sum.bit} 9 | \alias{min.bit} 10 | \alias{max.bit} 11 | \alias{range.bit} 12 | \alias{summary.bit} 13 | \alias{all.bitwhich} 14 | \alias{any.bitwhich} 15 | \alias{anyNA.bitwhich} 16 | \alias{sum.bitwhich} 17 | \alias{min.bitwhich} 18 | \alias{max.bitwhich} 19 | \alias{range.bitwhich} 20 | \alias{summary.bitwhich} 21 | \alias{all.which} 22 | \alias{any.which} 23 | \alias{anyNA.which} 24 | \alias{sum.which} 25 | \alias{min.which} 26 | \alias{max.which} 27 | \alias{range.which} 28 | \alias{summary.which} 29 | \alias{all.booltype} 30 | \alias{any.booltype} 31 | \alias{anyNA.booltype} 32 | \alias{sum.booltype} 33 | \alias{min.booltype} 34 | \alias{max.booltype} 35 | \alias{range.booltype} 36 | \alias{summary.booltype} 37 | \alias{all.ri} 38 | \alias{any.ri} 39 | \alias{anyNA.ri} 40 | \alias{sum.ri} 41 | \alias{min.ri} 42 | \alias{max.ri} 43 | \alias{range.ri} 44 | \alias{summary.ri} 45 | \title{Summaries of boolean vectors} 46 | \usage{ 47 | \method{all}{bit}(x, range = NULL, ...) 48 | 49 | \method{any}{bit}(x, range = NULL, ...) 50 | 51 | \method{anyNA}{bit}(x, recursive = FALSE) 52 | 53 | \method{sum}{bit}(x, range = NULL, ...) 54 | 55 | \method{min}{bit}(x, range = NULL, ...) 56 | 57 | \method{max}{bit}(x, range = NULL, ...) 58 | 59 | \method{range}{bit}(x, range = NULL, ...) 60 | 61 | \method{summary}{bit}(object, range = NULL, ...) 62 | 63 | \method{all}{bitwhich}(x, range = NULL, ...) 64 | 65 | \method{any}{bitwhich}(x, range = NULL, ...) 66 | 67 | \method{anyNA}{bitwhich}(x, recursive = FALSE) 68 | 69 | \method{sum}{bitwhich}(x, range = NULL, ...) 70 | 71 | \method{min}{bitwhich}(x, range = NULL, ...) 72 | 73 | \method{max}{bitwhich}(x, range = NULL, ...) 74 | 75 | \method{range}{bitwhich}(x, range = NULL, ...) 76 | 77 | \method{summary}{bitwhich}(object, range = NULL, ...) 78 | 79 | \method{all}{which}(x, range = NULL, ...) 80 | 81 | \method{any}{which}(x, range = NULL, ...) 82 | 83 | \method{anyNA}{which}(x, recursive = FALSE) 84 | 85 | \method{sum}{which}(x, range = NULL, ...) 86 | 87 | \method{min}{which}(x, range = NULL, ...) 88 | 89 | \method{max}{which}(x, range = NULL, ...) 90 | 91 | \method{range}{which}(x, range = NULL, ...) 92 | 93 | \method{summary}{which}(object, range = NULL, ...) 94 | 95 | \method{all}{booltype}(x, range = NULL, ...) 96 | 97 | \method{any}{booltype}(x, range = NULL, ...) 98 | 99 | \method{anyNA}{booltype}(x, ...) 100 | 101 | \method{sum}{booltype}(x, range = NULL, ...) 102 | 103 | \method{min}{booltype}(x, range = NULL, ...) 104 | 105 | \method{max}{booltype}(x, range = NULL, ...) 106 | 107 | \method{range}{booltype}(x, range = NULL, ...) 108 | 109 | \method{summary}{booltype}(object, range = NULL, ...) 110 | 111 | \method{all}{ri}(x, range = NULL, ...) 112 | 113 | \method{any}{ri}(x, range = NULL, ...) 114 | 115 | \method{anyNA}{ri}(x, recursive = FALSE) 116 | 117 | \method{sum}{ri}(x, ...) 118 | 119 | \method{min}{ri}(x, ...) 120 | 121 | \method{max}{ri}(x, ...) 122 | 123 | \method{range}{ri}(x, ...) 124 | 125 | \method{summary}{ri}(object, ...) 126 | } 127 | \arguments{ 128 | \item{x}{an object of class bit or bitwhich} 129 | 130 | \item{range}{a \code{\link[=ri]{ri()}} or an integer vector of length == 2 giving a 131 | range restriction for chunked processing} 132 | 133 | \item{...}{formally required but not used} 134 | 135 | \item{recursive}{formally required but not used} 136 | 137 | \item{object}{an object of class bit} 138 | } 139 | \value{ 140 | as expected 141 | } 142 | \description{ 143 | Fast aggregation functions for \code{\link[=booltype]{booltype()}} vectors. namely \code{\link[=bit]{bit()}}, \code{\link[=all]{all()}}, \code{\link[=any]{any()}}, 144 | \code{\link[=anyNA]{anyNA()}}, \code{\link[=min]{min()}}, \code{\link[=max]{max()}}, \code{\link[=range]{range()}}, \code{\link[=sum]{sum()}} and \code{\link[=summary]{summary()}}. 145 | Now all boolean summaries (except for \code{anyNA} because the generic does not allow it) 146 | have an optional \code{range} argument to restrict the range of evalution. 147 | Note that the boolean summaries have meaning and return values differing from logical 148 | aggregation functions: they treat \code{NA} as \code{FALSE}, \code{min}, \code{max} and \code{range} give the 149 | minimum and maximum positions of \code{TRUE}, \code{summary} returns counts of \code{FALSE}, \code{TRUE} 150 | and the \code{range}. 151 | Note that you can force the boolean interpretation by calling the booltype method 152 | explicitly on any \code{\link{booltypes}} input, e.g. \code{min.booltype()}, see the 153 | examples. 154 | } 155 | \details{ 156 | Summaries of \code{\link[=bit]{bit()}} vectors are quite fast because we use a double loop that fixes 157 | each word in a processor register. Furthermore we break out of looping as soon 158 | as possible. Summaries of \code{\link[=bitwhich]{bitwhich()}} vectors are even faster, if the selection is 159 | very skewed. 160 | } 161 | \examples{ 162 | 163 | l <- c(NA, FALSE, TRUE) 164 | b <- as.bit(l) 165 | 166 | all(l) 167 | all(b) 168 | all(b, range=c(3, 3)) 169 | all.booltype(l, range=c(3, 3)) 170 | 171 | min(l) 172 | min(b) 173 | 174 | sum(l) 175 | sum(b) 176 | 177 | summary(l) 178 | summary(b) 179 | summary.booltype(l) 180 | } 181 | \seealso{ 182 | \code{\link[=length]{length()}} 183 | } 184 | \author{ 185 | Jens Oehlschlägel 186 | } 187 | \keyword{classes} 188 | \keyword{logic} 189 | -------------------------------------------------------------------------------- /man/as.bit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R, R/generics.R 3 | \name{as.bit.NULL} 4 | \alias{as.bit.NULL} 5 | \alias{as.bit.bit} 6 | \alias{as.bit.logical} 7 | \alias{as.bit.integer} 8 | \alias{as.bit.double} 9 | \alias{as.bit.bitwhich} 10 | \alias{as.bit.which} 11 | \alias{as.bit.ri} 12 | \alias{as.bit} 13 | \title{Coercing to bit} 14 | \usage{ 15 | \method{as.bit}{`NULL`}(x, ...) 16 | 17 | \method{as.bit}{bit}(x, ...) 18 | 19 | \method{as.bit}{logical}(x, ...) 20 | 21 | \method{as.bit}{integer}(x, ...) 22 | 23 | \method{as.bit}{double}(x, ...) 24 | 25 | \method{as.bit}{bitwhich}(x, ...) 26 | 27 | \method{as.bit}{which}(x, length = attr(x, "maxindex"), ...) 28 | 29 | \method{as.bit}{ri}(x, ...) 30 | 31 | as.bit(x = NULL, ...) 32 | } 33 | \arguments{ 34 | \item{x}{an object of class \code{\link[=bit]{bit()}}, \code{\link[=logical]{logical()}}, 35 | \code{\link[=integer]{integer()}}, \code{\link[=bitwhich]{bitwhich()}} or an integer from 36 | \code{\link[=as.which]{as.which()}} or a boolean \code{\link[ff:vmode]{ff}}} 37 | 38 | \item{...}{further arguments} 39 | 40 | \item{length}{the length of the new bit vector} 41 | } 42 | \value{ 43 | \code{is.bit} returns FALSE or TRUE, \code{as.bit} returns a vector 44 | of class 'bit' 45 | } 46 | \description{ 47 | Coercing to bit vector 48 | } 49 | \details{ 50 | Coercing to bit is quite fast because we use a double loop that fixes each 51 | word in a processor register 52 | } 53 | \section{Methods (by class)}{ 54 | \itemize{ 55 | \item \code{as.bit(`NULL`)}: method to coerce to \code{\link[=bit]{bit()}} (zero length) from \code{\link{NULL}} 56 | 57 | \item \code{as.bit(bit)}: method to coerce to \code{\link[=bit]{bit()}} from \code{\link[=bit]{bit()}} 58 | 59 | \item \code{as.bit(logical)}: method to coerce to \code{\link[=bit]{bit()}} from \code{\link[=logical]{logical()}} 60 | 61 | \item \code{as.bit(integer)}: method to coerce to \code{\link[=bit]{bit()}} from 62 | \code{\link[=integer]{integer()}} (\code{0L} and \code{NA} become \code{FALSE}, 63 | everthing else becomes \code{TRUE}) 64 | 65 | \item \code{as.bit(double)}: method to coerce to \code{\link[=bit]{bit()}} from 66 | \code{\link[=double]{double()}} (\code{0} and \code{NA} become \code{FALSE}, everthing 67 | else becomes \code{TRUE}) 68 | 69 | \item \code{as.bit(bitwhich)}: method to coerce to \code{\link[=bit]{bit()}} from \code{\link[=bitwhich]{bitwhich()}} 70 | 71 | \item \code{as.bit(which)}: method to coerce to \code{\link[=bit]{bit()}} from \code{\link[=as.which]{which()}} 72 | 73 | \item \code{as.bit(ri)}: method to coerce to \code{\link[=bit]{bit()}} from \code{\link[=ri]{ri()}} 74 | 75 | }} 76 | \note{ 77 | Zero is coerced to FALSE, all other numbers including NA are coerced 78 | to TRUE. This differs from the NA-to-FALSE coercion in package ff and may 79 | change in the future. 80 | } 81 | \examples{ 82 | as.bit(c(0L, 1L, 2L, -2L, NA)) 83 | as.bit(c(0, 1, 2, -2, NA)) 84 | 85 | as.bit(c(FALSE, NA, TRUE)) 86 | 87 | } 88 | \seealso{ 89 | \code{\link{CoercionToStandard}}, \code{\link[=as.booltype]{as.booltype()}}, \code{\link[=as.bit]{as.bit()}}, 90 | \code{\link[=as.bitwhich]{as.bitwhich()}} , \code{\link[=as.which]{as.which()}}, \code{\link[=as.ri]{as.ri()}}, \code{\link[ff:as.hi]{ff::as.hi()}}, \code{\link[ff:as.ff]{ff::as.ff()}} 91 | } 92 | \author{ 93 | Jens Oehlschlägel 94 | } 95 | \keyword{classes} 96 | \keyword{logic} 97 | -------------------------------------------------------------------------------- /man/as.bitwhich.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R, R/generics.R 3 | \name{as.bitwhich.NULL} 4 | \alias{as.bitwhich.NULL} 5 | \alias{as.bitwhich.bitwhich} 6 | \alias{as.bitwhich.which} 7 | \alias{as.bitwhich.ri} 8 | \alias{as.bitwhich.integer} 9 | \alias{as.bitwhich.double} 10 | \alias{as.bitwhich.logical} 11 | \alias{as.bitwhich.bit} 12 | \alias{as.bitwhich} 13 | \title{Coercing to bitwhich} 14 | \usage{ 15 | \method{as.bitwhich}{`NULL`}(x, ...) 16 | 17 | \method{as.bitwhich}{bitwhich}(x, ...) 18 | 19 | \method{as.bitwhich}{which}(x, maxindex = attr(x, "maxindex"), ...) 20 | 21 | \method{as.bitwhich}{ri}(x, ...) 22 | 23 | \method{as.bitwhich}{integer}(x, poslength = NULL, ...) 24 | 25 | \method{as.bitwhich}{double}(x, poslength = NULL, ...) 26 | 27 | \method{as.bitwhich}{logical}(x, poslength = NULL, ...) 28 | 29 | \method{as.bitwhich}{bit}(x, range = NULL, poslength = NULL, ...) 30 | 31 | as.bitwhich(x = NULL, ...) 32 | } 33 | \arguments{ 34 | \item{x}{An object of class 'bitwhich', 'integer', 'logical' or 'bit' or an 35 | integer vector as resulting from 'which'} 36 | 37 | \item{...}{further arguments} 38 | 39 | \item{maxindex}{the length of the new bitwhich vector} 40 | 41 | \item{poslength}{the number of selected elements} 42 | 43 | \item{range}{a \code{\link[=ri]{ri()}} or an integer vector of length == 2 giving a 44 | range restriction for chunked processing} 45 | } 46 | \value{ 47 | a value of class \code{\link[=bitwhich]{bitwhich()}} 48 | } 49 | \description{ 50 | Functions to coerce to bitwhich 51 | } 52 | \section{Methods (by class)}{ 53 | \itemize{ 54 | \item \code{as.bitwhich(`NULL`)}: method to coerce to \code{\link[=bitwhich]{bitwhich()}} (zero length) from 55 | \code{\link{NULL}} 56 | 57 | \item \code{as.bitwhich(bitwhich)}: method to coerce to \code{\link[=bitwhich]{bitwhich()}} from \code{\link[=bitwhich]{bitwhich()}} 58 | 59 | \item \code{as.bitwhich(which)}: method to coerce to \code{\link[=bitwhich]{bitwhich()}} from \code{\link[=as.which]{which()}} 60 | 61 | \item \code{as.bitwhich(ri)}: method to coerce to \code{\link[=bitwhich]{bitwhich()}} from \code{\link[=ri]{ri()}} 62 | 63 | \item \code{as.bitwhich(integer)}: method to coerce to \code{\link[=bitwhich]{bitwhich()}} from 64 | \code{\link[=integer]{integer()}} (\code{0} and \code{NA} become \code{FALSE}, everthing 65 | else becomes \code{TRUE}) 66 | 67 | \item \code{as.bitwhich(double)}: method to coerce to \code{\link[=bitwhich]{bitwhich()}} from 68 | \code{\link[=double]{double()}} (\code{0} and \code{NA} become \code{FALSE}, everthing 69 | else becomes \code{TRUE}) 70 | 71 | \item \code{as.bitwhich(logical)}: method to coerce to \code{\link[=bitwhich]{bitwhich()}} from \code{\link[=logical]{logical()}} 72 | 73 | \item \code{as.bitwhich(bit)}: method to coerce to \code{\link[=bitwhich]{bitwhich()}} from \code{\link[=bit]{bit()}} 74 | 75 | }} 76 | \examples{ 77 | as.bitwhich(c(0L, 1L, 2L, -2L, NA)) 78 | as.bitwhich(c(0, 1, 2, -2, NA)) 79 | 80 | as.bitwhich(c(NA, NA, NA)) 81 | as.bitwhich(c(FALSE, FALSE, FALSE)) 82 | as.bitwhich(c(FALSE, FALSE, TRUE)) 83 | as.bitwhich(c(FALSE, TRUE, TRUE)) 84 | as.bitwhich(c(TRUE, TRUE, TRUE)) 85 | 86 | } 87 | \seealso{ 88 | \code{\link{CoercionToStandard}}, \code{\link[=as.booltype]{as.booltype()}}, \code{\link[=as.bit]{as.bit()}}, 89 | \code{\link[=as.bitwhich]{as.bitwhich()}} , \code{\link[=as.which]{as.which()}}, \code{\link[=as.ri]{as.ri()}}, \code{\link[ff:as.hi]{ff::as.hi()}}, \code{\link[ff:as.ff]{ff::as.ff()}} 90 | } 91 | \author{ 92 | Jens Oehlschlägel 93 | } 94 | \keyword{classes} 95 | \keyword{logic} 96 | -------------------------------------------------------------------------------- /man/as.booltype.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R, R/generics.R 3 | \name{as.booltype.default} 4 | \alias{as.booltype.default} 5 | \alias{as.booltype} 6 | \title{Coerce to booltype (generic)} 7 | \usage{ 8 | \method{as.booltype}{default}(x, booltype = "logical", ...) 9 | 10 | as.booltype(x, booltype, ...) 11 | } 12 | \arguments{ 13 | \item{x}{object to coerce} 14 | 15 | \item{booltype}{target \code{\link[=booltype]{booltype()}} given as integer or as character} 16 | 17 | \item{...}{further arguments} 18 | } 19 | \value{ 20 | \code{x} coerced to \code{booltype} 21 | } 22 | \description{ 23 | Coerce to booltype (generic) 24 | } 25 | \section{Methods (by class)}{ 26 | \itemize{ 27 | \item \code{as.booltype(default)}: default method for as.booltype 28 | 29 | }} 30 | \examples{ 31 | as.booltype(0:1) 32 | as.booltype(0:1, "logical") 33 | as.booltype(0:1, "bit") 34 | as.booltype(0:1, "bitwhich") 35 | as.booltype(0:1, "which", maxindex=2) 36 | as.booltype(0:1, "ri") 37 | } 38 | \seealso{ 39 | \code{\link{CoercionToStandard}}, \code{\link[=booltypes]{booltypes()}}, \code{\link[=booltype]{booltype()}}, 40 | \code{\link[=is.booltype]{is.booltype()}} 41 | } 42 | -------------------------------------------------------------------------------- /man/as.character.bit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{as.character.bit} 4 | \alias{as.character.bit} 5 | \title{Coerce bit to character} 6 | \usage{ 7 | \method{as.character}{bit}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{a \code{\link[=bit]{bit()}} vector} 11 | 12 | \item{...}{ignored} 13 | } 14 | \value{ 15 | a character vector of zeroes and ones 16 | } 17 | \description{ 18 | Coerce bit to character 19 | } 20 | \examples{ 21 | as.character(bit(12)) 22 | } 23 | -------------------------------------------------------------------------------- /man/as.character.bitwhich.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{as.character.bitwhich} 4 | \alias{as.character.bitwhich} 5 | \title{Coerce bitwhich to character} 6 | \usage{ 7 | \method{as.character}{bitwhich}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{a \code{\link[=bitwhich]{bitwhich()}} vector} 11 | 12 | \item{...}{ignored} 13 | } 14 | \value{ 15 | a character vector of zeroes and ones 16 | } 17 | \description{ 18 | Coerce bitwhich to character 19 | } 20 | \examples{ 21 | as.character(bitwhich(12)) 22 | } 23 | -------------------------------------------------------------------------------- /man/as.ri.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R, R/generics.R 3 | \name{as.ri.ri} 4 | \alias{as.ri.ri} 5 | \alias{as.ri.default} 6 | \alias{as.ri} 7 | \title{Coerce to ri} 8 | \usage{ 9 | \method{as.ri}{ri}(x, ...) 10 | 11 | \method{as.ri}{default}(x, ...) 12 | 13 | as.ri(x, ...) 14 | } 15 | \arguments{ 16 | \item{x}{object to coerce} 17 | 18 | \item{...}{further arguments} 19 | } 20 | \value{ 21 | an \code{\link[=ri]{ri()}} object 22 | } 23 | \description{ 24 | Coerce to ri 25 | } 26 | \section{Methods (by class)}{ 27 | \itemize{ 28 | \item \code{as.ri(ri)}: method to coerce \code{\link[=ri]{ri()}} to \code{\link[=ri]{ri()}} 29 | 30 | \item \code{as.ri(default)}: default method to coerce to \code{\link[=ri]{ri()}} 31 | 32 | }} 33 | \examples{ 34 | as.ri(c(FALSE, TRUE, FALSE, TRUE)) 35 | } 36 | \seealso{ 37 | \code{\link{CoercionToStandard}}, \code{\link[=as.booltype]{as.booltype()}}, \code{\link[=as.bit]{as.bit()}}, 38 | \code{\link[=as.bitwhich]{as.bitwhich()}} , \code{\link[=as.which]{as.which()}}, \code{\link[=as.ri]{as.ri()}}, \code{\link[ff:as.hi]{ff::as.hi()}}, \code{\link[ff:as.ff]{ff::as.ff()}} 39 | } 40 | \author{ 41 | Jens Oehlschlägel 42 | } 43 | \keyword{classes} 44 | \keyword{logic} 45 | -------------------------------------------------------------------------------- /man/as.which.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R, R/generics.R 3 | \name{as.which.which} 4 | \alias{as.which.which} 5 | \alias{as.which.NULL} 6 | \alias{as.which.numeric} 7 | \alias{as.which.integer} 8 | \alias{as.which.logical} 9 | \alias{as.which.ri} 10 | \alias{as.which.bit} 11 | \alias{as.which.bitwhich} 12 | \alias{as.which} 13 | \title{Coercion to (positive) integer positions} 14 | \usage{ 15 | \method{as.which}{which}(x, maxindex = NA_integer_, ...) 16 | 17 | \method{as.which}{`NULL`}(x, ...) 18 | 19 | \method{as.which}{numeric}(x, maxindex = NA_integer_, ...) 20 | 21 | \method{as.which}{integer}(x, maxindex = NA_integer_, is.unsorted = TRUE, has.dup = TRUE, ...) 22 | 23 | \method{as.which}{logical}(x, ...) 24 | 25 | \method{as.which}{ri}(x, ...) 26 | 27 | \method{as.which}{bit}(x, range = NULL, ...) 28 | 29 | \method{as.which}{bitwhich}(x, ...) 30 | 31 | as.which(x, ...) 32 | } 33 | \arguments{ 34 | \item{x}{an object of classes \code{\link[=bit]{bit()}}, \code{\link[=bitwhich]{bitwhich()}}, 35 | \code{\link[=ri]{ri()}} or something on which \code{\link[=which]{which()}} works} 36 | 37 | \item{maxindex}{the length of the boolean vector which is represented} 38 | 39 | \item{...}{further arguments (passed to \code{\link[=which]{which()}} for the 40 | default method, ignored otherwise)} 41 | 42 | \item{is.unsorted}{a logical scalar indicating whether the data may be unsorted} 43 | 44 | \item{has.dup}{a logical scalar indicating whether the data may have duplicates} 45 | 46 | \item{range}{a \code{\link[=ri]{ri()}} or an integer vector of length == 2 giving a 47 | range restriction for chunked processing} 48 | } 49 | \value{ 50 | a vector of class 'logical' or 'integer' 51 | } 52 | \description{ 53 | Coercing to something like the result of which \code{\link[=which]{which()}} 54 | } 55 | \details{ 56 | \code{as.which.bit} returns a vector of subscripts with class 'which' 57 | } 58 | \section{Methods (by class)}{ 59 | \itemize{ 60 | \item \code{as.which(which)}: method to coerce to \code{\link[=as.which]{which()}} from 61 | \code{\link[=as.which]{which()}} 62 | 63 | \item \code{as.which(`NULL`)}: method to coerce to zero length \code{\link[=as.which]{which()}} from 64 | \code{\link{NULL}} 65 | 66 | \item \code{as.which(numeric)}: method to coerce to \code{\link[=as.which]{which()}} from \code{\link[=numeric]{numeric()}} 67 | 68 | \item \code{as.which(integer)}: method to coerce to \code{\link[=as.which]{which()}} from \code{\link[=integer]{integer()}} 69 | 70 | \item \code{as.which(logical)}: method to coerce to \code{\link[=as.which]{which()}} from \code{\link[=logical]{logical()}} 71 | 72 | \item \code{as.which(ri)}: method to coerce to \code{\link[=as.which]{which()}} from \code{\link[=ri]{ri()}} 73 | 74 | \item \code{as.which(bit)}: method to coerce to \code{\link[=as.which]{which()}} from \code{\link[=bit]{bit()}} 75 | 76 | \item \code{as.which(bitwhich)}: method to coerce to \code{\link[=as.which]{which()}} from \code{\link[=bitwhich]{bitwhich()}} 77 | 78 | }} 79 | \examples{ 80 | 81 | r <- ri(5, 20, 100) 82 | x <- as.which(r) 83 | x 84 | 85 | stopifnot(identical(x, as.which(as.logical(r)))) 86 | stopifnot(identical(x, as.which(as.bitwhich(r)))) 87 | stopifnot(identical(x, as.which(as.bit(r)))) 88 | 89 | } 90 | \seealso{ 91 | \code{\link{CoercionToStandard}}, \code{\link[=as.booltype]{as.booltype()}}, \code{\link[=as.bit]{as.bit()}}, 92 | \code{\link[=as.bitwhich]{as.bitwhich()}} , \code{\link[=as.which]{as.which()}}, \code{\link[=as.ri]{as.ri()}}, \code{\link[ff:as.hi]{ff::as.hi()}}, \code{\link[ff:as.ff]{ff::as.ff()}} 93 | } 94 | \author{ 95 | Jens Oehlschlägel 96 | } 97 | \keyword{classes} 98 | \keyword{logic} 99 | -------------------------------------------------------------------------------- /man/bbatch.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/chunkutil.R 3 | \name{bbatch} 4 | \alias{bbatch} 5 | \title{Balanced Batch sizes} 6 | \usage{ 7 | bbatch(N, B) 8 | } 9 | \arguments{ 10 | \item{N}{total size in 0..integer_max} 11 | 12 | \item{B}{desired batch size in 1..integer_max} 13 | } 14 | \value{ 15 | a list with components: 16 | \itemize{ 17 | \item b: the batch size 18 | \item nb: the number of batches 19 | \item rb: the size of the rest 20 | } 21 | } 22 | \description{ 23 | \code{bbatch} calculates batch sizes in 1..N so that they have rather balanced 24 | sizes than very different sizes. 25 | } 26 | \details{ 27 | Tries to have \code{rb == 0} or \code{rb} as close to \code{b} as possible 28 | while guaranteeing that \code{rb < b && (b - rb) <= min(nb, b)} 29 | } 30 | \examples{ 31 | 32 | bbatch(100, 24) 33 | 34 | } 35 | \seealso{ 36 | \code{\link[=repfromto]{repfromto()}}, \code{\link[ff:ffapply]{ff::ffvecapply()}} 37 | } 38 | \author{ 39 | Jens Oehlschlägel 40 | } 41 | \keyword{IO} 42 | \keyword{data} 43 | -------------------------------------------------------------------------------- /man/bit-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit-package.R 3 | \name{bit-package} 4 | \alias{bit-package} 5 | \title{bit: Classes and methods for fast memory-efficient boolean selections} 6 | \description{ 7 | Provided are classes for boolean and skewed boolean vectors, fast boolean 8 | methods, fast unique and non-unique integer sorting, fast set operations on 9 | sorted and unsorted sets of integers, and foundations for ff (range indices, 10 | compression, chunked processing). 11 | } 12 | \details{ 13 | For details view the \code{vignette("bit-usage")} and \code{vignette("bit-performance")}. 14 | } 15 | -------------------------------------------------------------------------------- /man/bit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{bit} 4 | \alias{bit} 5 | \title{Create empty bit vector} 6 | \usage{ 7 | bit(length = 0L) 8 | } 9 | \arguments{ 10 | \item{length}{length in bits} 11 | } 12 | \value{ 13 | \code{bit} returns a vector of integer sufficiently long to store 'length' bits 14 | } 15 | \description{ 16 | Bit vectors are a boolean type wihout \code{NA} that requires by factor 32 less 17 | RAM than \code{\link[=logical]{logical()}}. 18 | For details on usage see \code{vignette("bit-usage")} and for details on 19 | performance see \code{vignette("bit-performance")}. 20 | } 21 | \examples{ 22 | bit(12) 23 | !bit(12) 24 | str(bit(128)) 25 | } 26 | \seealso{ 27 | \code{\link[=booltype]{booltype()}}, \code{\link[=bitwhich]{bitwhich()}}, \code{\link[=logical]{logical()}} 28 | } 29 | \keyword{classes} 30 | \keyword{logic} 31 | -------------------------------------------------------------------------------- /man/bit_in.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bitsort.R 3 | \name{bit_in} 4 | \alias{bit_in} 5 | \title{bit \%in\%} 6 | \usage{ 7 | bit_in(x, table, retFUN = as.bit) 8 | } 9 | \arguments{ 10 | \item{x}{an integer vector of values to be looked-up} 11 | 12 | \item{table}{an integer vector used as lookup-table} 13 | 14 | \item{retFUN}{a function that coerces \code{\link[=bit]{bit()}} and \code{\link[=logical]{logical()}} vectors} 15 | } 16 | \value{ 17 | a boolean vector coerced to \code{retFUN} 18 | } 19 | \description{ 20 | fast \code{\link[=match]{\%in\%}} for integers 21 | } 22 | \details{ 23 | determines the range of the integers and checks if the density justifies use 24 | of a bit vector; if yes, maps \code{x} or \code{table} -- whatever is smaller 25 | -- into a bit vector and searches the other of \code{table} or \code{x} in 26 | the it vector; if no, falls back to \code{\link[=match]{\%in\%}} 27 | } 28 | \examples{ 29 | bit_in(1:2, 2:3) 30 | bit_in(1:2, 2:3, retFUN=as.logical) 31 | } 32 | \seealso{ 33 | \code{\link[=match]{\%in\%}} 34 | } 35 | -------------------------------------------------------------------------------- /man/bit_init.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \docType{data} 4 | \name{.BITS} 5 | \alias{.BITS} 6 | \alias{bit_init} 7 | \alias{bit_done} 8 | \title{Initializing bit masks} 9 | \format{ 10 | An object of class \code{integer} of length 1. 11 | } 12 | \usage{ 13 | .BITS 14 | 15 | bit_init() 16 | 17 | bit_done() 18 | } 19 | \description{ 20 | Functions to allocate (and de-allocate) bit masks 21 | } 22 | \details{ 23 | The C-code operates with bit masks. The memory for these is allocated 24 | dynamically. \code{bit_init} is called by \code{\link[=.First.lib]{.First.lib()}} and 25 | \code{bit_done} is called by \code{\link[=.Last.lib]{.Last.lib()}}. You don't need to 26 | care about these under normal circumstances. 27 | } 28 | \examples{ 29 | 30 | bit_done() 31 | bit_init() 32 | 33 | } 34 | \seealso{ 35 | \code{\link[=bit]{bit()}} 36 | } 37 | \author{ 38 | Jens Oehlschlägel 39 | } 40 | \keyword{classes} 41 | \keyword{datasets} 42 | \keyword{logic} 43 | -------------------------------------------------------------------------------- /man/bit_rangediff.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bitsort.R 3 | \name{bit_rangediff} 4 | \alias{bit_rangediff} 5 | \title{bit range difference} 6 | \usage{ 7 | bit_rangediff(rx, y, revx = FALSE, revy = FALSE) 8 | } 9 | \arguments{ 10 | \item{rx}{range of integers given as \code{\link[=ri]{ri()}} or as a two-element \code{\link[=integer]{integer()}}} 11 | 12 | \item{y}{an integer vector of elements to exclude} 13 | 14 | \item{revx}{\code{FALSE} as is, \code{TRUE} to reverse the direction and sign of \code{rx}} 15 | 16 | \item{revy}{\code{FALSE} as is, \code{TRUE} to reverse the direction and sign of \code{y}} 17 | } 18 | \value{ 19 | an integer vector 20 | } 21 | \description{ 22 | Fast version of \code{setdiff(rx[1]:rx[2], y)}. 23 | } 24 | \details{ 25 | determines the range of the integers \code{y} and checks if the density justifies use 26 | of a bit vector; if yes, uses a bit vector for the set operation; if no, 27 | falls back to a quicksort and \code{\link[=merge_rangediff]{merge_rangediff()}} 28 | } 29 | \examples{ 30 | bit_rangediff(c(1L, 6L), c(3L, 4L)) 31 | bit_rangediff(c(6L, 1L), c(3L, 4L)) 32 | bit_rangediff(c(6L, 1L), c(3L, 4L), revx=TRUE) 33 | bit_rangediff(c(6L, 1L), c(3L, 4L), revx=TRUE, revy=TRUE) 34 | } 35 | \seealso{ 36 | \code{\link[=bit_setdiff]{bit_setdiff()}}, \code{\link[=merge_rangediff]{merge_rangediff()}} 37 | } 38 | -------------------------------------------------------------------------------- /man/bit_setops.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bitsort.R 3 | \name{bit_setops} 4 | \alias{bit_setops} 5 | \alias{bit_union} 6 | \alias{bit_intersect} 7 | \alias{bit_setdiff} 8 | \alias{bit_symdiff} 9 | \alias{bit_setequal} 10 | \title{bit set operations} 11 | \usage{ 12 | bit_union(x, y) 13 | 14 | bit_intersect(x, y) 15 | 16 | bit_setdiff(x, y) 17 | 18 | bit_symdiff(x, y) 19 | 20 | bit_setequal(x, y) 21 | } 22 | \arguments{ 23 | \item{x}{an integer vector} 24 | 25 | \item{y}{an integer vector} 26 | } 27 | \value{ 28 | an integer vector 29 | } 30 | \description{ 31 | Fast versions of \code{\link[=union]{union()}}, \code{\link[=intersect]{intersect()}}, 32 | \code{\link[=setdiff]{setdiff()}}, symmetric difference and \code{\link[=setequal]{setequal()}} 33 | for integers. 34 | } 35 | \details{ 36 | determines the range of the integers and checks if the density justifies use 37 | of a bit vector; if yes, uses a bit vector for finding duplicates; if no, 38 | falls back to \code{\link[=union]{union()}}, \code{\link[=intersect]{intersect()}}, 39 | \code{\link[=setdiff]{setdiff()}}, \code{union(setdiff(x, y), setdiff(y, x))} and \code{\link[=setequal]{setequal()}} 40 | } 41 | \section{Functions}{ 42 | \itemize{ 43 | \item \code{bit_union()}: union 44 | 45 | \item \code{bit_intersect()}: intersection 46 | 47 | \item \code{bit_setdiff()}: asymmetric difference 48 | 49 | \item \code{bit_symdiff()}: symmetricx difference 50 | 51 | \item \code{bit_setequal()}: equality 52 | 53 | }} 54 | \examples{ 55 | bit_union(1:2, 2:3) 56 | bit_intersect(1:2, 2:3) 57 | bit_setdiff(1:2, 2:3) 58 | bit_symdiff(1:2, 2:3) 59 | bit_setequal(1:2, 2:3) 60 | bit_setequal(1:2, 2:1) 61 | } 62 | \seealso{ 63 | \code{\link[=bit_in]{bit_in()}}, \code{\link[=bit_rangediff]{bit_rangediff()}} 64 | } 65 | -------------------------------------------------------------------------------- /man/bit_sort.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bitsort.R 3 | \name{bit_sort} 4 | \alias{bit_sort} 5 | \title{bit sort} 6 | \usage{ 7 | bit_sort(x, decreasing = FALSE, na.last = NA, has.dup = TRUE) 8 | } 9 | \arguments{ 10 | \item{x}{an integer vector} 11 | 12 | \item{decreasing}{(currently only \code{FALSE} is supported)} 13 | 14 | \item{na.last}{\code{NA} removes NAs, \code{FALSE} puts NAs at the beginning, 15 | \code{TRUE} puts NAs at the end} 16 | 17 | \item{has.dup}{TRUE (the default) assumes that \code{x} might have 18 | duplicates, set to \code{FALSE} if duplicates are impossible} 19 | } 20 | \value{ 21 | a sorted vector 22 | } 23 | \description{ 24 | fast sorting of integers 25 | } 26 | \details{ 27 | determines the range of the integers and checks if the density justifies use 28 | of a bit vector; if yes, sorts the first occurences of each integer in the 29 | range using a bit vector, sorts the rest and merges; if no, falls back to quicksort. 30 | } 31 | \examples{ 32 | bit_sort(c(2L, 1L, NA, NA, 1L, 2L)) 33 | bit_sort(c(2L, 1L, NA, NA, 1L, 2L), na.last=FALSE) 34 | bit_sort(c(2L, 1L, NA, NA, 1L, 2L), na.last=TRUE) 35 | 36 | \dontrun{ 37 | x <- sample(1e7, replace=TRUE) 38 | system.time(bit_sort(x)) 39 | system.time(sort(x)) 40 | } 41 | } 42 | \seealso{ 43 | \code{\link[=sort]{sort()}}, \code{\link[=ramsort]{ramsort()}}, 44 | \code{\link[=bit_sort_unique]{bit_sort_unique()}} 45 | } 46 | -------------------------------------------------------------------------------- /man/bit_sort_unique.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bitsort.R 3 | \name{bit_sort_unique} 4 | \alias{bit_sort_unique} 5 | \title{bit sort unique} 6 | \usage{ 7 | bit_sort_unique( 8 | x, 9 | decreasing = FALSE, 10 | na.last = NA, 11 | has.dup = TRUE, 12 | range_na = NULL 13 | ) 14 | } 15 | \arguments{ 16 | \item{x}{an integer vector} 17 | 18 | \item{decreasing}{\code{FALSE} (ascending) or \code{TRUE} (descending)} 19 | 20 | \item{na.last}{\code{NA} removes NAs, \code{FALSE} puts NAs at the beginning, \code{TRUE} puts NAs at 21 | the end} 22 | 23 | \item{has.dup}{TRUE (the default) assumes that \code{x} might have duplicates, set to 24 | \code{FALSE} if duplicates are impossible} 25 | 26 | \item{range_na}{\code{NULL} calls \code{\link[=range_na]{range_na()}}, optionally the result of \code{\link[=range_na]{range_na()}} can be 27 | given here to avoid calling it again} 28 | } 29 | \value{ 30 | a sorted unique integer vector 31 | } 32 | \description{ 33 | fast combination of \code{\link[=sort]{sort()}} and \code{\link[=unique]{unique()}} for integers 34 | } 35 | \details{ 36 | determines the range of the integers and checks if the density justifies use 37 | of a bit vector; if yes, creates the result using a bit vector; if no, falls back to 38 | \code{sort(unique())} 39 | } 40 | \examples{ 41 | bit_sort_unique(c(2L, 1L, NA, NA, 1L, 2L)) 42 | bit_sort_unique(c(2L, 1L, NA, NA, 1L, 2L), na.last=FALSE) 43 | bit_sort_unique(c(2L, 1L, NA, NA, 1L, 2L), na.last=TRUE) 44 | bit_sort_unique(c(2L, 1L, NA, NA, 1L, 2L), decreasing = TRUE) 45 | bit_sort_unique(c(2L, 1L, NA, NA, 1L, 2L), decreasing = TRUE, na.last=FALSE) 46 | bit_sort_unique(c(2L, 1L, NA, NA, 1L, 2L), decreasing = TRUE, na.last=TRUE) 47 | 48 | \dontrun{ 49 | x <- sample(1e7, replace=TRUE) 50 | system.time(bit_sort_unique(x)) 51 | system.time(sort(unique(x))) 52 | x <- sample(1e7) 53 | system.time(bit_sort_unique(x)) 54 | system.time(sort(x)) 55 | } 56 | } 57 | \seealso{ 58 | \code{\link[=sort]{sort()}}, \code{\link[=unique]{unique()}}, 59 | \code{\link[=bit_sort]{bit_sort()}}, \code{\link[=bit_unique]{bit_unique()}} 60 | } 61 | -------------------------------------------------------------------------------- /man/bit_unidup.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bitsort.R 3 | \name{bit_unidup} 4 | \alias{bit_unidup} 5 | \alias{bit_unique} 6 | \alias{bit_duplicated} 7 | \alias{bit_anyDuplicated} 8 | \alias{bit_sumDuplicated} 9 | \title{bit unique and duplicated} 10 | \usage{ 11 | bit_unique(x, na.rm = NA, range_na = NULL) 12 | 13 | bit_duplicated(x, na.rm = NA, range_na = NULL, retFUN = as.bit) 14 | 15 | bit_anyDuplicated(x, na.rm = NA, range_na = NULL) 16 | 17 | bit_sumDuplicated(x, na.rm = NA, range_na = NULL) 18 | } 19 | \arguments{ 20 | \item{x}{an integer vector} 21 | 22 | \item{na.rm}{\code{NA} treats NAs like other integers, \code{TRUE} treats 23 | \emph{all} NAs as duplicates, \code{FALSE} treats \emph{no} NAs as 24 | duplicates} 25 | 26 | \item{range_na}{\code{NULL} calls \code{\link[=range_na]{range_na()}}, optionally the result of \code{\link[=range_na]{range_na()}} can be 27 | given here to avoid calling it again} 28 | 29 | \item{retFUN}{a function that coerces \code{\link[=bit]{bit()}} and \code{\link[=logical]{logical()}} vectors} 30 | } 31 | \value{ 32 | \itemize{ 33 | \item \code{bit_unique} returns a vector of unique integers, 34 | \item \code{bit_duplicated} returns a boolean vector coerced to \code{retFUN}, 35 | \item \code{bit_anyDuplicated} returns the position of the first duplicate (or zero if no 36 | duplicates) 37 | \item \code{bit_sumDuplicated} returns the number of duplicated values (as.integer) 38 | } 39 | } 40 | \description{ 41 | Fast versions of \code{\link[=unique]{unique()}}, \code{\link[=duplicated]{duplicated()}} , 42 | \code{\link[=anyDuplicated]{anyDuplicated()}} and \code{sum(duplicated(x))} for integers. 43 | } 44 | \details{ 45 | determines the range of the integers and checks if the density justifies use 46 | of a bit vector; if yes, uses a bit vector for finding duplicates; if no, 47 | falls back to \code{\link[=unique]{unique()}}, \code{\link[=duplicated]{duplicated()}}, \code{\link[=anyDuplicated]{anyDuplicated()}} and \code{sum(duplicated(x))} 48 | } 49 | \section{Functions}{ 50 | \itemize{ 51 | \item \code{bit_unique()}: extracts unique elements 52 | 53 | \item \code{bit_duplicated()}: determines duplicate elements 54 | 55 | \item \code{bit_anyDuplicated()}: checks for existence of duplicate elements 56 | 57 | \item \code{bit_sumDuplicated()}: counts duplicate elements 58 | 59 | }} 60 | \examples{ 61 | bit_unique(c(2L, 1L, NA, NA, 1L, 2L)) 62 | bit_unique(c(2L, 1L, NA, NA, 1L, 2L), na.rm=FALSE) 63 | bit_unique(c(2L, 1L, NA, NA, 1L, 2L), na.rm=TRUE) 64 | 65 | bit_duplicated(c(2L, 1L, NA, NA, 1L, 2L)) 66 | bit_duplicated(c(2L, 1L, NA, NA, 1L, 2L), na.rm=FALSE) 67 | bit_duplicated(c(2L, 1L, NA, NA, 1L, 2L), na.rm=TRUE) 68 | 69 | bit_anyDuplicated(c(2L, 1L, NA, NA, 1L, 2L)) 70 | bit_anyDuplicated(c(2L, 1L, NA, NA, 1L, 2L), na.rm=FALSE) 71 | bit_anyDuplicated(c(2L, 1L, NA, NA, 1L, 2L), na.rm=TRUE) 72 | 73 | bit_sumDuplicated(c(2L, 1L, NA, NA, 1L, 2L)) 74 | bit_sumDuplicated(c(2L, 1L, NA, NA, 1L, 2L), na.rm=FALSE) 75 | bit_sumDuplicated(c(2L, 1L, NA, NA, 1L, 2L), na.rm=TRUE) 76 | } 77 | \seealso{ 78 | \code{\link[=bit_sort_unique]{bit_sort_unique()}} 79 | } 80 | -------------------------------------------------------------------------------- /man/bitsort.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bitsort.R 3 | \name{bitsort} 4 | \alias{bitsort} 5 | \title{Low-level sorting: bit sort} 6 | \usage{ 7 | bitsort(x, na.last = NA, depth = 1) 8 | } 9 | \arguments{ 10 | \item{x}{an integer vector} 11 | 12 | \item{na.last}{\code{NA} removes NAs, \code{FALSE} puts NAs at the beginning, 13 | \code{TRUE} puts NAs at the end} 14 | 15 | \item{depth}{an integer scalar giving the number of bit-passed before switching to 16 | quicksort} 17 | } 18 | \value{ 19 | a sorted vector 20 | } 21 | \description{ 22 | In one pass over the vector \code{NA}s are handled according to parameter 23 | \code{na.last} by \code{\link[=range_sortna]{range_sortna()}}, then, if the vector is unsorted, 24 | bit sort is invoked. 25 | } 26 | \examples{ 27 | bitsort(c(2L, 0L, 1L, NA, 2L)) 28 | bitsort(c(2L, 0L, 1L, NA, 2L), na.last=TRUE) 29 | bitsort(c(2L, 0L, 1L, NA, 2L), na.last=FALSE) 30 | } 31 | -------------------------------------------------------------------------------- /man/bitwhich.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{bitwhich} 4 | \alias{bitwhich} 5 | \title{Create bitwhich vector (skewed boolean)} 6 | \usage{ 7 | bitwhich( 8 | maxindex = 0L, 9 | x = NULL, 10 | xempty = FALSE, 11 | poslength = NULL, 12 | is.unsorted = TRUE, 13 | has.dup = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{maxindex}{length of the vector} 18 | 19 | \item{x}{Information about which positions are \code{FALSE} or \code{TRUE}: either \code{logical()} or 20 | \code{TRUE} or \code{FALSE} or a integer vector of positive or of negative subscripts.} 21 | 22 | \item{xempty}{what to assume about parameter \code{x} if \code{x=integer(0)}, typically \code{TRUE} 23 | or \code{FALSE}.} 24 | 25 | \item{poslength}{tuning: \code{poslength} is calculated automatically, you can give 26 | \code{poslength} explicitly, in this case it must be correct and \code{x} must be sorted and 27 | not have duplicates.} 28 | 29 | \item{is.unsorted}{tuning: FALSE implies that \code{x} is already sorted and sorting 30 | is skipped} 31 | 32 | \item{has.dup}{tuning: FALSE implies that \code{x} has no duplicates} 33 | } 34 | \value{ 35 | an object of class 'bitwhich' carrying two attributes 36 | \itemize{ 37 | \item maxindex: see above 38 | \item poslength: see above 39 | } 40 | } 41 | \description{ 42 | A bitwhich object represents a boolean filter like a \code{\link[=bit]{bit()}} object (NAs are not 43 | allowed) but uses a sparse representation suitable for very skewed (asymmetric) 44 | selections. Three extreme cases are represented with logical values, no length via 45 | \code{logical()}, all \code{TRUE} with \code{TRUE} and all \code{FALSE} with \code{FALSE}. All other 46 | selections are represented with positive or negative integers, whatever is shorter. 47 | This needs less RAM compared to \code{\link[=logical]{logical()}} (and often less than \code{\link[=bit]{bit()}} or 48 | \code{\link[=as.which]{which()}}). Logical operations are fast if the selection is asymmetric 49 | (only few or almost all selected). 50 | } 51 | \examples{ 52 | bitwhich() 53 | bitwhich(12) 54 | bitwhich(12, x=TRUE) 55 | bitwhich(12, x=3) 56 | bitwhich(12, x=-3) 57 | bitwhich(12, x=integer()) 58 | bitwhich(12, x=integer(), xempty=TRUE) 59 | } 60 | \seealso{ 61 | \code{\link[=bitwhich_representation]{bitwhich_representation()}}, \code{\link[=as.bitwhich]{as.bitwhich()}}, \code{\link[=bit]{bit()}} 62 | } 63 | -------------------------------------------------------------------------------- /man/bitwhich_representation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{bitwhich_representation} 4 | \alias{bitwhich_representation} 5 | \title{Diagnose representation of bitwhich} 6 | \usage{ 7 | bitwhich_representation(x) 8 | } 9 | \arguments{ 10 | \item{x}{a \code{\link[=bitwhich]{bitwhich()}} object} 11 | } 12 | \value{ 13 | a scalar, one of \code{logical()}, \code{FALSE}, \code{TRUE}, \code{-1} or \code{1} 14 | } 15 | \description{ 16 | Diagnose representation of bitwhich 17 | } 18 | \examples{ 19 | bitwhich_representation(bitwhich()) 20 | bitwhich_representation(bitwhich(12, FALSE)) 21 | bitwhich_representation(bitwhich(12, TRUE)) 22 | bitwhich_representation(bitwhich(12, -3)) 23 | bitwhich_representation(bitwhich(12, 3)) 24 | } 25 | -------------------------------------------------------------------------------- /man/booltype.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{booltype} 4 | \alias{booltype} 5 | \title{Diagnosing boolean types} 6 | \usage{ 7 | booltype(x) 8 | } 9 | \arguments{ 10 | \item{x}{an R object} 11 | } 12 | \value{ 13 | one scalar element of \code{\link[=booltypes]{booltypes()}} in case of 'nobool' it carries a name 14 | attribute with the data type. 15 | } 16 | \description{ 17 | Specific methods for \code{booltype} are required, where non-unary methods can combine 18 | multiple bollean types, particularly boolean binary operators. 19 | } 20 | \details{ 21 | Function \code{booltype} returns the boolean type of its argument. 22 | There are currently six boolean types, \code{booltypes} is an \code{\link[=ordered]{ordered()}} vector with the 23 | following ordinal \code{\link[=levels]{levels()}}: 24 | \itemize{ 25 | \item nobool: non-boolean type 26 | \item \code{\link[=logical]{logical()}}: for representing any boolean data including \code{NA} 27 | \item \code{\link[=bit]{bit()}}: for representing dense boolean data 28 | \item \code{\link[=bitwhich]{bitwhich()}}: for representing sparse (skewed) boolean data 29 | \item \code{\link[=which]{which()}}: for representing sparse boolean data with few `TRUE 30 | \item \code{\link[=ri]{ri()}}: range-indexing, for representing sparse boolean data with a single range of 31 | \code{TRUE} 32 | } 33 | } 34 | \note{ 35 | do not rely on the internal integer codes of these levels, we might add-in 36 | \code{\link[ff:hi]{hi}} later 37 | } 38 | \examples{ 39 | unname(booltypes) 40 | str(booltypes) 41 | sapply( 42 | list(double(), integer(), logical(), bit(), bitwhich(), as.which(), ri(1, 2, 3)), 43 | booltype 44 | ) 45 | } 46 | \seealso{ 47 | \code{\link[=booltypes]{booltypes()}}, \code{\link[=is.booltype]{is.booltype()}}, \code{\link[=as.booltype]{as.booltype()}} 48 | } 49 | -------------------------------------------------------------------------------- /man/booltypes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \docType{data} 4 | \name{booltypes} 5 | \alias{booltypes} 6 | \title{Boolean types} 7 | \format{ 8 | An object of class \code{ordered} (inherits from \code{factor}) of length 6. 9 | } 10 | \usage{ 11 | booltypes 12 | } 13 | \description{ 14 | The \code{\link[=ordered]{ordered()}} factor \code{booltypes} ranks the boolean types. 15 | } 16 | \details{ 17 | There are currently six boolean types, \code{booltypes} is an \code{\link[=ordered]{ordered()}} vector with the 18 | following ordinal \code{\link[=levels]{levels()}}: 19 | \itemize{ 20 | \item nobool: non-boolean type 21 | \item \code{\link[=logical]{logical()}}: for representing any boolean data including \code{NA} 22 | \item \code{\link[=bit]{bit()}}: for representing dense boolean data 23 | \item \code{\link[=bitwhich]{bitwhich()}}: for representing sparse (skewed) boolean data 24 | \item \code{\link[=which]{which()}}: for representing sparse boolean data with few `TRUE 25 | \item \code{\link[=ri]{ri()}}: range-indexing, for representing sparse boolean data with a single range of 26 | \code{TRUE} 27 | } 28 | 29 | \code{booltypes} has a \code{\link[=names]{names()}} attribute such that elements can be selected by name. 30 | } 31 | \note{ 32 | do not rely on the internal integer codes of these levels, we might add-in 33 | \code{\link[ff:hi]{hi}} later 34 | } 35 | \seealso{ 36 | \code{\link[=booltype]{booltype()}}, \code{\link[=is.booltype]{is.booltype()}}, \code{\link[=as.booltype]{as.booltype()}} 37 | } 38 | \keyword{datasets} 39 | -------------------------------------------------------------------------------- /man/c.booltype.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{c.booltype} 4 | \alias{c.booltype} 5 | \alias{c.bit} 6 | \alias{c.bitwhich} 7 | \title{Concatenating booltype vectors} 8 | \usage{ 9 | \method{c}{booltype}(...) 10 | 11 | \method{c}{bit}(...) 12 | 13 | \method{c}{bitwhich}(...) 14 | } 15 | \arguments{ 16 | \item{...}{\code{\link[=booltype]{booltype()}} vectors} 17 | } 18 | \value{ 19 | a vector with the lowest input \code{\link[=booltype]{booltype()}} (but not lower than\code{\link[=logical]{logical()}}) 20 | } 21 | \description{ 22 | Creating new boolean vectors by concatenating boolean vectors 23 | } 24 | \examples{ 25 | c(bit(4), !bit(4)) 26 | c(bit(4), !bitwhich(4)) 27 | c(bitwhich(4), !bit(4)) 28 | c(ri(1, 2, 4), !bit(4)) 29 | c(bit(4), !logical(4)) 30 | message("logical in first argument does not dispatch: c(logical(4), bit(4))") 31 | c.booltype(logical(4), !bit(4)) 32 | 33 | } 34 | \seealso{ 35 | \code{\link[=c]{c()}}, \code{\link[=bit]{bit()}} , \code{\link[=bitwhich]{bitwhich()}}, , \code{\link[=which]{which()}} 36 | } 37 | \author{ 38 | Jens Oehlschlägel 39 | } 40 | \keyword{classes} 41 | \keyword{logic} 42 | -------------------------------------------------------------------------------- /man/chunk.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/chunkutil.R 3 | \name{chunk} 4 | \alias{chunk} 5 | \alias{chunk.default} 6 | \title{Methods for chunked range index} 7 | \usage{ 8 | chunk(x = NULL, ...) 9 | 10 | \method{chunk}{default}(x = NULL, ..., RECORDBYTES = NULL, BATCHBYTES = NULL) 11 | } 12 | \arguments{ 13 | \item{x}{the object along we want chunks} 14 | 15 | \item{...}{further arguments passed to \code{\link[=chunks]{chunks()}}} 16 | 17 | \item{RECORDBYTES}{integer scalar representing the bytes needed to process a single 18 | element of the boolean vector (default 4 bytes for logical)} 19 | 20 | \item{BATCHBYTES}{integer scalar limiting the number of bytes to be processed in one 21 | chunk, default from \code{getOption("ffbatchbytes")} if not null, otherwise 16777216} 22 | } 23 | \value{ 24 | returns a named list of \code{\link[=ri]{ri()}} objects 25 | representing chunks of subscripts 26 | } 27 | \description{ 28 | Calls \code{\link[=chunks]{chunks()}} to create a sequence of range indexes along the object which causes 29 | the method dispatch. 30 | } 31 | \details{ 32 | \code{chunk} is generic, the default method is described here, other methods 33 | that automatically consider RAM needs are provided with package 'ff', see 34 | for example \code{\link[ff:chunk.ffdf]{ff::chunk.ffdf()}} 35 | } 36 | \section{Methods (by class)}{ 37 | \itemize{ 38 | \item \code{chunk(default)}: default vector method 39 | 40 | }} 41 | \section{available methods}{ 42 | \code{chunk.default}, \code{\link[ff:chunk.ffdf]{ff::chunk.ff_vector()}}, 43 | \code{\link[ff:chunk.ffdf]{ff::chunk.ffdf()}} 44 | } 45 | 46 | \examples{ 47 | chunk(complex(1e7)) 48 | chunk(raw(1e7)) 49 | chunk(raw(1e7), length=3) 50 | 51 | chunks(1, 10, 3) 52 | # no longer do 53 | chunk(1, 100, 10) 54 | # but for bckward compatibility this works 55 | chunk(from=1, to=100, by=10) 56 | 57 | } 58 | \seealso{ 59 | \code{\link[=chunks]{chunks()}}, \code{\link[=ri]{ri()}}, \code{\link[base:seq]{seq()}}, \code{\link[=bbatch]{bbatch()}} 60 | } 61 | \author{ 62 | Jens Oehlschlägel 63 | } 64 | \keyword{data} 65 | -------------------------------------------------------------------------------- /man/chunks.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/chunkutil.R 3 | \name{chunks} 4 | \alias{chunks} 5 | \title{Function for chunked range index} 6 | \usage{ 7 | chunks( 8 | from = NULL, 9 | to = NULL, 10 | by = NULL, 11 | length.out = NULL, 12 | along.with = NULL, 13 | overlap = 0L, 14 | method = c("bbatch", "seq"), 15 | maxindex = NA 16 | ) 17 | } 18 | \arguments{ 19 | \item{from}{the starting value of the sequence.} 20 | 21 | \item{to}{the (maximal) end value of the sequence.} 22 | 23 | \item{by}{increment of the sequence} 24 | 25 | \item{length.out}{desired length of the sequence.} 26 | 27 | \item{along.with}{take the length from the length of this argument.} 28 | 29 | \item{overlap}{number of values to overlap (will lower the starting value of 30 | the sequence, the first range becomes smaller} 31 | 32 | \item{method}{default 'bbatch' will try to balance the chunk size, see 33 | \code{\link[=bbatch]{bbatch()}}, 'seq' will create chunks like \code{\link[base:seq]{seq()}}} 34 | 35 | \item{maxindex}{passed to \code{\link[=ri]{ri()}}} 36 | } 37 | \value{ 38 | returns a named list of \code{\link[=ri]{ri()}} objects 39 | representing chunks of subscripts 40 | } 41 | \description{ 42 | creates a sequence of range indexes using a syntax not completely unlike 43 | 'seq' 44 | } 45 | \examples{ 46 | 47 | chunks(1, 100, by=30) 48 | chunks(1, 100, by=30, method="seq") 49 | \dontrun{ 50 | require(foreach) 51 | m <- 10000 52 | k <- 1000 53 | n <- m*k 54 | message("Four ways to loop from 1 to n. Slowest foreach to fastest chunk is 1700:1 55 | on a dual core notebook with 3GB RAM\n") 56 | z <- 0L; 57 | print(k*system.time({it <- icount(m); foreach (i = it) \%do\% { z <- i; NULL }})) 58 | z 59 | 60 | z <- 0L 61 | print(system.time({i <- 0L; while (i < n) {i <- i + 1L; z <- i}})) 62 | z 63 | 64 | z <- 0L 65 | print(system.time(for (i in 1:n) z <- i)) 66 | z 67 | 68 | z <- 0L; n <- m*k; 69 | print(system.time(for (ch in chunks(1, n, by=m)) {for (i in ch[1]:ch[2]) z <- i})) 70 | z 71 | 72 | message("Seven ways to calculate sum(1:n). 73 | Slowest foreach to fastest chunk is 61000:1 on a dual core notebook with 3GB RAM\n") 74 | print(k*system.time({it <- icount(m); foreach (i = it, .combine="+") \%do\% { i }})) 75 | 76 | z <- 0; 77 | print(k*system.time({it <- icount(m); foreach (i = it) \%do\% { z <- z + i; NULL }})) 78 | z 79 | 80 | z <- 0; print(system.time({i <- 0L;while (i < n) {i <- i + 1L; z <- z + i}})); z 81 | 82 | z <- 0; print(system.time(for (i in 1:n) z <- z + i)); z 83 | 84 | print(system.time(sum(as.double(1:n)))) 85 | 86 | z <- 0; n <- m*k 87 | print(system.time(for (ch in chunks(1, n, by=m)) {for (i in ch[1]:ch[2]) z <- z + i})) 88 | z 89 | 90 | z <- 0; n <- m*k 91 | print(system.time(for (ch in chunks(1, n, by=m)) {z <- z + sum(as.double(ch[1]:ch[2]))})) 92 | z 93 | } 94 | 95 | } 96 | \seealso{ 97 | generic \code{\link[=chunk]{chunk()}}, \code{\link[=ri]{ri()}}, \code{\link[base:seq]{seq()}}, \code{\link[=bbatch]{bbatch()}} 98 | } 99 | \author{ 100 | Jens Oehlschlägel 101 | } 102 | \keyword{data} 103 | -------------------------------------------------------------------------------- /man/clone.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/clone.R 3 | \name{clone} 4 | \alias{clone} 5 | \alias{clone.default} 6 | \title{Cloning ff and ram objects} 7 | \usage{ 8 | clone(x, ...) 9 | 10 | \method{clone}{default}(x, ...) 11 | } 12 | \arguments{ 13 | \item{x}{\code{x} an R object} 14 | 15 | \item{...}{further arguments to the generic} 16 | } 17 | \value{ 18 | an object that is a deep copy of x 19 | } 20 | \description{ 21 | \code{clone} physically duplicates objects and can additionally change 22 | some features, e.g. length. 23 | } 24 | \details{ 25 | \code{clone} is generic. \code{clone.default} handles ram objects. 26 | Further methods are provided in package 'ff'. 27 | \code{still.identical} returns TRUE if the two atomic arguments still 28 | point to the same memory. 29 | } 30 | \section{Methods (by class)}{ 31 | \itemize{ 32 | \item \code{clone(default)}: default method uses R's C-API 'duplicate()' 33 | 34 | }} 35 | \examples{ 36 | 37 | x <- 1:12 38 | y <- x 39 | still.identical(x, y) 40 | y[1] <- y[1] 41 | still.identical(x, y) 42 | y <- clone(x) 43 | still.identical(x, y) 44 | rm(x, y); gc() 45 | 46 | } 47 | \seealso{ 48 | \code{clone.ff}, \code{\link[=copy_vector]{copy_vector()}} 49 | } 50 | \author{ 51 | Jens Oehlschlägel 52 | } 53 | \keyword{IO} 54 | \keyword{data} 55 | -------------------------------------------------------------------------------- /man/copy_vector.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/integerutil.R 3 | \name{copy_vector} 4 | \alias{copy_vector} 5 | \title{Copy atomic R vector} 6 | \usage{ 7 | copy_vector(x, revx = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{an R vector} 11 | 12 | \item{revx}{default \code{FALSE}, set to \code{TRUE} to reverse the elements in 'x'} 13 | } 14 | \value{ 15 | copied R vector 16 | } 17 | \description{ 18 | Creates a true copy of the underlying C-vector -- dropping all attributes -- and 19 | optionally reverses the direction of the elements. 20 | } 21 | \details{ 22 | This can be substantially faster than \code{duplicate(as.vector(unclass(x)))} 23 | } 24 | \examples{ 25 | x <- factor(letters) 26 | y <- x 27 | z <- copy_vector(x) 28 | still.identical(x, y) 29 | still.identical(x, z) 30 | str(x) 31 | str(y) 32 | str(z) 33 | } 34 | \seealso{ 35 | \code{\link[=clone]{clone()}}, \code{\link[=still.identical]{still.identical()}}, \code{\link[=reverse_vector]{reverse_vector()}} 36 | } 37 | -------------------------------------------------------------------------------- /man/countsort.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bitsort.R 3 | \name{countsort} 4 | \alias{countsort} 5 | \title{Low-level sorting: counting sort} 6 | \usage{ 7 | countsort(x, na.last = NA) 8 | } 9 | \arguments{ 10 | \item{x}{an integer vector} 11 | 12 | \item{na.last}{\code{NA} removes NAs, \code{FALSE} puts NAs at the beginning, 13 | \code{TRUE} puts NAs at the end} 14 | } 15 | \value{ 16 | a sorted vector 17 | } 18 | \description{ 19 | In one pass over the vector \code{NA}s are handled according to parameter 20 | \code{na.last} by \code{\link[=range_sortna]{range_sortna()}}, then, if the vector is unsorted, 21 | counting sort is invoked. 22 | } 23 | \examples{ 24 | countsort(c(2L, 0L, 1L, NA, 2L)) 25 | countsort(c(2L, 0L, 1L, NA, 2L), na.last=TRUE) 26 | countsort(c(2L, 0L, 1L, NA, 2L), na.last=FALSE) 27 | } 28 | -------------------------------------------------------------------------------- /man/firstNA.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/integerutil.R 3 | \name{firstNA} 4 | \alias{firstNA} 5 | \title{Position of first NA} 6 | \usage{ 7 | firstNA(x) 8 | } 9 | \arguments{ 10 | \item{x}{an R vector} 11 | } 12 | \value{ 13 | a reversed vector 14 | } 15 | \description{ 16 | This is substantially faster than \code{which.max(is.na(x))} 17 | } 18 | \examples{ 19 | x <- c(FALSE, NA, TRUE) 20 | firstNA(x) 21 | reverse_vector(x) 22 | \dontrun{ 23 | x <- 1:1e7 24 | system.time(rev(x)) 25 | system.time(reverse_vector(x)) 26 | } 27 | } 28 | \seealso{ 29 | \code{\link[=which.max]{which.max()}}, \code{\link[=is.na]{is.na()}}, \code{\link[=anyNA]{anyNA()}}, \code{\link[=anyDuplicated]{anyDuplicated()}}, \code{\link[=bit_anyDuplicated]{bit_anyDuplicated()}} 30 | } 31 | -------------------------------------------------------------------------------- /man/get_length.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/integerutil.R 3 | \name{get_length} 4 | \alias{get_length} 5 | \title{Get C length of a vector} 6 | \usage{ 7 | get_length(x) 8 | } 9 | \arguments{ 10 | \item{x}{a vector} 11 | } 12 | \value{ 13 | integer scalar 14 | } 15 | \description{ 16 | Gets C length of a vector ignoring any length-methods dispatched by classes 17 | } 18 | \details{ 19 | Queries the vector length using C-macro \code{LENGTH}, this can be substantially faster than 20 | \code{length(unclass(x))} 21 | } 22 | \examples{ 23 | length(bit(12)) 24 | get_length(bit(12)) 25 | } 26 | -------------------------------------------------------------------------------- /man/getsetattr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/attrutil.R 3 | \name{getsetattr} 4 | \alias{getsetattr} 5 | \alias{setattr} 6 | \alias{setattributes} 7 | \title{Attribute setting by reference} 8 | \usage{ 9 | getsetattr(x, which, value) 10 | 11 | setattr(x, which, value) 12 | 13 | setattributes(x, attributes) 14 | } 15 | \arguments{ 16 | \item{x}{an R object} 17 | 18 | \item{which}{name of the attribute} 19 | 20 | \item{value}{value of the attribute, use NULL to remove this attribute} 21 | 22 | \item{attributes}{a named list of attribute values} 23 | } 24 | \value{ 25 | invisible(), we do not return the changed object to remind you of 26 | the fact that this function is called for its side-effect of changing its 27 | input object. 28 | } 29 | \description{ 30 | Function \code{setattr} sets a singe attribute and function 31 | \code{setattributes} sets a list of attributes. 32 | } 33 | \details{ 34 | The attributes of 'x' are changed in place without copying x. function 35 | \code{setattributes} does only change the named attributes, it does not 36 | delete the non-names attributes like \code{\link[=attributes]{attributes()}} does. 37 | } 38 | \examples{ 39 | 40 | x <- as.single(runif(10)) 41 | attr(x, "Csingle") 42 | 43 | f <- function(x) attr(x, "Csingle") <- NULL 44 | g <- function(x) setattr(x, "Csingle", NULL) 45 | 46 | f(x) 47 | x 48 | g(x) 49 | x 50 | 51 | \dontrun{ 52 | 53 | # restart R 54 | library(bit) 55 | 56 | mysingle <- function(length = 0) { 57 | ret <- double(length) 58 | setattr(ret, "Csingle", TRUE) 59 | ret 60 | } 61 | 62 | # show that mysinge gives exactly the same result as single 63 | identical(single(10), mysingle(10)) 64 | 65 | # look at the speedup and memory-savings of mysingle compared to single 66 | system.time(mysingle(1e7)) 67 | memory.size(max=TRUE) 68 | system.time(single(1e7)) 69 | memory.size(max=TRUE) 70 | 71 | # look at the memory limits 72 | # on my win32 machine the first line fails 73 | # because of not enough RAM, the second works 74 | x <- single(1e8) 75 | x <- mysingle(1e8) 76 | 77 | # .g. performance with factors 78 | x <- rep(factor(letters), length.out=1e7) 79 | x[1:10] 80 | # look how fast one can do this 81 | system.time(setattr(x, "levels", rev(letters))) 82 | x[1:10] 83 | # look at the performance loss in time caused by the non-needed copying 84 | system.time(levels(x) <- letters) 85 | x[1:10] 86 | 87 | 88 | # restart R 89 | library(bit) 90 | 91 | simplefactor <- function(n) { 92 | factor(rep(1:2, length.out=n)) 93 | } 94 | 95 | mysimplefactor <- function(n) { 96 | ret <- rep(1:2, length.out=n) 97 | setattr(ret, "levels", as.character(1:2)) 98 | setattr(ret, "class", "factor") 99 | ret 100 | } 101 | 102 | identical(simplefactor(10), mysimplefactor(10)) 103 | 104 | system.time(x <- mysimplefactor(1e7)) 105 | memory.size(max=TRUE) 106 | system.time(setattr(x, "levels", c("a", "b"))) 107 | memory.size(max=TRUE) 108 | x[1:4] 109 | memory.size(max=TRUE) 110 | rm(x) 111 | gc() 112 | 113 | system.time(x <- simplefactor(1e7)) 114 | memory.size(max=TRUE) 115 | system.time(levels(x) <- c("x", "y")) 116 | memory.size(max=TRUE) 117 | x[1:4] 118 | memory.size(max=TRUE) 119 | rm(x) 120 | gc() 121 | 122 | } 123 | 124 | 125 | } 126 | \references{ 127 | Writing R extensions -- System and foreign language interfaces 128 | -- Handling R objects in C -- Attributes (Version 2.11.1 (2010-06-03 ) R 129 | Development) 130 | } 131 | \seealso{ 132 | \code{\link[=attr]{attr()}} \code{\link[=unattr]{unattr()}} 133 | } 134 | \author{ 135 | Jens Oehlschlägel 136 | } 137 | \keyword{attributes} 138 | -------------------------------------------------------------------------------- /man/in.bitwhich.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{in.bitwhich} 4 | \alias{in.bitwhich} 5 | \title{Check existence of integers in table} 6 | \usage{ 7 | in.bitwhich(x, table, is.unsorted = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{a vector of integer} 11 | 12 | \item{table}{a \code{\link[=bitwhich]{bitwhich()}} object or a vector of integer} 13 | 14 | \item{is.unsorted}{logical telling the function whether the table is (un)sorted. With 15 | the default \code{NULL} \code{FALSE} is assumed for \code{\link[=bitwhich]{bitwhich()}} tables, otherwise \code{TRUE}} 16 | } 17 | \value{ 18 | logical vector 19 | } 20 | \description{ 21 | If the table is sorted, this can be much faster than \code{\link[=match]{\%in\%}} 22 | } 23 | \examples{ 24 | x <- bitwhich(100) 25 | x[3] <- TRUE 26 | in.bitwhich(c(NA, 2, 3), x) 27 | } 28 | \seealso{ 29 | \code{\link[=match]{\%in\%}} 30 | } 31 | -------------------------------------------------------------------------------- /man/intrle.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rle.R 3 | \name{intrle} 4 | \alias{intrle} 5 | \alias{intisasc} 6 | \alias{intisdesc} 7 | \title{Hybrid Index, C-coded utilities} 8 | \usage{ 9 | intrle(x) 10 | 11 | intisasc(x, na.method = c("none", "break", "skip")[2]) 12 | 13 | intisdesc(x, na.method = c("none", "break", "skip")[1]) 14 | } 15 | \arguments{ 16 | \item{x}{an integer vector} 17 | 18 | \item{na.method}{one of "none", "break", "skip", see details. The strange defaults stem 19 | from the initial usage.} 20 | } 21 | \value{ 22 | \itemize{ 23 | \item \code{intrle} returns an object of class \code{\link[=rle]{rle()}} or NULL, if rle-compression is not 24 | efficient (compression factor <3 or \code{length(x) < 3}). 25 | \item \code{intisasc} returns one of \verb{FALSE, NA, TRUE} 26 | \item \code{intisdesc} returns one of \verb{FALSE, TRUE} (if the input contains NAs, the output is 27 | undefined) 28 | } 29 | } 30 | \description{ 31 | These C-coded utilitites speed up index preprocessing considerably. 32 | } 33 | \details{ 34 | \code{intrle} is by factor 50 faster and needs less RAM (2x its input 35 | vector) compared to \code{\link[=rle]{rle()}} which needs 9x the RAM of its input 36 | vector. This is achieved because we allow the C-code of \code{intrle} to 37 | break when it turns out, that rle-packing will not achieve a compression 38 | factor of 3 or better. 39 | 40 | \code{intisasc} is a faster version of \code{\link[=is.unsorted]{is.unsorted()}}: it checks whether \code{x} is sorted. 41 | 42 | \code{intisdesc} checks for being sorted descending and by default default assumes that the 43 | input \code{x} contains no NAs. 44 | 45 | \code{na.method="none"} treats \code{NAs} (the smallest integer) like every other integer and 46 | hence returns either \code{TRUE} or \code{FALSE} \code{na.method="break"} checks for \code{NAs} and 47 | returns either \code{NA} as soon as \code{NA} is encountered. \code{na.method="skip"} checks for 48 | \code{NAs} and skips over them, hence decides the return value only on the basis of 49 | non-NA values. 50 | } 51 | \section{Functions}{ 52 | \itemize{ 53 | \item \code{intisasc()}: check whether integer vector is ascending 54 | 55 | \item \code{intisdesc()}: check whether integer vector is descending 56 | 57 | }} 58 | \examples{ 59 | 60 | intrle(sample(1:10)) 61 | intrle(diff(1:10)) 62 | intisasc(1:10) 63 | intisasc(10:1) 64 | intisasc(c(NA, 1:10)) 65 | intisdesc(1:10) 66 | intisdesc(c(10:1, NA)) 67 | intisdesc(c(10:6, NA, 5:1)) 68 | intisdesc(c(10:6, NA, 5:1), na.method="skip") 69 | intisdesc(c(10:6, NA, 5:1), na.method="break") 70 | 71 | } 72 | \seealso{ 73 | \code{\link[ff:hi]{ff::hi()}}, \code{\link[=rle]{rle()}}, \code{\link[=is.unsorted]{is.unsorted()}}, 74 | \code{\link[ff:is.sorted]{ff::is.sorted.default()}} 75 | } 76 | \author{ 77 | Jens Oehlschlägel 78 | } 79 | \keyword{IO} 80 | \keyword{data} 81 | -------------------------------------------------------------------------------- /man/is.booltype.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{is.booltype} 4 | \alias{is.booltype} 5 | \alias{is.bit} 6 | \alias{is.bitwhich} 7 | \alias{is.which} 8 | \alias{is.hi} 9 | \alias{is.ri} 10 | \title{Testing for boolean types} 11 | \usage{ 12 | is.booltype(x) 13 | 14 | is.bit(x) 15 | 16 | is.bitwhich(x) 17 | 18 | is.which(x) 19 | 20 | is.hi(x) 21 | 22 | is.ri(x) 23 | } 24 | \arguments{ 25 | \item{x}{an R object} 26 | } 27 | \value{ 28 | logical scalar 29 | } 30 | \description{ 31 | All \code{\link[=booltypes]{booltypes()}} including \code{\link[=logical]{logical()}} except 'nobool' types are considered 32 | 'is.booltype'. 33 | } 34 | \section{Functions}{ 35 | \itemize{ 36 | \item \code{is.bit()}: tests for \code{\link[=bit]{bit()}} 37 | 38 | \item \code{is.bitwhich()}: tests for \code{\link[=bitwhich]{bitwhich()}} 39 | 40 | \item \code{is.which()}: tests for \code{\link[=as.which]{which()}} 41 | 42 | \item \code{is.hi()}: tests for \code{\link[ff:hi]{hi}} 43 | 44 | \item \code{is.ri()}: tests for \code{\link[=ri]{ri()}} 45 | 46 | }} 47 | \examples{ 48 | sapply( 49 | list(double(), integer(), logical(), bit(), bitwhich(), as.which(), ri(1, 2, 3)), 50 | is.booltype 51 | ) 52 | } 53 | \seealso{ 54 | \code{\link[=booltypes]{booltypes()}}, \code{\link[=booltype]{booltype()}}, \code{\link[=as.booltype]{as.booltype()}} 55 | } 56 | -------------------------------------------------------------------------------- /man/is.na.bit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{is.na.bit} 4 | \alias{is.na.bit} 5 | \alias{is.na.bitwhich} 6 | \title{Test for NA in bit and bitwhich} 7 | \usage{ 8 | \method{is.na}{bit}(x) 9 | 10 | \method{is.na}{bitwhich}(x) 11 | } 12 | \arguments{ 13 | \item{x}{a \code{\link[=bit]{bit()}} or \code{\link[=bitwhich]{bitwhich()}} vector} 14 | } 15 | \value{ 16 | vector of same type with all elements \code{FALSE} 17 | } 18 | \description{ 19 | Test for NA in bit and bitwhich 20 | } 21 | \section{Functions}{ 22 | \itemize{ 23 | \item \code{is.na(bitwhich)}: method for \code{\link[=is.na]{is.na()}} from \code{\link[=bitwhich]{bitwhich()}} 24 | 25 | }} 26 | \examples{ 27 | is.na(bit(6)) 28 | is.na(bitwhich(6)) 29 | } 30 | \seealso{ 31 | \code{\link[=is.na]{is.na()}} 32 | } 33 | -------------------------------------------------------------------------------- /man/length.bit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{length.bit} 4 | \alias{length.bit} 5 | \alias{length<-.bit} 6 | \alias{length.bitwhich} 7 | \alias{length<-.bitwhich} 8 | \alias{length.ri} 9 | \title{Getting and setting length of bit, bitwhich and ri objects} 10 | \usage{ 11 | \method{length}{bit}(x) 12 | 13 | \method{length}{bit}(x) <- value 14 | 15 | \method{length}{bitwhich}(x) 16 | 17 | \method{length}{bitwhich}(x) <- value 18 | 19 | \method{length}{ri}(x) 20 | } 21 | \arguments{ 22 | \item{x}{a \code{\link[=bit]{bit()}}, \code{\link[=bitwhich]{bitwhich()}} or \code{\link[=ri]{ri()}} 23 | object} 24 | 25 | \item{value}{the new number of bits} 26 | } 27 | \value{ 28 | the length A bit vector with the new length 29 | } 30 | \description{ 31 | Query the number of bits in a \code{\link[=bit]{bit()}} vector or change the number 32 | of bits in a bit vector. 33 | Query the number of bits in a bitwhich()] vector or change the number of bits in a bit 34 | vector. 35 | } 36 | \details{ 37 | NOTE that the length does NOT reflect the number of selected (\code{TRUE}) 38 | bits, it reflects the sum of both, \code{TRUE} and \code{FALSE} bits. 39 | Increasing the length of a \code{\link[=bit]{bit()}} object will set new bits to 40 | \code{FALSE}. The behaviour of increasing the length of a 41 | \code{\link[=bitwhich]{bitwhich()}} object is different and depends on the content of the 42 | object: 43 | \itemize{ 44 | \item TRUE -- all included, new bits are set to \code{TRUE} 45 | \item positive integers -- some included, new bits are set to \code{FALSE} 46 | \item negative integers -- some excluded, new bits are set to \code{TRUE} 47 | \item FALSE -- all excluded:, new bits are set to \code{FALSE} 48 | } 49 | 50 | Decreasing the length of bit or bitwhich removes any previous information 51 | about the status bits above the new length. 52 | } 53 | \examples{ 54 | 55 | stopifnot(length(ri(1, 1, 32)) == 32) 56 | 57 | x <- as.bit(ri(32, 32, 32)) 58 | stopifnot(length(x) == 32) 59 | stopifnot(sum(x) == 1) 60 | length(x) <- 16 61 | stopifnot(length(x) == 16) 62 | stopifnot(sum(x) == 0) 63 | length(x) <- 32 64 | stopifnot(length(x) == 32) 65 | stopifnot(sum(x) == 0) 66 | 67 | x <- as.bit(ri(1, 1, 32)) 68 | stopifnot(length(x) == 32) 69 | stopifnot(sum(x) == 1) 70 | length(x) <- 16 71 | stopifnot(length(x) == 16) 72 | stopifnot(sum(x) == 1) 73 | length(x) <- 32 74 | stopifnot(length(x) == 32) 75 | stopifnot(sum(x) == 1) 76 | 77 | x <- as.bitwhich(bit(32)) 78 | stopifnot(length(x) == 32) 79 | stopifnot(sum(x) == 0) 80 | length(x) <- 16 81 | stopifnot(length(x) == 16) 82 | stopifnot(sum(x) == 0) 83 | length(x) <- 32 84 | stopifnot(length(x) == 32) 85 | stopifnot(sum(x) == 0) 86 | 87 | x <- as.bitwhich(!bit(32)) 88 | stopifnot(length(x) == 32) 89 | stopifnot(sum(x) == 32) 90 | length(x) <- 16 91 | stopifnot(length(x) == 16) 92 | stopifnot(sum(x) == 16) 93 | length(x) <- 32 94 | stopifnot(length(x) == 32) 95 | stopifnot(sum(x) == 32) 96 | 97 | x <- as.bitwhich(ri(32, 32, 32)) 98 | stopifnot(length(x) == 32) 99 | stopifnot(sum(x) == 1) 100 | length(x) <- 16 101 | stopifnot(length(x) == 16) 102 | stopifnot(sum(x) == 0) 103 | length(x) <- 32 104 | stopifnot(length(x) == 32) 105 | stopifnot(sum(x) == 0) 106 | 107 | x <- as.bitwhich(ri(2, 32, 32)) 108 | stopifnot(length(x) == 32) 109 | stopifnot(sum(x) == 31) 110 | length(x) <- 16 111 | stopifnot(length(x) == 16) 112 | stopifnot(sum(x) == 15) 113 | length(x) <- 32 114 | stopifnot(length(x) == 32) 115 | stopifnot(sum(x) == 31) 116 | 117 | x <- as.bitwhich(ri(1, 1, 32)) 118 | stopifnot(length(x) == 32) 119 | stopifnot(sum(x) == 1) 120 | length(x) <- 16 121 | stopifnot(length(x) == 16) 122 | stopifnot(sum(x) == 1) 123 | length(x) <- 32 124 | stopifnot(length(x) == 32) 125 | stopifnot(sum(x) == 1) 126 | 127 | x <- as.bitwhich(ri(1, 31, 32)) 128 | stopifnot(length(x) == 32) 129 | stopifnot(sum(x) == 31) 130 | message("NOTE the change from 'some excluded' to 'all excluded' here") 131 | length(x) <- 16 132 | stopifnot(length(x) == 16) 133 | stopifnot(sum(x) == 16) 134 | length(x) <- 32 135 | stopifnot(length(x) == 32) 136 | stopifnot(sum(x) == 32) 137 | 138 | } 139 | \seealso{ 140 | \code{\link[=length]{length()}}, \code{\link[=sum.bit]{sum()}}, 141 | \code{\link[=poslength]{poslength()}}, \code{\link[=maxindex]{maxindex()}} 142 | } 143 | \author{ 144 | Jens Oehlschlägel 145 | } 146 | \keyword{classes} 147 | \keyword{logic} 148 | -------------------------------------------------------------------------------- /man/maxindex.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R, R/generics.R 3 | \name{maxindex.default} 4 | \alias{maxindex.default} 5 | \alias{poslength.default} 6 | \alias{maxindex.logical} 7 | \alias{poslength.logical} 8 | \alias{maxindex.bit} 9 | \alias{poslength.bit} 10 | \alias{maxindex.bitwhich} 11 | \alias{poslength.bitwhich} 12 | \alias{maxindex.which} 13 | \alias{poslength.which} 14 | \alias{maxindex.ri} 15 | \alias{poslength.ri} 16 | \alias{maxindex} 17 | \alias{poslength} 18 | \title{Get maxindex (length of boolean vector) and poslength (number of 'selected' elements)} 19 | \usage{ 20 | \method{maxindex}{default}(x, ...) 21 | 22 | \method{poslength}{default}(x, ...) 23 | 24 | \method{maxindex}{logical}(x, ...) 25 | 26 | \method{poslength}{logical}(x, ...) 27 | 28 | \method{maxindex}{bit}(x, ...) 29 | 30 | \method{poslength}{bit}(x, ...) 31 | 32 | \method{maxindex}{bitwhich}(x, ...) 33 | 34 | \method{poslength}{bitwhich}(x, ...) 35 | 36 | \method{maxindex}{which}(x, ...) 37 | 38 | \method{poslength}{which}(x, ...) 39 | 40 | \method{maxindex}{ri}(x, ...) 41 | 42 | \method{poslength}{ri}(x, ...) 43 | 44 | maxindex(x, ...) 45 | 46 | poslength(x, ...) 47 | } 48 | \arguments{ 49 | \item{x}{an R object, typically a \code{\link[=is.booltype]{is.booltype()}} object.} 50 | 51 | \item{...}{further arguments (ignored)} 52 | } 53 | \value{ 54 | an integer scalar 55 | } 56 | \description{ 57 | For \code{\link[=is.booltype]{is.booltype()}} objects the term \code{\link[=length]{length()}} is ambiguous. 58 | For example the length of \code{\link[=which]{which()}} corresponds to the sum of \code{\link[=logical]{logical()}}. 59 | The generic \code{maxindex} gives \code{length(logical)} for all \code{\link[=booltype]{booltype()}}s. 60 | The generic \code{poslength} gives the number of positively selected elements, i.e. 61 | \code{sum(logical)} for all \code{\link[=booltype]{booltype()}}s (and gives \code{NA} if \code{NAs} are present). 62 | } 63 | \section{Methods (by class)}{ 64 | \itemize{ 65 | \item \code{maxindex(default)}: default method for \code{maxindex} 66 | 67 | \item \code{maxindex(logical)}: \code{maxindex} method for class \code{\link[=logical]{logical()}} 68 | 69 | \item \code{maxindex(bit)}: \code{maxindex} method for class \code{\link[=bit]{bit()}} 70 | 71 | \item \code{maxindex(bitwhich)}: \code{maxindex} method for class \code{\link[=bitwhich]{bitwhich()}} 72 | 73 | \item \code{maxindex(which)}: \code{maxindex} method for class \code{\link[=as.which]{which()}} 74 | 75 | \item \code{maxindex(ri)}: \code{maxindex} method for class \code{\link[=ri]{ri()}} 76 | 77 | }} 78 | \section{Functions}{ 79 | \itemize{ 80 | \item \code{poslength(default)}: default method for \code{poslength} 81 | 82 | \item \code{poslength(logical)}: \code{poslength} method for class \code{\link[=logical]{logical()}} 83 | 84 | \item \code{poslength(bit)}: \code{poslength} method for class \code{\link[=bit]{bit()}} 85 | 86 | \item \code{poslength(bitwhich)}: \code{poslength} method for class \code{\link[=bitwhich]{bitwhich()}} 87 | 88 | \item \code{poslength(which)}: \code{poslength} method for class \code{\link[=as.which]{which()}} 89 | 90 | \item \code{poslength(ri)}: \code{poslength} method for class \code{\link[=ri]{ri()}} 91 | 92 | }} 93 | \examples{ 94 | r <- ri(1, 2, 12) 95 | i <- as.which(r) 96 | w <- as.bitwhich(r) 97 | b <- as.bit(r) 98 | l <- as.logical(r) 99 | u <- which(l) # unclassed which 100 | 101 | sapply(list(r=r, u=u, i=i, w=w, b=b, l=l), function(x) { 102 | c(length=length(x), sum=sum(x), maxindex=maxindex(x), poslength=poslength(x)) 103 | }) 104 | } 105 | -------------------------------------------------------------------------------- /man/print.bit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{print.bit} 4 | \alias{print.bit} 5 | \title{Print method for bit} 6 | \usage{ 7 | \method{print}{bit}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{a bit vector} 11 | 12 | \item{...}{passed to print} 13 | } 14 | \value{ 15 | a character vector showing first and last elements of the bit vector 16 | } 17 | \description{ 18 | Print method for bit 19 | } 20 | \examples{ 21 | print(bit(120)) 22 | } 23 | -------------------------------------------------------------------------------- /man/print.bitwhich.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{print.bitwhich} 4 | \alias{print.bitwhich} 5 | \title{Print method for bitwhich} 6 | \usage{ 7 | \method{print}{bitwhich}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{a \code{\link[=bitwhich]{bitwhich()}} object} 11 | 12 | \item{...}{ignored} 13 | } 14 | \description{ 15 | Print method for bitwhich 16 | } 17 | -------------------------------------------------------------------------------- /man/quicksort2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bitsort.R 3 | \name{quicksort2} 4 | \alias{quicksort2} 5 | \title{Low-level sorting: binary quicksort} 6 | \usage{ 7 | quicksort2(x, na.last = NA) 8 | } 9 | \arguments{ 10 | \item{x}{an integer vector} 11 | 12 | \item{na.last}{\code{NA} removes NAs, \code{FALSE} puts NAs at the beginning, 13 | \code{TRUE} puts NAs at the end} 14 | } 15 | \value{ 16 | a sorted vector 17 | } 18 | \description{ 19 | In one pass over the vector \code{NA}s are handled according to parameter 20 | \code{na.last} by \code{\link[=range_sortna]{range_sortna()}}, then, if the vector is unsorted, 21 | binary quicksort is invoked. 22 | } 23 | \examples{ 24 | quicksort2(c(2L, 0L, 1L, NA, 2L)) 25 | quicksort2(c(2L, 0L, 1L, NA, 2L), na.last=TRUE) 26 | quicksort2(c(2L, 0L, 1L, NA, 2L), na.last=FALSE) 27 | } 28 | -------------------------------------------------------------------------------- /man/quicksort3.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bitsort.R 3 | \name{quicksort3} 4 | \alias{quicksort3} 5 | \title{Low-level sorting: threeway quicksort} 6 | \usage{ 7 | quicksort3(x, na.last = NA) 8 | } 9 | \arguments{ 10 | \item{x}{an integer vector} 11 | 12 | \item{na.last}{\code{NA} removes NAs, \code{FALSE} puts NAs at the beginning, 13 | \code{TRUE} puts NAs at the end} 14 | } 15 | \value{ 16 | a sorted vector 17 | } 18 | \description{ 19 | In one pass over the vector \code{NA}s are handled according to parameter 20 | \code{na.last} by \code{\link[=range_sortna]{range_sortna()}}, then, if the vector is unsorted, 21 | threeway quicksort is invoked. 22 | } 23 | \examples{ 24 | countsort(c(2L, 0L, 1L, NA, 2L)) 25 | countsort(c(2L, 0L, 1L, NA, 2L), na.last=TRUE) 26 | countsort(c(2L, 0L, 1L, NA, 2L), na.last=FALSE) 27 | } 28 | -------------------------------------------------------------------------------- /man/range_na.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bitsort.R 3 | \name{range_na} 4 | \alias{range_na} 5 | \title{Get range and number of NAs} 6 | \usage{ 7 | range_na(x) 8 | } 9 | \arguments{ 10 | \item{x}{an integer vector} 11 | } 12 | \value{ 13 | an integer vector with three elements: 14 | \enumerate{ 15 | \item min integer 16 | \item max integer 17 | \item number of NAs 18 | } 19 | } 20 | \description{ 21 | Get range and number of NAs 22 | } 23 | \examples{ 24 | range_na(c(0L, 1L, 2L, NA)) 25 | } 26 | \seealso{ 27 | \code{\link[=range_nanozero]{range_nanozero()}} and \code{\link[=range_sortna]{range_sortna()}} 28 | } 29 | -------------------------------------------------------------------------------- /man/range_nanozero.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bitsort.R 3 | \name{range_nanozero} 4 | \alias{range_nanozero} 5 | \title{Remove zeros and get range and number of NAs} 6 | \usage{ 7 | range_nanozero(x) 8 | } 9 | \arguments{ 10 | \item{x}{an integer vector} 11 | } 12 | \value{ 13 | an integer vector without zeros and with an attribute \code{\link[=range_na]{range_na()}} with three 14 | elements: 15 | \enumerate{ 16 | \item min integer 17 | \item max integer 18 | \item number of NAs 19 | } 20 | } 21 | \description{ 22 | Remove zeros and get range and number of NAs 23 | } 24 | \examples{ 25 | range_nanozero(c(0L, 1L, 2L, NA)) 26 | } 27 | \seealso{ 28 | \code{\link[=range_na]{range_na()}} and \code{\link[=range_sortna]{range_sortna()}} 29 | } 30 | -------------------------------------------------------------------------------- /man/range_sortna.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bitsort.R 3 | \name{range_sortna} 4 | \alias{range_sortna} 5 | \title{Prepare for sorting and get range, number of NAs and unsortedness} 6 | \usage{ 7 | range_sortna(x, decreasing = FALSE, na.last = NA) 8 | } 9 | \arguments{ 10 | \item{x}{an integer vector} 11 | 12 | \item{decreasing}{(currently only \code{FALSE} is supported)} 13 | 14 | \item{na.last}{\code{NA} removes NAs, \code{FALSE} puts NAs at the beginning, 15 | \code{TRUE} puts NAs at the end} 16 | } 17 | \value{ 18 | an integer vector with \code{NA}s are treated and an \code{attribute} \code{\link[=range_na]{range_na()}} with 19 | four elements: 20 | \enumerate{ 21 | \item min integer 22 | \item max integer 23 | \item number of NAs 24 | \item 0 for sorted vector and 1 for \code{\link[=is.unsorted]{is.unsorted()}} 25 | } 26 | } 27 | \description{ 28 | In one pass over the vector \code{NA}s are treated according to parameter 29 | \code{na.last} exactly like \code{\link[=sort]{sort()}} does, the \code{\link[=range]{range()}}, 30 | number of \code{NA}s and unsortedness is determined. 31 | } 32 | \examples{ 33 | range_sortna(c(0L, 1L, NA, 2L)) 34 | range_sortna(c(2L, NA, 1L, 0L)) 35 | range_sortna(c(0L, 1L, NA, 2L), na.last=TRUE) 36 | range_sortna(c(2L, NA, 1L, 0L), na.last=TRUE) 37 | range_sortna(c(0L, 1L, NA, 2L), na.last=FALSE) 38 | range_sortna(c(2L, NA, 1L, 0L), na.last=FALSE) 39 | } 40 | \seealso{ 41 | \code{\link[=range_na]{range_na()}} and \code{\link[=range_nanozero]{range_nanozero()}} 42 | } 43 | -------------------------------------------------------------------------------- /man/rep.booltype.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{rep.booltype} 4 | \alias{rep.booltype} 5 | \alias{rep.bit} 6 | \alias{rep.bitwhich} 7 | \title{Replicating bit and bitwhich vectors} 8 | \usage{ 9 | \method{rep}{bit}(x, times = 1L, length.out = NA, ...) 10 | 11 | \method{rep}{bitwhich}(x, times = 1L, length.out = NA, ...) 12 | } 13 | \arguments{ 14 | \item{x}{bit or bitwhich object} 15 | 16 | \item{times}{number of replications} 17 | 18 | \item{length.out}{final length of replicated vector (dominates times)} 19 | 20 | \item{...}{not used} 21 | } 22 | \value{ 23 | An object of class 'bit' or 'bitwhich' 24 | } 25 | \description{ 26 | Creating new bit or bitwhich by recycling such vectors 27 | } 28 | \examples{ 29 | 30 | rep(as.bit(c(FALSE, TRUE)), 2) 31 | rep(as.bit(c(FALSE, TRUE)), length.out=7) 32 | rep(as.bitwhich(c(FALSE, TRUE)), 2) 33 | rep(as.bitwhich(c(FALSE, TRUE)), length.out=1) 34 | } 35 | \seealso{ 36 | \code{\link[=rep]{rep()}}, \code{\link[=bit]{bit()}} , \code{\link[=bitwhich]{bitwhich()}} 37 | } 38 | \author{ 39 | Jens Oehlschlägel 40 | } 41 | \keyword{classes} 42 | \keyword{logic} 43 | -------------------------------------------------------------------------------- /man/repeat.time.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/timeutil.R 3 | \name{repeat.time} 4 | \alias{repeat.time} 5 | \title{Adaptive timer} 6 | \usage{ 7 | repeat.time(expr, gcFirst = TRUE, minSec = 0.5, envir = parent.frame()) 8 | } 9 | \arguments{ 10 | \item{expr}{Valid expression to be timed.} 11 | 12 | \item{gcFirst}{Logical - should a garbage collection be performed 13 | immediately before the timing? Default is \code{TRUE}.} 14 | 15 | \item{minSec}{number of seconds to repeat at least} 16 | 17 | \item{envir}{the environment in which to evaluate \code{expr} (by default 18 | the calling frame)} 19 | } 20 | \value{ 21 | A object of class \code{"proc_time"}: see \code{\link[=proc.time]{proc.time()}} 22 | for details. 23 | } 24 | \description{ 25 | Repeats timing expr until minSec is reached 26 | } 27 | \examples{ 28 | 29 | system.time(1 + 1) 30 | repeat.time(1 + 1) 31 | system.time(sort(runif(1e6))) 32 | repeat.time(sort(runif(1e6))) 33 | 34 | } 35 | \seealso{ 36 | \code{\link[=system.time]{system.time()}} 37 | } 38 | \author{ 39 | Jens Oehlschlägel \href{mailto:Jens.Oehlschlaegel@truecluster.com}{Jens.Oehlschlaegel@truecluster.com} 40 | } 41 | \keyword{utilities} 42 | -------------------------------------------------------------------------------- /man/repfromto.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/chunkutil.R 3 | \name{repfromto} 4 | \alias{repfromto} 5 | \alias{repfromto<-} 6 | \title{Virtual recycling} 7 | \usage{ 8 | repfromto(x, from, to) 9 | 10 | repfromto(x, from, to) <- value 11 | } 12 | \arguments{ 13 | \item{x}{an object from which to recycle} 14 | 15 | \item{from}{first position to return} 16 | 17 | \item{to}{last position to return} 18 | 19 | \item{value}{value to assign} 20 | } 21 | \value{ 22 | a vector of length \code{from - to + 1} 23 | } 24 | \description{ 25 | \code{repfromto} virtually recylcles object \code{x} and cuts out 26 | positions \verb{from .. to} 27 | } 28 | \details{ 29 | \code{repfromto} is a generalization of \code{\link[=rep]{rep()}}, where 30 | \code{rep(x, n) == repfromto(x, 1, n)}. You can see this as an R-side 31 | (vector) solution of the \code{mod_iterate} macro in arithmetic.c 32 | } 33 | \examples{ 34 | 35 | message("a simple example") 36 | repfromto(0:9, 11, 20) 37 | 38 | } 39 | \seealso{ 40 | \code{\link[=rep]{rep()}}, \code{\link[ff:ffapply]{ff::ffvecapply()}} 41 | } 42 | \author{ 43 | Jens Oehlschlägel 44 | } 45 | \keyword{IO} 46 | \keyword{data} 47 | -------------------------------------------------------------------------------- /man/rev.booltype.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{rev.booltype} 4 | \alias{rev.booltype} 5 | \alias{rev.bit} 6 | \alias{rev.bitwhich} 7 | \title{Reversing bit and bitwhich vectors} 8 | \usage{ 9 | \method{rev}{bit}(x) 10 | 11 | \method{rev}{bitwhich}(x) 12 | } 13 | \arguments{ 14 | \item{x}{bit or bitwhich object} 15 | } 16 | \value{ 17 | An object of class 'bit' or 'bitwhich' 18 | } 19 | \description{ 20 | Creating new bit or bitwhich by reversing such vectors 21 | } 22 | \examples{ 23 | 24 | rev(as.bit(c(FALSE, TRUE))) 25 | rev(as.bitwhich(c(FALSE, TRUE))) 26 | } 27 | \seealso{ 28 | \code{\link[=rev]{rev()}}, \code{\link[=bit]{bit()}} , \code{\link[=bitwhich]{bitwhich()}} 29 | } 30 | \author{ 31 | Jens Oehlschlägel 32 | } 33 | \keyword{classes} 34 | \keyword{logic} 35 | -------------------------------------------------------------------------------- /man/reverse_vector.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/integerutil.R 3 | \name{reverse_vector} 4 | \alias{reverse_vector} 5 | \title{Reverse atomic vector} 6 | \usage{ 7 | reverse_vector(x) 8 | } 9 | \arguments{ 10 | \item{x}{an R vector} 11 | } 12 | \value{ 13 | a reversed vector 14 | } 15 | \description{ 16 | Returns a reversed copy -- with attributes retained. 17 | } 18 | \details{ 19 | This is substantially faster than \code{\link[=rev]{rev()}} 20 | } 21 | \examples{ 22 | x <- factor(letters) 23 | rev(x) 24 | reverse_vector(x) 25 | \dontrun{ 26 | x <- 1:1e7 27 | system.time(rev(x)) 28 | system.time(reverse_vector(x)) 29 | } 30 | } 31 | \seealso{ 32 | \code{\link[=rev]{rev()}}, \code{\link[=copy_vector]{copy_vector()}} 33 | } 34 | -------------------------------------------------------------------------------- /man/ri.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{ri} 4 | \alias{ri} 5 | \alias{print.ri} 6 | \title{Range index} 7 | \usage{ 8 | ri(from, to = NULL, maxindex = NA) 9 | 10 | \method{print}{ri}(x, ...) 11 | } 12 | \arguments{ 13 | \item{from}{first position} 14 | 15 | \item{to}{last posistion} 16 | 17 | \item{maxindex}{the maximal length of the object-to-be-subscripted (if 18 | known)} 19 | 20 | \item{x}{an object of class 'ri'} 21 | 22 | \item{...}{further arguments} 23 | } 24 | \value{ 25 | A two element integer vector with class 'ri' 26 | } 27 | \description{ 28 | A range index can be used to extract or replace a continuous ascending part 29 | of the data 30 | } 31 | \examples{ 32 | 33 | bit(12)[ri(1, 6)] 34 | 35 | } 36 | \seealso{ 37 | \code{\link[ff:as.hi]{ff::as.hi()}} 38 | } 39 | \author{ 40 | Jens Oehlschlägel 41 | } 42 | \keyword{classes} 43 | \keyword{logic} 44 | -------------------------------------------------------------------------------- /man/rlepack.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rle.R 3 | \name{rlepack} 4 | \alias{rlepack} 5 | \alias{rlepack.integer} 6 | \alias{rleunpack} 7 | \alias{rleunpack.rlepack} 8 | \alias{rev.rlepack} 9 | \alias{unique.rlepack} 10 | \alias{anyDuplicated.rlepack} 11 | \title{Hybrid Index, rle-pack utilities} 12 | \usage{ 13 | rlepack(x, ...) 14 | 15 | \method{rlepack}{integer}(x, pack = TRUE, ...) 16 | 17 | rleunpack(x) 18 | 19 | \method{rleunpack}{rlepack}(x) 20 | 21 | \method{rev}{rlepack}(x) 22 | 23 | \method{unique}{rlepack}(x, incomparables = FALSE, ...) 24 | 25 | \method{anyDuplicated}{rlepack}(x, incomparables = FALSE, ...) 26 | } 27 | \arguments{ 28 | \item{x}{in 'rlepack' an integer vector, in the other functions an object of 29 | class 'rlepack'} 30 | 31 | \item{...}{just to keep R CMD CHECK quiet (not used)} 32 | 33 | \item{pack}{FALSE to suppress packing} 34 | 35 | \item{incomparables}{just to keep R CMD CHECK quiet (not used)} 36 | } 37 | \value{ 38 | A list with components: 39 | \itemize{ 40 | \item first: the first element of the packed sequence 41 | \item dat: either an object of class \code{\link[=rle]{rle()}} or the complete input vector \code{x} if 42 | rle-packing is not efficient 43 | \item last: the last element of the packed sequence 44 | } 45 | } 46 | \description{ 47 | Basic utilities for rle packing and unpacking and apropriate methods for 48 | \code{\link[=rev]{rev()}} and \code{\link[=unique]{unique()}}. 49 | } 50 | \examples{ 51 | 52 | x <- rlepack(rep(0L, 10)) 53 | 54 | } 55 | \seealso{ 56 | \code{\link[ff:hi]{ff::hi()}}, \code{\link[=intrle]{intrle()}}, \code{\link[=rle]{rle()}}, \code{\link[=rev]{rev()}}, \code{\link[=unique]{unique()}} 57 | } 58 | \author{ 59 | Jens Oehlschlägel 60 | } 61 | \keyword{IO} 62 | \keyword{data} 63 | -------------------------------------------------------------------------------- /man/still.identical.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/integerutil.R 3 | \name{still.identical} 4 | \alias{still.identical} 5 | \title{Test for C-level identity of two atomic vectors} 6 | \usage{ 7 | still.identical(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{an atomic vector} 11 | 12 | \item{y}{an atomic vector} 13 | } 14 | \value{ 15 | logical scalar 16 | } 17 | \description{ 18 | Test for C-level identity of two atomic vectors 19 | } 20 | \examples{ 21 | x <- 1:2 22 | y <- x 23 | z <- copy_vector(x) 24 | still.identical(y, x) 25 | still.identical(z, x) 26 | } 27 | -------------------------------------------------------------------------------- /man/str.bit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{str.bit} 4 | \alias{str.bit} 5 | \title{Str method for bit} 6 | \usage{ 7 | \method{str}{bit}( 8 | object, 9 | vec.len = strO$vec.len, 10 | give.head = TRUE, 11 | give.length = give.head, 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{object}{any \R object about which you want to have some 17 | information.} 18 | 19 | \item{vec.len}{numeric (>= 0) indicating how many \sQuote{first few} elements 20 | are displayed of each vector. The number is multiplied by different 21 | factors (from .5 to 3) depending on the kind of vector. Defaults to 22 | the \code{vec.len} component of option \code{"str"} (see 23 | \code{\link{options}}) which defaults to 4.} 24 | 25 | \item{give.head}{logical; if \code{TRUE} (default), give (possibly 26 | abbreviated) mode/class and length (as \code{\var{type}[1:\dots]}).} 27 | 28 | \item{give.length}{logical; if \code{TRUE} (default), indicate 29 | length (as \code{[1:\dots]}).} 30 | 31 | \item{...}{potential further arguments (required for Method/Generic 32 | reasons).} 33 | } 34 | \value{ 35 | \code{\link[=invisible]{invisible()}} 36 | } 37 | \description{ 38 | To actually view the internal structure use \code{str(unclass(bit))} 39 | } 40 | \examples{ 41 | str(bit(120)) 42 | } 43 | -------------------------------------------------------------------------------- /man/str.bitwhich.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R 3 | \name{str.bitwhich} 4 | \alias{str.bitwhich} 5 | \title{Str method for bitwhich} 6 | \usage{ 7 | \method{str}{bitwhich}( 8 | object, 9 | vec.len = strO$vec.len, 10 | give.head = TRUE, 11 | give.length = give.head, 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{object}{any \R object about which you want to have some 17 | information.} 18 | 19 | \item{vec.len}{numeric (>= 0) indicating how many \sQuote{first few} elements 20 | are displayed of each vector. The number is multiplied by different 21 | factors (from .5 to 3) depending on the kind of vector. Defaults to 22 | the \code{vec.len} component of option \code{"str"} (see 23 | \code{\link{options}}) which defaults to 4.} 24 | 25 | \item{give.head}{logical; if \code{TRUE} (default), give (possibly 26 | abbreviated) mode/class and length (as \code{\var{type}[1:\dots]}).} 27 | 28 | \item{give.length}{logical; if \code{TRUE} (default), indicate 29 | length (as \code{[1:\dots]}).} 30 | 31 | \item{...}{potential further arguments (required for Method/Generic 32 | reasons).} 33 | } 34 | \value{ 35 | \code{\link[=invisible]{invisible()}} 36 | } 37 | \description{ 38 | To actually view the internal structure use \code{str(unclass(bitwhich))} 39 | } 40 | \examples{ 41 | str(bitwhich(120)) 42 | } 43 | -------------------------------------------------------------------------------- /man/symdiff.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/merge.R 3 | \name{symdiff} 4 | \alias{symdiff} 5 | \title{Symmetric set complement} 6 | \usage{ 7 | symdiff(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{a vector} 11 | 12 | \item{y}{a vector} 13 | } 14 | \value{ 15 | \code{union(setdiff(x, y), setdiff(y, x))} 16 | } 17 | \description{ 18 | Symmetric set complement 19 | } 20 | \note{ 21 | that \code{symdiff(x, y)} is not \code{\link[=identical]{identical()}} 22 | as \code{symdiff(y, x)} without applying \code{\link[=sort]{sort()}} to the result 23 | } 24 | \examples{ 25 | symdiff(c(1L, 2L, 2L), c(2L, 3L)) 26 | symdiff(c(2L, 3L), c(1L, 2L, 2L)) 27 | } 28 | \seealso{ 29 | \code{\link[=merge_symdiff]{merge_symdiff()}} and \code{\link[=xor]{xor()}} 30 | } 31 | -------------------------------------------------------------------------------- /man/unattr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/attrutil.R 3 | \name{unattr} 4 | \alias{unattr} 5 | \title{Attribute removal} 6 | \usage{ 7 | unattr(x) 8 | } 9 | \arguments{ 10 | \item{x}{any R object} 11 | } 12 | \value{ 13 | a similar object with attributes removed 14 | } 15 | \description{ 16 | Returns object with attributes removed 17 | } 18 | \details{ 19 | attribute removal copies the object as usual 20 | } 21 | \examples{ 22 | 23 | bit(2)[] 24 | unattr(bit(2)[]) 25 | 26 | } 27 | \seealso{ 28 | \code{\link[=attributes]{attributes()}}, \code{\link[=setattributes]{setattributes()}}, 29 | \code{\link[=unclass]{unclass()}} 30 | } 31 | \author{ 32 | Jens Oehlschlägel 33 | } 34 | \keyword{attribute} 35 | -------------------------------------------------------------------------------- /man/vecseq.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/chunkutil.R 3 | \name{vecseq} 4 | \alias{vecseq} 5 | \title{Vectorized Sequences} 6 | \usage{ 7 | vecseq(x, y = NULL, concat = TRUE, eval = TRUE) 8 | } 9 | \arguments{ 10 | \item{x}{vector of sequence start points} 11 | 12 | \item{y}{vector of sequence end points (if \code{is.null(y)} then \code{x} 13 | are taken as endpoints, all starting at 1)} 14 | 15 | \item{concat}{vector of sequence end points (if \code{is.null(y)} then 16 | \code{x} are taken as endpoints, all starting at 1)} 17 | 18 | \item{eval}{vector of sequence end points (if \code{is.null(y)} then 19 | \code{x} are taken as endpoints, all starting at 1)} 20 | } 21 | \value{ 22 | \itemize{ 23 | \item if \code{concat == FALSE} and \code{eval == FALSE} a list with n calls that generate sequences 24 | \item if \code{concat == FALSE} and \code{eval == TRUE } a list with n sequences 25 | \item if \code{concat == TRUE } and \code{eval == FALSE} a single call generating the concatenated 26 | sequences 27 | \item if \code{concat == TRUE} and \code{eval == TRUE } an integer vector of concatentated sequences 28 | } 29 | } 30 | \description{ 31 | \code{vecseq} returns concatenated multiple sequences 32 | } 33 | \details{ 34 | This is a generalization of \code{\link[=sequence]{sequence()}} in that you can choose 35 | sequence starts other than 1 and also have options to no concat and/or 36 | return a call instead of the evaluated sequence. 37 | } 38 | \examples{ 39 | 40 | sequence(c(3, 4)) 41 | vecseq(c(3, 4)) 42 | vecseq(c(1, 11), c(5, 15)) 43 | vecseq(c(1, 11), c(5, 15), concat=FALSE, eval=FALSE) 44 | vecseq(c(1, 11), c(5, 15), concat=FALSE, eval=TRUE) 45 | vecseq(c(1, 11), c(5, 15), concat=TRUE, eval=FALSE) 46 | vecseq(c(1, 11), c(5, 15), concat=TRUE, eval=TRUE) 47 | 48 | } 49 | \seealso{ 50 | \code{\link{:}}, \code{\link[=seq]{seq()}}, \code{\link[=sequence]{sequence()}} 51 | } 52 | \author{ 53 | Angelo Canty, Jens Oehlschlägel 54 | } 55 | \keyword{manip} 56 | -------------------------------------------------------------------------------- /man/xor.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bit.R, R/generics.R 3 | \name{xor.default} 4 | \alias{xor.default} 5 | \alias{xor.logical} 6 | \alias{!.bit} 7 | \alias{&.bit} 8 | \alias{|.bit} 9 | \alias{==.bit} 10 | \alias{!=.bit} 11 | \alias{xor.bit} 12 | \alias{!.bitwhich} 13 | \alias{&.bitwhich} 14 | \alias{|.bitwhich} 15 | \alias{==.bitwhich} 16 | \alias{!=.bitwhich} 17 | \alias{xor.bitwhich} 18 | \alias{&.booltype} 19 | \alias{|.booltype} 20 | \alias{==.booltype} 21 | \alias{!=.booltype} 22 | \alias{xor.booltype} 23 | \alias{xor} 24 | \title{Boolean operators and functions} 25 | \usage{ 26 | \method{xor}{default}(x, y) 27 | 28 | \method{xor}{logical}(x, y) 29 | 30 | \method{!}{bit}(x) 31 | 32 | \method{&}{bit}(e1, e2) 33 | 34 | \method{|}{bit}(e1, e2) 35 | 36 | \method{==}{bit}(e1, e2) 37 | 38 | \method{!=}{bit}(e1, e2) 39 | 40 | \method{xor}{bit}(x, y) 41 | 42 | \method{!}{bitwhich}(x) 43 | 44 | \method{&}{bitwhich}(e1, e2) 45 | 46 | \method{|}{bitwhich}(e1, e2) 47 | 48 | \method{==}{bitwhich}(e1, e2) 49 | 50 | \method{!=}{bitwhich}(e1, e2) 51 | 52 | \method{xor}{bitwhich}(x, y) 53 | 54 | \method{&}{booltype}(e1, e2) 55 | 56 | \method{|}{booltype}(e1, e2) 57 | 58 | \method{==}{booltype}(e1, e2) 59 | 60 | \method{!=}{booltype}(e1, e2) 61 | 62 | \method{xor}{booltype}(x, y) 63 | 64 | xor(x, y) 65 | } 66 | \arguments{ 67 | \item{x}{a \code{\link[=is.booltype]{is.booltype()}} vector} 68 | 69 | \item{y}{a \code{\link[=is.booltype]{is.booltype()}} vector} 70 | 71 | \item{e1}{a \code{\link[=is.booltype]{is.booltype()}} vector} 72 | 73 | \item{e2}{a \code{\link[=is.booltype]{is.booltype()}} vector} 74 | } 75 | \value{ 76 | An object of class \code{\link[=booltype]{booltype()}} or \code{\link[=logical]{logical()}} 77 | } 78 | \description{ 79 | Boolean NEGATION '!', AND '&', OR '|' and EXCLUSIVE OR xor', see 80 | \code{\link[base:Logic]{Logic}}. 81 | } 82 | \details{ 83 | The binary operators and function \code{xor} can now combine any \code{\link[=is.booltype]{is.booltype()}} vectors. 84 | They now recycle if vectors have different length. If the two arguments have different 85 | \code{\link[=booltypes]{booltypes()}} the return value corresponds to the lower \code{\link[=booltype]{booltype()}} of the two. 86 | 87 | Boolean operations on \code{\link[=bit]{bit()}} vectors are extremely fast because they are 88 | implemented using C's bitwise operators. Boolean operations on or \code{\link[=bitwhich]{bitwhich()}} 89 | vectors are even faster, if they represent very skewed selections. 90 | 91 | The \code{xor} function has been made generic and \code{xor.default} has 92 | been implemented much faster than R's standard \code{\link[=xor]{xor()}}. 93 | This was possible because actually boolean function \code{xor} and 94 | comparison operator \code{!=} do the same (even with NAs), and \code{!=} is 95 | much faster than the multiple calls in \code{(x | y) & !(x & y)} 96 | } 97 | \section{Methods (by class)}{ 98 | \itemize{ 99 | \item \code{xor(default)}: default method for \code{\link[=xor]{xor()}} 100 | 101 | \item \code{xor(logical)}: \code{\link[=logical]{logical()}} method for \code{\link[=xor]{xor()}} 102 | 103 | \item \code{xor(bit)}: \code{\link[=bit]{bit()}} method for \code{\link[=xor]{xor()}} 104 | 105 | \item \code{xor(bitwhich)}: \code{\link[=bitwhich]{bitwhich()}} method for \code{\link[=xor]{xor()}} 106 | 107 | \item \code{xor(booltype)}: \code{\link[=booltype]{booltype()}} method for \code{\link[=xor]{xor()}} 108 | 109 | }} 110 | \section{Functions}{ 111 | \itemize{ 112 | \item \code{`!`(bit)}: \code{\link[=bit]{bit()}} method for \code{\link[=Logic]{!}} 113 | 114 | \item \code{ & }: \code{\link[=bit]{bit()}} method for \code{\link[=Logic]{&}} 115 | 116 | \item \code{ | }: \code{\link[=bit]{bit()}} method for \code{\link[=Logic]{|}} 117 | 118 | \item \code{ == }: \code{\link[=bit]{bit()}} method for \code{\link[=Comparison]{==}} 119 | 120 | \item \code{ != }: \code{\link[=bit]{bit()}} method for \code{\link[=Comparison]{!=}} 121 | 122 | \item \code{`!`(bitwhich)}: \code{\link[=bitwhich]{bitwhich()}} method for \code{\link[=Logic]{!}} 123 | 124 | \item \code{ & }: \code{\link[=bitwhich]{bitwhich()}} method for \code{\link[=Logic]{&}} 125 | 126 | \item \code{ | }: \code{\link[=bitwhich]{bitwhich()}} method for \code{\link[=Logic]{|}} 127 | 128 | \item \code{ == }: \code{\link[=bitwhich]{bitwhich()}} method for \code{\link[=Comparison]{==}} 129 | 130 | \item \code{ != }: \code{\link[=bitwhich]{bitwhich()}} method for \code{\link[=Comparison]{!=}} 131 | 132 | \item \code{ & }: \code{\link[=booltype]{booltype()}} method for \code{\link[=Logic]{&}} 133 | 134 | \item \code{ | }: \code{\link[=booltype]{booltype()}} method for \code{\link[=Logic]{|}} 135 | 136 | \item \code{ == }: \code{\link[=booltype]{booltype()}} method for \code{\link[=Comparison]{==}} 137 | 138 | \item \code{ != }: \code{\link[=booltype]{booltype()}} method for \code{\link[=Comparison]{!=}} 139 | 140 | }} 141 | \examples{ 142 | 143 | x <- c(FALSE, FALSE, FALSE, NA, NA, NA, TRUE, TRUE, TRUE) 144 | y <- c(FALSE, NA, TRUE, FALSE, NA, TRUE, FALSE, NA, TRUE) 145 | 146 | x | y 147 | x | as.bit(y) 148 | x | as.bitwhich(y) 149 | x | as.which(y) 150 | x | ri(1, 1, 9) 151 | 152 | 153 | } 154 | \seealso{ 155 | \code{\link[=booltypes]{booltypes()}}, \code{\link{Logic}} 156 | } 157 | \author{ 158 | Jens Oehlschlägel 159 | } 160 | \keyword{classes} 161 | \keyword{logic} 162 | -------------------------------------------------------------------------------- /src/Makevars: -------------------------------------------------------------------------------- 1 | #CC = gcc-4.8 -std=gnu99 -fsanitize=address -fno-omit-frame-pointer 2 | #CXX = g++-4.8 -fsanitize=address -fno-omit-frame-pointer 3 | #F77 = gfortran-4.8 -fsanitize=address 4 | #FC = gfortran-4.8 -fsanitize=address 5 | #for checking LTO errors 6 | #PKG_CFLAGS=-flto 7 | -------------------------------------------------------------------------------- /src/attrutil.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | SEXP R_bit_set_attr(SEXP x, SEXP which, SEXP value) 5 | { 6 | /* xx looking at R sources setAttrib would directly accept a string, however this is not documented */ 7 | return setAttrib(x, install(CHAR(STRING_ELT(which, 0))), value); 8 | } 9 | -------------------------------------------------------------------------------- /src/bit.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-lib/bit/d128f0735f3c15ac67070a1398fea3411de5eab8/src/bit.dll -------------------------------------------------------------------------------- /src/chunkutil.c: -------------------------------------------------------------------------------- 1 | /* 2 | # C-Code for chunk utilities 3 | # (c) 2012 Jens Oehlschaegel 4 | # Licence: GPL2 5 | # Provided 'as is', use at your own risk 6 | */ 7 | 8 | #include 9 | #define USE_RINTERNALS 10 | #include 11 | 12 | SEXP R_bit_vecseq(SEXP x_, SEXP y_) 13 | { 14 | int *x,*y,*ret; 15 | register int val, lim; 16 | R_len_t K,k,n,i; 17 | SEXP ret_; 18 | // if (!isInteger(x_)) 19 | // error("x must be an integer vector"); 20 | // if (!isInteger(y_)) 21 | // error("y must be an integer vector"); 22 | K = LENGTH(x_); 23 | // if (LENGTH(y_) != K) error("x and y must be the same length"); 24 | 25 | x = INTEGER(x_); 26 | y = INTEGER(y_); 27 | 28 | n = 0; 29 | for (k=0; k=lim){ 44 | ret[i++] = val--; 45 | } 46 | } 47 | } 48 | UNPROTECT(1); 49 | return(ret_); 50 | } 51 | -------------------------------------------------------------------------------- /src/clone.c: -------------------------------------------------------------------------------- 1 | /* 2 | # cloning and identity querying 3 | # (c) 2014 Jens Oehlschlägel 4 | # Licence: GPL2 5 | # Provided 'as is', use at your own risk 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | 12 | SEXP R_duplicate(SEXP x_){ 13 | SEXP y_ = PROTECT(duplicate(x_)); 14 | UNPROTECT(1); 15 | return(y_); 16 | } 17 | -------------------------------------------------------------------------------- /src/merge.h: -------------------------------------------------------------------------------- 1 | /* 2 | # Fast methods for sorted integers 3 | # (c) 2016 - 2017 Jens Oehlschägel 4 | # Licence: GPL2 5 | # Provided 'as is', use at your own risk 6 | */ 7 | 8 | #ifndef ALREADY_DEFINED_merge 9 | #define ALREADY_DEFINED_merge 10 | 11 | #include 12 | //#include 13 | #include 14 | 15 | #undef DEBUG 16 | #define NDEBUG 1 17 | // #define DEBUG 18 | // #undef NDEBUG 19 | 20 | typedef int IndexT; 21 | typedef int ValueT; 22 | typedef struct RangeIndexTStruct { 23 | IndexT min; 24 | IndexT max; 25 | } RangeIndexT; 26 | 27 | #define MALLOC(n,typ) (typ *) R_Calloc((n),typ) 28 | #define FREE(x) R_Free(x) 29 | 30 | #ifdef NDEBUG 31 | #define assert(EX) ((void)0) 32 | #define debugprint(...)((void)0) 33 | #else 34 | #define assert(EX) (void)((EX) || (error("assert(" #EX ") file %s line %d", __FILE__, __LINE__), 0)) 35 | #define debugprint(...) {Rprintf( __VA_ARGS__); R_FlushConsole();} 36 | #endif /* NDEBUG */ 37 | 38 | #define ABS(X)(X) 39 | #define LT(A,B) (ABS(A) < ABS(B)) 40 | #define LE(A,B) (ABS(A) <= ABS(B)) 41 | #define GT(A, B) LT((B), (A)) 42 | #define GE(A, B) LE((B), (A)) 43 | #define EQ(A,B) (ABS(A) == ABS(B)) 44 | #define NE(A,B) (ABS(A) != ABS(B)) 45 | 46 | #define MOVE(TO,FROM) TO=FROM; 47 | #define EXCH(A,B,t) {MOVE(t,A) MOVE(A,B) MOVE(B,t)} 48 | #define COMPEXCH(A,B,t) if (LT(B,A)) EXCH(A,B,t) 49 | 50 | #define INSERTIONSORT_LIMIT 32 51 | 52 | 53 | void int_merge_match(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c, IndexT nomatch); 54 | void int_merge_in(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 55 | void int_merge_notin(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 56 | void int_merge_union_all(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 57 | int int_merge_union_exact(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 58 | int int_merge_union_unique(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 59 | int int_merge_intersect_exact(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 60 | int int_merge_intersect_unique(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 61 | int int_merge_symdiff_exact(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 62 | int int_merge_symdiff_unique(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 63 | int int_merge_setdiff_exact(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 64 | int int_merge_setdiff_unique(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 65 | int int_merge_setequal_exact(ValueT *a, IndexT na, ValueT *b, IndexT nb); 66 | int int_merge_setequal_unique(ValueT *a, IndexT na, ValueT *b, IndexT nb); 67 | int int_merge_posdiff_exact(IndexT na, ValueT *b, IndexT nb, ValueT *c); 68 | int int_merge_posdiff_unique(IndexT na, ValueT *b, IndexT nb, ValueT *c); 69 | int int_merge_negdiff_exact(IndexT na, ValueT *b, IndexT nb, ValueT *c); 70 | int int_merge_negdiff_unique(IndexT na, ValueT *b, IndexT nb, ValueT *c); 71 | 72 | void int_merge_match_revab(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c, IndexT nomatch); 73 | void int_merge_in_revab(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 74 | void int_merge_notin_revab(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 75 | void int_merge_union_all_revab(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 76 | int int_merge_union_exact_revab(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 77 | int int_merge_union_unique_revab(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 78 | int int_merge_intersect_exact_revab(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 79 | int int_merge_intersect_unique_revab(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 80 | int int_merge_symdiff_exact_revab(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 81 | int int_merge_symdiff_unique_revab(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 82 | int int_merge_setdiff_exact_revab(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 83 | int int_merge_setdiff_unique_revab(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 84 | int int_merge_setequal_exact_revab(ValueT *a, IndexT na, ValueT *b, IndexT nb); 85 | int int_merge_setequal_unique_revab(ValueT *a, IndexT na, ValueT *b, IndexT nb); 86 | int int_merge_posdiff_exact_revab(IndexT na, ValueT *b, IndexT nb, ValueT *c); 87 | int int_merge_posdiff_unique_revab(IndexT na, ValueT *b, IndexT nb, ValueT *c); 88 | int int_merge_negdiff_exact_revab(IndexT na, ValueT *b, IndexT nb, ValueT *c); 89 | int int_merge_negdiff_unique_revab(IndexT na, ValueT *b, IndexT nb, ValueT *c); 90 | 91 | void int_merge_match_reva(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c, IndexT nomatch); 92 | void int_merge_in_reva(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 93 | void int_merge_notin_reva(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 94 | void int_merge_union_all_reva(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 95 | int int_merge_union_exact_reva(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 96 | int int_merge_union_unique_reva(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 97 | int int_merge_intersect_exact_reva(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 98 | int int_merge_intersect_unique_reva(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 99 | int int_merge_symdiff_exact_reva(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 100 | int int_merge_symdiff_unique_reva(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 101 | int int_merge_setdiff_exact_reva(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 102 | int int_merge_setdiff_unique_reva(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 103 | int int_merge_setequal_exact_reva(ValueT *a, IndexT na, ValueT *b, IndexT nb); 104 | int int_merge_setequal_unique_reva(ValueT *a, IndexT na, ValueT *b, IndexT nb); 105 | int int_merge_posdiff_exact_reva(IndexT na, ValueT *b, IndexT nb, ValueT *c); 106 | int int_merge_posdiff_unique_reva(IndexT na, ValueT *b, IndexT nb, ValueT *c); 107 | int int_merge_negdiff_exact_reva(IndexT na, ValueT *b, IndexT nb, ValueT *c); 108 | int int_merge_negdiff_unique_reva(IndexT na, ValueT *b, IndexT nb, ValueT *c); 109 | 110 | void int_merge_match_revb(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c, IndexT nomatch); 111 | void int_merge_in_revb(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 112 | void int_merge_notin_revb(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 113 | void int_merge_union_all_revb(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 114 | int int_merge_union_exact_revb(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 115 | int int_merge_union_unique_revb(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 116 | int int_merge_intersect_exact_revb(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 117 | int int_merge_intersect_unique_revb(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 118 | int int_merge_symdiff_exact_revb(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 119 | int int_merge_symdiff_unique_revb(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 120 | int int_merge_setdiff_exact_revb(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 121 | int int_merge_setdiff_unique_revb(ValueT *a, IndexT na, ValueT *b, IndexT nb, ValueT *c); 122 | int int_merge_setequal_exact_revb(ValueT *a, IndexT na, ValueT *b, IndexT nb); 123 | int int_merge_setequal_unique_revb(ValueT *a, IndexT na, ValueT *b, IndexT nb); 124 | int int_merge_posdiff_exact_revb(IndexT na, ValueT *b, IndexT nb, ValueT *c); 125 | int int_merge_posdiff_unique_revb(IndexT na, ValueT *b, IndexT nb, ValueT *c); 126 | int int_merge_negdiff_exact_revb(IndexT na, ValueT *b, IndexT nb, ValueT *c); 127 | int int_merge_negdiff_unique_revb(IndexT na, ValueT *b, IndexT nb, ValueT *c); 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /src/range.c.h: -------------------------------------------------------------------------------- 1 | /* 2 | # Fast methods for sorted integers (where the first argument is a range) 3 | # (c) 2016 - 2017 Jens Oehlschägel 4 | # Licence: GPL2 5 | # Provided 'as is', use at your own risk 6 | */ 7 | 8 | #include "merge.h" 9 | 10 | #ifdef REV_B 11 | #ifdef REV_A 12 | #define FUNCNAME(NAME)NAME##_revab 13 | #else 14 | #define FUNCNAME(NAME)NAME##_revb 15 | #endif 16 | #else 17 | #ifdef REV_A 18 | #define FUNCNAME(NAME)NAME##_reva 19 | #else 20 | #define FUNCNAME(NAME)NAME 21 | #endif 22 | #endif 23 | 24 | #ifdef REV_A 25 | #define INIT_A(i,r) i=r[1] 26 | #define A_INC(i) i-- 27 | #define INC_A(i) --i 28 | #define A_MINUS + 29 | #define A_PLUS - 30 | #define DONE_A(i,r) (i < r[0]) 31 | #define STILL_A(i,r) (i >= r[0]) 32 | #define A(i)(-i) 33 | #else 34 | #define INIT_A(i,r) i=r[0] 35 | #define A_INC(i) i++ 36 | #define INC_A(i) ++i 37 | #define A_MINUS - 38 | #define A_PLUS + 39 | #define DONE_A(i,r) (i > r[1]) 40 | #define STILL_A(i,r) (i <= r[1]) 41 | #define A(i)i 42 | #endif 43 | 44 | #ifdef REV_B 45 | #define INIT_B(i,n) i=n-1 46 | #define B_INC(i) i-- 47 | #define INC_B(i) --i 48 | #define B_MINUS + 49 | #define B_PLUS - 50 | #define DONE_B(i,n) (i < 0) 51 | #define STILL_B(i,n) (i >= 0) 52 | #define B(i)(-b[i]) 53 | #else 54 | #define INIT_B(i,n) i=0 55 | #define B_INC(i) i++ 56 | #define INC_B(i) ++i 57 | #define B_MINUS - 58 | #define B_PLUS + 59 | #define DONE_B(i,n) (i >= nb) 60 | #define STILL_B(i,n) (i < nb) 61 | #define B(i)b[i] 62 | #endif 63 | 64 | 65 | ValueT FUNCNAME(int_merge_firstin)(IndexT *ra, ValueT *b, IndexT nb){ 66 | IndexT INIT_A(ia, ra), INIT_B(ib, nb), c=NA_INTEGER; 67 | if (ra[0]<=ra[1] && nb>0) for (;;){ 68 | if(LT(A(ia), B(ib))){ 69 | A_INC(ia); 70 | if DONE_A(ia, ra) 71 | break; 72 | }else{ 73 | if(LT(B(ib), A(ia))){ 74 | B_INC(ib); 75 | }else{ 76 | c = A(ia); 77 | break; 78 | } 79 | if DONE_B(ib, nb) 80 | break; 81 | } 82 | } 83 | return c; 84 | } 85 | 86 | ValueT FUNCNAME(int_merge_firstnotin)(IndexT *ra, ValueT *b, IndexT nb){ 87 | IndexT INIT_A(ia, ra), INIT_B(ib, nb), c=NA_INTEGER; 88 | if (ra[0]<=ra[1] && nb>0) for (;;){ 89 | if(LT(A(ia), B(ib))){ 90 | c = A(ia); 91 | goto done; 92 | }else{ 93 | if(LT(B(ib), A(ia))){ 94 | B_INC(ib); 95 | }else{ 96 | B_INC(ib); 97 | A_INC(ia); 98 | if DONE_A(ia, ra) 99 | goto done; 100 | } 101 | if DONE_B(ib, nb){ 102 | break; 103 | } 104 | } 105 | } 106 | if STILL_A(ia, ra){ 107 | c = A(ia); 108 | } 109 | done: 110 | return c; 111 | } 112 | 113 | int FUNCNAME(int_merge_rangesect)(IndexT *ra, ValueT *b, IndexT nb, ValueT *c){ 114 | IndexT INIT_A(ia, ra), INIT_B(ib, nb), ic=0; 115 | if (ra[0]<=ra[1] && nb>0) for (;;){ 116 | if(LT(A(ia), B(ib))){ 117 | A_INC(ia); 118 | if DONE_A(ia, ra) 119 | break; 120 | }else{ 121 | if(LT(B(ib), A(ia))){ 122 | B_INC(ib); 123 | }else{ 124 | c[ic++] = A(ia); 125 | B_INC(ib); 126 | A_INC(ia); 127 | if DONE_A(ia, ra) 128 | break; 129 | } 130 | if DONE_B(ib, nb) 131 | break; 132 | } 133 | } 134 | return ic; 135 | } 136 | 137 | 138 | int FUNCNAME(int_merge_rangediff)(IndexT *ra, ValueT *b, IndexT nb, ValueT *c){ 139 | IndexT INIT_A(ia, ra), INIT_B(ib, nb), ic=0; 140 | if (ra[0]<=ra[1] && nb>0) for (;;){ 141 | if(LT(A(ia), B(ib))){ 142 | c[ic++] = A(A_INC(ia)); 143 | if DONE_A(ia, ra) 144 | break; 145 | }else{ 146 | if(LT(B(ib), A(ia))){ 147 | B_INC(ib); 148 | }else{ 149 | B_INC(ib); 150 | A_INC(ia); 151 | if DONE_A(ia, ra) 152 | break; 153 | } 154 | if DONE_B(ib, nb) 155 | break; 156 | } 157 | } 158 | while STILL_A(ia, ra){ 159 | c[ic++] = A(A_INC(ia)); 160 | } 161 | return ic; 162 | } 163 | 164 | 165 | void FUNCNAME(int_merge_rangein)(ValueT *ra, ValueT *b, IndexT nb, ValueT *c){ 166 | IndexT INIT_A(ia, ra), INIT_B(ib, nb), ic=0; 167 | if (ra[0]<=ra[1] && nb>0) for (;;){ 168 | if(LT(B(ib), A(ia))){ 169 | B_INC(ib); 170 | if DONE_B(ib, nb) 171 | break; 172 | }else{ 173 | if(LT(A(ia), B(ib))){ 174 | c[ic++] = FALSE; 175 | }else{ 176 | c[ic++] = TRUE; 177 | } 178 | A_INC(ia); 179 | if DONE_A(ia, ra) 180 | break; 181 | } 182 | } 183 | while STILL_A(ia, ra){ 184 | c[ic++] = FALSE; 185 | A_INC(ia); 186 | } 187 | } 188 | 189 | 190 | void FUNCNAME(int_merge_rangenotin)(ValueT *ra, ValueT *b, IndexT nb, ValueT *c){ 191 | IndexT INIT_A(ia, ra), INIT_B(ib, nb), ic=0; 192 | if (ra[0]<=ra[1] && nb>0) for (;;){ 193 | if(LT(B(ib), A(ia))){ 194 | B_INC(ib); 195 | if DONE_B(ib, nb) 196 | break; 197 | }else{ 198 | if(LT(A(ia), B(ib))){ 199 | c[ic++] = TRUE; 200 | }else{ 201 | c[ic++] = FALSE; 202 | } 203 | A_INC(ia); 204 | if DONE_A(ia, ra) 205 | break; 206 | } 207 | } 208 | while STILL_A(ia, ra){ 209 | c[ic++] = TRUE; 210 | A_INC(ia); 211 | } 212 | } 213 | 214 | #undef INIT_A 215 | #undef A_INC 216 | #undef INC_A 217 | #undef A_MINUS 218 | #undef A_PLUS 219 | #undef DONE_A 220 | #undef STILL_A 221 | #undef A 222 | 223 | #undef INIT_B 224 | #undef B_INC 225 | #undef INC_B 226 | #undef B_MINUS 227 | #undef B_PLUS 228 | #undef DONE_B 229 | #undef STILL_B 230 | #undef B 231 | 232 | #undef FUNCNAME 233 | 234 | -------------------------------------------------------------------------------- /src/rle.c: -------------------------------------------------------------------------------- 1 | /* 2 | # fast rle handling for bit and ff 3 | # (c) 2007-2009 Jens Oehlschägel 4 | # Licence: GPL2 5 | # Provided 'as is', use at your own risk 6 | # Created: 2007-08-24 7 | # Last changed: 2007-11-29 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | /* returns position of first zero found */ 14 | SEXP R_first_zero(SEXP x) 15 | { 16 | int i; 17 | int n = LENGTH(x); 18 | int *p = INTEGER(x); 19 | SEXP ret_; 20 | PROTECT( ret_ = allocVector(INTSXP, 1) ); 21 | INTEGER(ret_)[0] = 0; 22 | if (n){ 23 | for (i=0;ip[i-1]){ 131 | status = FALSE; 132 | break; 133 | } 134 | } 135 | } 136 | 137 | INTEGER(ret_)[0] = status; 138 | UNPROTECT(1); 139 | return ret_; 140 | } 141 | 142 | SEXP R_int_is_desc_skip(SEXP x) 143 | { 144 | Rboolean status=TRUE; 145 | register int i, last=NA_INTEGER; // assignment to keep compiler quiet 146 | int n = LENGTH(x); 147 | int *p = INTEGER(x); 148 | SEXP ret_; 149 | PROTECT( ret_ = allocVector(LGLSXP, 1) ); 150 | 151 | if (n){ 152 | for (i=0;ilast){ 161 | status = FALSE; 162 | break; 163 | } 164 | last = p[i]; 165 | } 166 | } 167 | } 168 | 169 | INTEGER(ret_)[0] = status; 170 | UNPROTECT(1); 171 | return ret_; 172 | } 173 | 174 | 175 | SEXP R_int_is_desc_break(SEXP x) 176 | { 177 | Rboolean status=TRUE; 178 | int i; 179 | int n = LENGTH(x); 180 | int *p = INTEGER(x); 181 | SEXP ret_; 182 | PROTECT( ret_ = allocVector(LGLSXP, 1) ); 183 | 184 | if (n){ 185 | if (p[0]==NA_INTEGER){ 186 | status=NA_LOGICAL; 187 | }else{ 188 | for (i=1;ip[i-1]){ 193 | status = FALSE; 194 | } 195 | } 196 | } 197 | } 198 | 199 | INTEGER(ret_)[0] = status; 200 | UNPROTECT(1); 201 | return ret_; 202 | } 203 | 204 | 205 | 206 | /* create integer rle 207 | NOTE if rle is not efficient we return NULL instead of an rle object 208 | */ 209 | SEXP R_int_rle(SEXP x_) 210 | { 211 | register int lv,ln,i,c=0; 212 | int n2, n = LENGTH(x_); 213 | if (n<3) 214 | return R_NilValue; 215 | n2 = n / 3; /* xx EXPLANATION: max RAM requirement 2x, but rle only if at least 2/3 savings, using 2 instead of 3 would need 50% more time, have max RAM requirement 2.5x for savings of any size */ 216 | 217 | int *x = INTEGER(x_); 218 | int *val, *len, *values, *lengths; 219 | SEXP ret_, lengths_, values_, names_, class_; 220 | 221 | val = R_Calloc(n2, int); 222 | len = R_Calloc(n2, int); 223 | if (n){ 224 | lv = x[0]; 225 | ln = 1; 226 | for (i=1;i= n); \ 14 | return r; \ 15 | } 16 | 17 | static RANDINDEX(randIndex) 18 | 19 | 20 | #define INSERTIONSORT(funcnam) void funcnam ( \ 21 | ValueT *x \ 22 | , IndexT l \ 23 | , IndexT r \ 24 | ) \ 25 | { \ 26 | IndexT i; \ 27 | ValueT t; \ 28 | for (i=r;i>l;i--){ \ 29 | if (LT(x[i],x[i-1])) { \ 30 | EXCH(x[i-1],x[i],t); \ 31 | } \ 32 | } \ 33 | for (i=l+2;i<=r;i++){ \ 34 | IndexT j=i; \ 35 | ValueT v; \ 36 | MOVE(v, x[i]) \ 37 | while (LT(v,x[j-1])){ \ 38 | MOVE(x[j], x[j-1]) \ 39 | j--; \ 40 | } \ 41 | MOVE(x[j], v) \ 42 | } \ 43 | } 44 | 45 | INSERTIONSORT(int_insertionsort) 46 | 47 | void int_quicksort2(ValueT *x, IndexT l, IndexT r) 48 | { 49 | #if INSERTIONSORT_LIMIT > 0 50 | if (r - l < INSERTIONSORT_LIMIT){ 51 | int_insertionsort(x, l, r); 52 | return; 53 | } 54 | #else 55 | if (l >= r) 56 | return; 57 | #endif 58 | IndexT j, i = l+randIndex(r-l+1); 59 | ValueT t, v; 60 | EXCH(x[i], x[r], v); // first argument pivot now in v and x[r] 61 | i = l-1; j = r; 62 | for (;;){ 63 | while (LT(x[++i], v)); // sentinel stop of for loop 64 | while (LT(v, x[--j])){ 65 | if (j <= i) // explicit stop of for loop 66 | break; 67 | } 68 | if (j <= i) 69 | break; 70 | EXCH(x[i], x[j], t); 71 | } 72 | EXCH(x[i], x[r], t); 73 | int_quicksort2(x, l, i-1); 74 | int_quicksort2(x, i+1, r); 75 | } 76 | 77 | 78 | void int_quicksort3(ValueT *x, IndexT l, IndexT r) 79 | { 80 | #if INSERTIONSORT_LIMIT > 0 81 | if (r - l < INSERTIONSORT_LIMIT){ 82 | int_insertionsort(x, l, r); 83 | return; 84 | } 85 | #else 86 | if (l >= r) 87 | return; 88 | #endif 89 | IndexT k, p, q, j, i = l+randIndex(r-l+1); 90 | ValueT t, v; 91 | EXCH(x[i], x[r], v); // first argument pivot now in v and x[r] 92 | i = p = l-1; j = q = r; 93 | for (;;){ 94 | while (LT(x[++i],v)); // sentinel stop of for loop 95 | while (LT(v,x[--j])) if (j <= i) break; // explicit stop of for loop 96 | if (j <= i) break; 97 | EXCH(x[i], x[j], t); 98 | if (EQ(x[i],v)) {++p; EXCH(x[p], x[i],t);} 99 | if (EQ(v,x[j])) {--q; EXCH(x[j], x[q], t);} 100 | } 101 | EXCH(x[i], x[r], t); 102 | j = i-1; i = i+1; 103 | for (k = l; k < p; k++, j--) EXCH(x[k], x[j], t); 104 | for (k = r-1; k > q; k--, i++) EXCH(x[i], x[k], t); 105 | int_quicksort3(x, l, j); 106 | int_quicksort3(x, i, r); 107 | } 108 | 109 | 110 | void int_countsort( 111 | IndexT *x 112 | , IndexT *count 113 | , IndexT *range 114 | , IndexT l, IndexT r 115 | ) 116 | { 117 | IndexT i, v, lim; 118 | IndexT nrange = range[1] - range[0] + 1; 119 | // initialize counter 120 | for (i=0;i 1) 21 | x <- sample(x) 22 | 23 | range_result <- suppressWarnings(as.integer(c(range(x, na.rm=TRUE), sum(is.na(x))))) 24 | expect_identical( 25 | range_na(x), 26 | range_result, 27 | label=paste0("range_na(c(", toString(x), "))") 28 | ) 29 | 30 | range_result <- suppressWarnings(as.integer(c( 31 | range(x[is.na(x) | x != 0], na.rm=TRUE), 32 | sum(is.na(x)) 33 | ))) 34 | expect_identical( 35 | attr(range_nanozero(x), "range_na"), 36 | range_result, 37 | label=paste0("range_na(c(", toString(x), ")") 38 | ) 39 | 40 | for (na.last in c(NA, FALSE, TRUE)) { 41 | expected = range_sortna(x, na.last=na.last) 42 | expected[!is.na(expected)] = 1L 43 | 44 | actual = sort.int(x, na.last=na.last, method='quick') 45 | r = range_na(actual) 46 | r[4L] = is.unsorted(x, na.rm=TRUE) 47 | actual[!is.na(actual)] = 1L 48 | attr(actual, "range_sortna") = r 49 | expect_identical( 50 | expected, actual, 51 | label=sprintf("range_sortna(c(%s), na.last=%s)", toString(x), na.last) 52 | ) 53 | 54 | expect_identical( 55 | bit_sort_unique(x, na.last=na.last, has.dup = TRUE), 56 | sort.int(unique(x), na.last=na.last, method="quick"), 57 | label=sprintf("bit_sort_unique(c(%s), na.last=%s, has.dup=TRUE)", toString(x), na.last) 58 | ) 59 | 60 | y <- unique(x) 61 | expect_identical( 62 | bit_sort_unique(y, na.last=na.last, has.dup = FALSE), 63 | sort.int(y, na.last=na.last, method="quick"), 64 | label=sprintf("bit_sort_unique(c(%s), na.last=%s, has.dup=FALSE)", toString(x), na.last) 65 | ) 66 | 67 | expect_identical( 68 | bit_sort(x, na.last=na.last), 69 | sort.int(x, na.last=na.last, method="quick"), 70 | label=paste0("bit_sort(c(", toString(x), "), na.last=", na.last, ")") 71 | ) 72 | } 73 | 74 | expect_identical( 75 | bit_unique(x, na.rm=NA), 76 | unique(x, incomparables=FALSE), 77 | label=paste0("bit_unique(c(", toString(x), "), na.rm=", NA, ")") 78 | ) 79 | expect_identical( 80 | bit_unique(x, na.rm=FALSE), 81 | unique(x, incomparables=NA), 82 | label=paste0("bit_unique(c(", toString(x), "), na.rm=", FALSE, ")") 83 | ) 84 | expect_identical( 85 | bit_unique(x, na.rm=TRUE), 86 | unique(x[!is.na(x)]), 87 | label=paste0("bit_unique(c(", toString(x), "), na.rm=", TRUE, ")") 88 | ) 89 | 90 | expect_identical( 91 | bit_duplicated(x, na.rm=NA), 92 | as.bit(duplicated(x, incomparables=FALSE)), 93 | label=paste0("bit_duplicated(c(", toString(x), "), na.rm=", NA, ")") 94 | ) 95 | expect_identical( 96 | bit_duplicated(x, na.rm=FALSE), 97 | as.bit(duplicated(x, incomparables=NA)), 98 | label=paste0("bit_duplicated(c(", toString(x), "), na.rm=", FALSE, ")") 99 | ) 100 | expect_identical( 101 | bit_duplicated(x, na.rm=TRUE), 102 | as.bit(duplicated(x) | is.na(x)), 103 | label=paste0("bit_duplicated(c(", toString(x), "), na.rm=", TRUE, ")") 104 | ) 105 | 106 | expect_identical( 107 | bit_anyDuplicated(x, na.rm=NA), 108 | anyDuplicated(x, incomparables=FALSE), 109 | label=paste0("bit_anyDuplicated(c(", toString(x), "), na.rm=", NA, ")") 110 | ) 111 | expect_identical( 112 | bit_anyDuplicated(x, na.rm=FALSE), 113 | anyDuplicated(x, incomparables=NA), 114 | label=paste0("bit_anyDuplicated(c(", toString(x), "), na.rm=", FALSE, ")") 115 | ) 116 | expect_identical( 117 | bit_anyDuplicated(x, na.rm=TRUE), 118 | max(0L, head(which(is.na(x) | duplicated(x)), 1)), 119 | label=paste0("bit_anyDuplicated(c(", toString(x), "), na.rm=", TRUE, ")") 120 | ) 121 | 122 | expect_identical( 123 | bit_sumDuplicated(x, na.rm=NA), 124 | sum(duplicated(x, incomparables=FALSE)), 125 | label=paste0("bit_sumDuplicated(c(", toString(x), "))") 126 | ) 127 | expect_identical( 128 | bit_sumDuplicated(x, na.rm=FALSE), 129 | sum(duplicated(x, incomparables=NA)), 130 | label=paste0("bit_sumDuplicated(c(", toString(x), "))") 131 | ) 132 | expect_identical( 133 | bit_sumDuplicated(x, na.rm=TRUE), 134 | sum(duplicated(x, incomparables=NA)) + sum(is.na(x)), 135 | label=paste0("bit_sumDuplicated(c(", toString(x), "))") 136 | ) 137 | 138 | } 139 | } 140 | 141 | }) 142 | 143 | 144 | test_that("bit_sort and bit_sort_unique are OK", { 145 | n <- 6L 146 | for (s in 1:10) { 147 | set.seed(s) 148 | x <- 2L * sample(n, replace=TRUE) 149 | for (napos in c(-1L, 0L, 1L)) { 150 | if (napos == -1) { 151 | y <- c(NA, x) 152 | } else if (napos == 1) { 153 | y <- c(x, NA) 154 | } else { 155 | y <- c(x[1:(n %/% 2)], NA, x[(n %/% 2 + 1L):n]) 156 | } 157 | for (has.dup in c(TRUE, FALSE)) { 158 | if (!has.dup) 159 | y <- unique(y) 160 | for (na.last in c(NA, FALSE, TRUE)) { 161 | eval(substitute( 162 | expect_identical( 163 | bit_sort(y, na.last=na.last, has.dup = has.dup), 164 | sort(y, na.last = na.last) 165 | ), 166 | list( 167 | y=y, 168 | na.last=na.last, 169 | has.dup = has.dup 170 | ) 171 | )) 172 | for (decreasing in c(FALSE, TRUE)) { 173 | eval(substitute( 174 | expect_identical( 175 | bit_sort_unique(y, decreasing=decreasing, na.last=na.last, has.dup = has.dup), 176 | sort(unique(y), decreasing=decreasing, na.last = na.last) 177 | ), 178 | list( 179 | y=y, 180 | decreasing=decreasing, 181 | na.last=na.last, 182 | has.dup = has.dup 183 | ) 184 | )) 185 | range_na = range_na(y) 186 | env = list( 187 | y=y, 188 | decreasing=decreasing, 189 | na.last=na.last, 190 | has.dup = has.dup, 191 | range_na = range_na 192 | ) 193 | eval(substitute(env = env, { 194 | expect_identical( 195 | bit_sort_unique(y, 196 | decreasing=decreasing, 197 | na.last=na.last, 198 | has.dup=has.dup, 199 | range_na=range_na 200 | ), 201 | sort(unique(y), 202 | decreasing=decreasing, 203 | na.last=na.last 204 | ) 205 | ) 206 | })) 207 | } 208 | } 209 | } 210 | } 211 | } 212 | }) 213 | 214 | test_that("bit_setops work", { 215 | x = 1:5 216 | y = 2:6 217 | x_na = c(x, NA_integer_) 218 | y_na = c(y, NA_integer_) 219 | 220 | expect_identical(bit_setdiff(x, y), 1L) 221 | expect_identical(bit_setdiff(x_na, y), c(1L, NA_integer_)) 222 | expect_identical(bit_setdiff(x, y_na), 1L) 223 | expect_identical(bit_setdiff(x_na, y_na), 1L) 224 | 225 | expect_identical(bit_symdiff(x, y), c(1L, 6L)) 226 | expect_identical(bit_symdiff(x_na, y), c(1L, NA_integer_, 6L)) 227 | expect_identical(bit_symdiff(x, y_na), c(1L, 6L, NA_integer_)) 228 | expect_identical(bit_symdiff(x_na, y_na), c(1L, 6L)) 229 | 230 | expect_identical(bit_intersect(x, y), 2:5) 231 | expect_identical(bit_intersect(x_na, y), 2:5) 232 | expect_identical(bit_intersect(x, y_na), 2:5) 233 | expect_identical(bit_intersect(x_na, y_na), c(2:5, NA_integer_)) 234 | 235 | expect_identical(bit_union(x, y), 1:6) 236 | expect_identical(bit_union(x_na, y), c(1:5, NA_integer_, 6L)) 237 | expect_identical(bit_union(x, y_na), c(1:6, NA_integer_)) 238 | expect_identical(bit_union(x_na, y_na), c(1:5, NA_integer_, 6L)) 239 | 240 | expect_false(bit_setequal(x, y)) 241 | expect_false(bit_setequal(x_na, y)) 242 | expect_false(bit_setequal(x, y_na)) 243 | expect_false(bit_setequal(x_na, y_na)) 244 | expect_true(bit_setequal(x, x)) 245 | expect_true(bit_setequal(x_na, x_na)) 246 | 247 | expect_identical(bit_rangediff(c(1L, 6L), c(3L, 4L)), c(1:2, 5:6)) 248 | expect_identical(bit_rangediff(c(1L, 6L), c(3L, 4L), revx=TRUE), -(6:1)) 249 | expect_identical(bit_rangediff(c(1L, 6L), c(3L, 4L), revy=TRUE), 1:6) 250 | expect_identical(bit_rangediff(c(1L, 6L), c(3L, 4L), revx=TRUE, revy=TRUE), -c(6:5, 2:1)) 251 | expect_identical(bit_rangediff(c(6L, 1L), c(3L, 4L), revx=TRUE), -(1:6)) 252 | expect_identical(bit_rangediff(c(6L, 1L), c(3L, 4L), revy=TRUE), 6:1) 253 | expect_identical(bit_rangediff(c(6L, 1L), c(3L, 4L), revx=TRUE, revy=TRUE), -c(1:2, 5:6)) 254 | }) 255 | 256 | test_that("bitsort works", { 257 | expect_identical(bitsort(c(2L, 0L, 1L, NA, 2L)), c(0:2, 2L)) 258 | expect_identical(bitsort(c(2L, 0L, 1L, NA, 2L), na.last=TRUE), c(0:2, 2L, NA)) 259 | }) 260 | 261 | test_that("bit_in works", { 262 | x = 1:5 263 | y = 3:6 264 | x_na = c(x, NA) 265 | y_na = c(y, NA) 266 | 267 | expect_identical(bit_in(x, y), as.bit(x %in% y)) 268 | expect_identical(bit_in(y, x), as.bit(y %in% x)) 269 | expect_identical(bit_in(x_na, y), as.bit(x_na %in% y)) 270 | expect_identical(bit_in(y, x), as.bit(y %in% x_na)) 271 | expect_identical(bit_in(x, y_na), as.bit(x %in% y_na)) 272 | expect_identical(bit_in(y_na, x), as.bit(y_na %in% x)) 273 | expect_identical(bit_in(x_na, y_na), as.bit(x_na %in% y_na)) 274 | expect_identical(bit_in(y_na, x_na), as.bit(y_na %in% x_na)) 275 | }) 276 | -------------------------------------------------------------------------------- /tests/testthat/test-merge.R: -------------------------------------------------------------------------------- 1 | # map NAs to position 1 2 | NAtab <- function(x, nbins=max(1L, x, na.rm = TRUE)) { 3 | force(nbins) 4 | x <- x + 1L 5 | x[is.na(x)] <- 1L 6 | tabulate(x, nbins + 1L) 7 | } 8 | 9 | test_that("positive merging is OK with NAs", { 10 | xs <- list( 11 | rep(3:7, rep(1L, 5L)), 12 | rep(3:7, rep(2L, 5L)), 13 | rep(c(3L, 5L, 7L), rep(1L, 3L)), 14 | rep(c(3L, 5L, 7L), rep(2L, 3L)) 15 | ) 16 | ys <- list( 17 | rep(1:9, rep(1L, 9L)), 18 | rep(1:9, rep(2L, 9L)), 19 | rep(2:8, rep(1L, 7L)), 20 | rep(2:8, rep(2L, 7L)), 21 | rep(3:7, rep(1L, 5L)), 22 | rep(3:7, rep(2L, 5L)), 23 | rep(c(3L, 5L, 7L), rep(1L, 3L)), 24 | rep(c(3L, 5L, 7L), rep(2L, 3L)), 25 | rep(4:6, rep(1L, 3L)), 26 | rep(4:6, rep(2L, 3L)), 27 | rep(5L, 1L), 28 | rep(5L, 2L), 29 | rep(5L, 3L), 30 | rep(1L, 1L), 31 | rep(1L, 1L), 32 | rep(1L, 2L), 33 | rep(1:2, rep(1L, 2L)), 34 | rep(1:2, rep(2L, 2L)), 35 | rep(1:3, rep(1L, 3L)), 36 | rep(1:3, rep(2L, 3L)), 37 | rep(1:4, rep(1L, 4L)), 38 | rep(1:4, rep(2L, 4L)), 39 | rep(1:5, rep(1L, 5L)), 40 | rep(1:5, rep(2L, 5L)), 41 | rep(5:9, rep(1L, 5L)), 42 | rep(5:9, rep(2L, 5L)), 43 | rep(6:9, rep(1L, 4L)), 44 | rep(6:9, rep(2L, 4L)), 45 | rep(7:9, rep(1L, 3L)), 46 | rep(7:9, rep(2L, 3L)), 47 | rep(8:9, rep(1L, 2L)), 48 | rep(8:9, rep(2L, 2L)), 49 | rep(9L, 1L), 50 | rep(9L, 1L), 51 | rep(9L, 2L) 52 | ) 53 | for (xi in seq_along(xs)) { 54 | for (yi in seq_along(ys)) { 55 | x <- sort.int(xs[[xi]], na.last=FALSE, method="quick") 56 | y <- sort.int(ys[[yi]], na.last=FALSE, method="quick") 57 | env = list(x=x, y=y) 58 | eval(substitute(env=env, expect_identical( 59 | merge_union(x, y, method="all"), 60 | sort.int(c(x, y), na.last=FALSE, method="quick") 61 | ))) 62 | eval(substitute(env=env, expect_identical( 63 | merge_union(x, y, method="exact"), 64 | rep(c(NA, 1:9), pmax(NAtab(x, 9), NAtab(y, 9))) 65 | ))) 66 | eval(substitute(env=env, expect_identical( 67 | merge_intersect(x, y, method="exact"), 68 | rep(c(NA, 1:9), pmin(NAtab(x, 9), NAtab(y, 9))) 69 | ))) 70 | eval(substitute(env=env, expect_identical( 71 | merge_setdiff(x, y, method="exact"), 72 | rep(c(NA, 1:9), pmax(0L, NAtab(x, 9) - NAtab(y, 9))) 73 | ))) 74 | eval(substitute(env=env, expect_identical( 75 | merge_symdiff(x, y, method="exact"), 76 | rep(c(NA, 1:9), abs(NAtab(x, 9) - NAtab(y, 9))) 77 | ))) 78 | eval(substitute(env=env, expect_identical( 79 | merge_union(x, y), 80 | sort.int(union(x, y), na.last=FALSE, method="quick") 81 | ))) 82 | eval(substitute(env=env, expect_identical( 83 | merge_intersect(x, y), 84 | sort.int(intersect(x, y), na.last=FALSE, method="quick") 85 | ))) 86 | eval(substitute(env=env, expect_identical( 87 | merge_setdiff(x, y), 88 | sort.int(setdiff(x, y), na.last=FALSE, method="quick") 89 | ))) 90 | eval(substitute(env=env, expect_identical( 91 | merge_symdiff(x, y), 92 | sort.int(union(setdiff(x, y), setdiff(y, x)), na.last=FALSE, method="quick") 93 | ))) 94 | } 95 | } 96 | }) 97 | 98 | 99 | test_that("reversed merging is OK (without NAs)", { 100 | set.seed(1) 101 | for (i in 1:24) { 102 | x <- sort.int(sample(9, replace=TRUE), na.last=FALSE, method="quick") 103 | y <- sort.int(sample(9, replace=TRUE), na.last=FALSE, method="quick") 104 | for (revx in c(FALSE, TRUE)) { 105 | if (revx) 106 | rx <- rev(-x) 107 | else 108 | rx <- x 109 | for (revy in c(FALSE, TRUE)) { 110 | if (revy) 111 | ry <- rev(-y) 112 | else 113 | ry <- y 114 | eval(substitute(expect_identical( 115 | merge_union(rx, ry, revx=revx, revy=revy, method="all") 116 | , sort.int(c(x, y), na.last=FALSE, method="quick") 117 | ), list(x=x, y=y, revx=revx, revy=revy))) 118 | eval(substitute(expect_identical( 119 | merge_union(rx, ry, revx=revx, revy=revy, method="exact") 120 | , rep(c(NA, 1:9), pmax(NAtab(x, 9), NAtab(y, 9))) 121 | ), list(x=x, y=y, revx=revx, revy=revy))) 122 | eval(substitute(expect_identical( 123 | merge_intersect(rx, ry, revx=revx, revy=revy, method="exact") 124 | , rep(c(NA, 1:9), pmin(NAtab(x, 9), NAtab(y, 9))) 125 | ), list(x=x, y=y, revx=revx, revy=revy))) 126 | eval(substitute(expect_identical( 127 | merge_setdiff(rx, ry, revx=revx, revy=revy, method="exact") 128 | , rep(c(NA, 1:9), pmax(0L, NAtab(x, 9) - NAtab(y, 9))) 129 | ), list(x=x, y=y, revx=revx, revy=revy))) 130 | eval(substitute(expect_identical( 131 | merge_symdiff(rx, ry, revx=revx, revy=revy, method="exact") 132 | , rep(c(NA, 1:9), abs(NAtab(x, 9) - NAtab(y, 9))) 133 | ), list(x=x, y=y, revx=revx, revy=revy))) 134 | eval(substitute(expect_identical( 135 | merge_union(rx, ry, revx=revx, revy=revy) 136 | , sort.int(union(x, y), na.last=FALSE, method="quick") 137 | ), list(x=x, y=y, revx=revx, revy=revy))) 138 | eval(substitute(expect_identical( 139 | merge_intersect(rx, ry, revx=revx, revy=revy) 140 | , sort.int(intersect(x, y), na.last=FALSE, method="quick") 141 | ), list(x=x, y=y, revx=revx, revy=revy))) 142 | eval(substitute(expect_identical( 143 | merge_setdiff(rx, ry, revx=revx, revy=revy) 144 | , sort.int(setdiff(x, y), na.last=FALSE, method="quick") 145 | ), list(x=x, y=y, revx=revx, revy=revy))) 146 | eval(substitute(expect_identical( 147 | merge_symdiff(rx, ry, revx=revx, revy=revy) 148 | , sort.int(union(setdiff(x, y), setdiff(y, x)), na.last=FALSE, method="quick") 149 | ), list(x=x, y=y, revx=revx, revy=revy))) 150 | 151 | } 152 | } 153 | } 154 | 155 | }) 156 | 157 | 158 | test_that("for-looped merging is OK (without NAs)", { 159 | nx <- 9 160 | x <- 1:nx 161 | set.seed(1) 162 | for (i in 1:12) { 163 | y <- sort.int(sample(nx, replace=TRUE), na.last=FALSE, method="quick") 164 | for (revx in c(FALSE, TRUE)) { 165 | if (revx) { 166 | rx <- rev(-x) 167 | rnx <- c(-nx, -1L) 168 | } else { 169 | rx <- x 170 | rnx <- c(1L, nx) 171 | } 172 | for (revy in c(FALSE, TRUE)) { 173 | if (revy) { 174 | ry <- rev(-y) 175 | } else { 176 | ry <- y 177 | } 178 | eval(substitute(expect_identical( 179 | merge_rangesect(rnx, ry, revx=revx, revy=revy) 180 | , merge_intersect(rx, ry, revx=revx, revy=revy) 181 | ), list(rnx=rnx, rx=rx, ry=ry, revx=revx, revy=revy))) 182 | eval(substitute(expect_identical( 183 | merge_rangediff(rnx, ry, revx=revx, revy=revy) 184 | , merge_setdiff(rx, ry, revx=revx, revy=revy) 185 | ), list(rnx=rnx, rx=rx, ry=ry, revx=revx, revy=revy))) 186 | eval(substitute(expect_identical( 187 | merge_rangein(rnx, ry, revx=revx, revy=revy) 188 | , copy_vector(rx, revx=revx) %in% copy_vector(ry, revx=revy) 189 | ), list(rnx=rnx, rx=rx, ry=ry, revx=revx, revy=revy))) 190 | eval(substitute(expect_identical( 191 | merge_rangenotin(rnx, ry, revx=revx, revy=revy) 192 | , !(copy_vector(rx, revx=revx) %in% copy_vector(ry, revx=revy)) 193 | ), list(rnx=rnx, rx=rx, ry=ry, revx=revx, revy=revy))) 194 | } 195 | } 196 | } 197 | 198 | }) 199 | -------------------------------------------------------------------------------- /tests/testthat/test-rle.R: -------------------------------------------------------------------------------- 1 | test_that("intisasc is correct", { 2 | expect_true(intisasc(c(as.integer(NA, NA)), "none")) 3 | expect_true(intisasc(c(NA, 1L), "none")) 4 | expect_true(intisasc(c(1L, 1L), "none")) 5 | expect_false(intisasc(c(1L, NA), "none")) 6 | expect_true(intisasc(c(NA, 1L, NA, 2L, NA), "skip")) 7 | expect_true(intisasc(c(NA, 1L, NA, 1L, NA), "skip")) 8 | expect_false(intisasc(c(NA, 2L, NA, 1L, NA), "skip")) 9 | expect_identical(intisasc(c(1L, NA, 2L), "break"), NA) 10 | expect_true(intisasc(c(1L, 2L), "break")) 11 | expect_true(intisasc(c(1L, 1L), "break")) 12 | expect_false(intisasc(c(2L, 1L), "break")) 13 | expect_true(intisasc(c(1L, 2L))) 14 | expect_true(intisasc(c(1L, 1L))) 15 | expect_false(intisasc(c(2L, 1L))) 16 | }) 17 | 18 | test_that("intisdesc is correct", { 19 | expect_true(intisdesc(c(as.integer(NA, NA)), "none")) 20 | expect_false(intisdesc(c(NA, 1L), "none")) 21 | expect_true(intisdesc(c(1L, 1L), "none")) 22 | expect_true(intisdesc(c(1L, NA), "none")) 23 | expect_false(intisdesc(c(NA, 1L, NA, 2L, NA), "skip")) 24 | expect_true(intisdesc(c(NA, 1L, NA, 1L, NA), "skip")) 25 | expect_true(intisdesc(c(NA, 2L, NA, 1L, NA), "skip")) 26 | expect_identical(intisdesc(c(1L, NA, 2L), "break"), NA) 27 | expect_false(intisdesc(c(1L, 2L), "break")) 28 | expect_true(intisdesc(c(1L, 1L), "break")) 29 | expect_true(intisdesc(c(2L, 1L), "break")) 30 | expect_true(intisdesc(c(as.integer(NA, NA)))) 31 | expect_false(intisdesc(c(NA, 1L))) 32 | expect_true(intisdesc(c(1L, 1L))) 33 | expect_true(intisdesc(c(1L, NA))) 34 | }) 35 | 36 | test_that("intrle is correct", { 37 | x = c(rep(1L, 60), 1:30) 38 | expect_identical(intrle(x), rle(x)) 39 | expect_null(intrle(c(rep(1L, 60), 1:31))) 40 | }) 41 | 42 | test_that("rlepack, rleunpack, and rlepack methods for rev, uniqu and anyDuplicated work", { 43 | inputs = list( 44 | 10:1, 45 | 1:10, 46 | c(10:1, 1:10), 47 | c(1:10, 10:1), 48 | sample(100), 49 | sample(100, 100, TRUE), 50 | sample(10, 100, TRUE) 51 | ) 52 | for (x in inputs) { 53 | expect_identical(rleunpack(rlepack(x)), x) 54 | expect_identical(rleunpack(rev(rlepack(x))), rev(x)) 55 | expect_identical(rleunpack(unique(rlepack(x))), unique(x)) 56 | expect_identical(anyDuplicated(rlepack(x)), anyDuplicated(x)) 57 | } 58 | }) 59 | -------------------------------------------------------------------------------- /vignettes/bit-demo.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Demo of the bit package" 3 | author: "Dr. Jens Oehlschlägel" 4 | date: '`r Sys.Date()`' 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{Demo of the bit package} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r, echo = FALSE, results = "hide", message = FALSE} 13 | knitr::opts_chunk$set(collapse = TRUE, comment = "#>") 14 | library(bit) 15 | .ff.is.available = requireNamespace("ff", quietly=TRUE) && packageVersion("ff") >= "4.0.0" 16 | if (.ff.is.available) library(ff) 17 | #tools::buildVignette("vignettes/bit-demo.Rmd") 18 | #devtools::build_vignettes() 19 | ``` 20 | 21 | --- 22 | 23 | ## bit type 24 | 25 | Create a huge boolean vector (no NAs allowed) 26 | 27 | ```{r} 28 | n <- 1e8 29 | b1 <- bit(n) 30 | b1 31 | ``` 32 | 33 | It costs only one bit per element 34 | 35 | ```{r} 36 | object.size(b1) / n 37 | ``` 38 | 39 | 40 | A couple of standard methods work 41 | 42 | ```{r} 43 | b1[10:30] <- TRUE 44 | summary(b1) 45 | ``` 46 | 47 | Create a another boolean vector with TRUE in some different positions 48 | 49 | ```{r} 50 | b2 <- bit(n) 51 | b2[20:40] <- TRUE 52 | b2 53 | ``` 54 | 55 | fast boolean operations 56 | 57 | ```{r} 58 | b1 & b2 59 | ``` 60 | 61 | fast boolean operations 62 | 63 | ```{r} 64 | summary(b1 & b2) 65 | ``` 66 | 67 | 68 | ## bitwhich type 69 | 70 | Since we have a very skewed distribution we may coerce to an even sparser representation 71 | 72 | ```{r} 73 | w1 <- as.bitwhich(b1) 74 | w2 <- as.bitwhich(b2) 75 | object.size(w1) / n 76 | ``` 77 | 78 | and everything 79 | 80 | ```{r} 81 | w1 & w2 82 | ``` 83 | 84 | works as expected 85 | 86 | ```{r} 87 | summary(w1 & w2) 88 | ``` 89 | 90 | 91 | even mixing 92 | 93 | ```{r} 94 | summary(b1 & w2) 95 | ``` 96 | 97 | 98 | ## processing chunks 99 | 100 | Many bit functions support a range restriction, 101 | 102 | ```{r} 103 | summary(b1, range=c(1, 1000)) 104 | ``` 105 | 106 | which is useful 107 | 108 | ```{r} 109 | as.which(b1, range=c(1, 1000)) 110 | ``` 111 | 112 | for filtered chunked looping 113 | 114 | ```{r} 115 | lapply(chunk(from=1, to=n, length=10), function(i) as.which(b1, range=i)) 116 | ``` 117 | 118 | over large ff vectors 119 | 120 | ```{r, eval=.ff.is.available} 121 | options(ffbatchbytes=1024^3) 122 | x <- ff(vmode="single", length=n) 123 | x[1:1000] <- runif(1000) 124 | lapply(chunk(x, length.out = 10), function(i) sum(x[as.hi(b1, range=i)])) 125 | ``` 126 | 127 | and wrap-up 128 | 129 | ```{r, eval=.ff.is.available} 130 | delete(x) 131 | rm(x, b1, b2, w1, w2, n) 132 | ``` 133 | 134 | for more info check the usage vignette 135 | --------------------------------------------------------------------------------