Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

bit_sort

bit sort


Description

fast sorting of integers

Usage

bit_sort(x, decreasing = FALSE, na.last = NA, has.dup = TRUE)

Arguments

x

an integer vector

decreasing

(currently only FALSE is supported)

na.last

NA removes NAs, FALSE puts NAs at the beginning, TRUE puts NAs at the end

has.dup

TRUE (the default) assumes that x might have duplicates, set to FALSE if duplicates are impossible

Details

determines the range of the integers and checks if the density justifies use of a bit vector; if yes, sorts the first occurences of each integer in the range using a bit vector, sorts the rest and merges; if no, falls back to quicksort.

Value

a sorted vector

See Also

Examples

bit_sort(c(2L,1L,NA,NA,1L,2L))
bit_sort(c(2L,1L,NA,NA,1L,2L), na.last=FALSE)
bit_sort(c(2L,1L,NA,NA,1L,2L), na.last=TRUE)

## Not run: 
x <- sample(1e7, replace=TRUE)
system.time(bit_sort(x))
system.time(sort(x))

## End(Not run)

bit

Classes and Methods for Fast Memory-Efficient Boolean Selections

v4.0.4
GPL-2 | GPL-3
Authors
Jens Oehlschlägel [aut, cre], Brian Ripley [ctb]
Initial release
2020-08-03

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.