binary_search: Binary search algorithm

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/binary_search.R

Description

Search a value in an ordered vector.

Usage

1
binary_search(x, v, index=FALSE)

Arguments

x

A vector with the data.

v

A value to check if exists in the vector x.

index

A boolean value for choose to return the position inside the vector.

Details

The functions is written in C++ in order to be as fast as possible.

Value

Search if the v exists in x. Then returns TRUE/FALSE if the value is been found.

Author(s)

Manos Papadakis

R implementation and documentation: Manos Papadakis <papadakm95@gmail.com>.

See Also

is_element

Examples

1
2
3
4
x <- sort(rnorm(1000))
v <- x[50]
b <- binary_search(x,v) 
b1 <- binary_search(x,v,TRUE) 

Example output

Loading required package: Rcpp
Loading required package: RcppZiggurat

Rfast documentation built on May 18, 2021, 1:07 a.m.