A bitwhich object represents a boolean filter like a bit() object (NAs are not allowed) but uses a sparse representation suitable for very skewed (asymmetric) selections. Three extreme cases are represented with logical values, no length via logical(), all TRUE with TRUE and all FALSE with FALSE. All other selections are represented with positive or negative integers, whatever is shorter. This needs less RAM compared to logical() (and often less than bit() or which()). Logical operations are fast if the selection is asymmetric (only few or almost all selected).

bitwhich(
  maxindex = 0L,
  x = NULL,
  xempty = FALSE,
  poslength = NULL,
  is.unsorted = TRUE,
  has.dup = TRUE
)

Arguments

maxindex

length of the vector

x

Information about which positions are FALSE or TRUE: either logical() or TRUE or FALSE or a integer vector of positive or of negative subscripts.

xempty

what to assume about parameter x if x=integer(0), typically TRUE or FALSE.

poslength

tuning: poslength is calculated automatically, you can give poslength explicitly, in this case it must be correct and x must be sorted and not have duplicates.

is.unsorted

tuning: FALSE implies that x is already sorted and sorting is skipped

has.dup

tuning: FALSE implies that x has no duplicates

Value

an object of class 'bitwhich' carrying two attributes

  • maxindex: see above

  • poslength: see above

Examples

bitwhich()
bitwhich(12)
#> bitwhich: 0/ 12 occupying only  1 int32 in FALSE representation
#>     1     2     3     4     5     6     7     8     9    10    11    12 
#> FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE 
bitwhich(12, x=TRUE)
#> bitwhich: 12/ 12 occupying only  1 int32 in TRUE representation
#>    1    2    3    4    5    6    7    8    9   10   11   12 
#> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE 
bitwhich(12, x=3)
#> bitwhich: 1/ 12 occupying only  1 int32 in 1 representation
#>     1     2     3     4     5     6     7     8     9    10    11    12 
#> FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE 
bitwhich(12, x=-3)
#> bitwhich: 11/ 12 occupying only  1 int32 in -1 representation
#>     1     2     3     4     5     6     7     8     9    10    11    12 
#>  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE 
bitwhich(12, x=integer())
#> bitwhich: 0/ 12 occupying only  1 int32 in FALSE representation
#>     1     2     3     4     5     6     7     8     9    10    11    12 
#> FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE 
bitwhich(12, x=integer(), xempty=TRUE)
#> bitwhich: 12/ 12 occupying only  1 int32 in TRUE representation
#>    1    2    3    4    5    6    7    8    9   10   11   12 
#> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE