Search sorted data

kd_lower_bound(x, v)

kd_upper_bound(x, v)

kd_range_query(x, l, u, ...)

# S3 method for arrayvec
kd_range_query(x, l, u, ...)

# S3 method for matrix
kd_range_query(x, l, u, cols = NULL, ...)

# S3 method for data.frame
kd_range_query(x, l, u, cols = NULL, ...)

kd_rq_indices(x, l, u, ...)

# S3 method for arrayvec
kd_rq_indices(x, l, u, ...)

# S3 method for matrix
kd_rq_indices(x, l, u, cols = NULL, ...)

# S3 method for data.frame
kd_rq_indices(x, l, u, cols = NULL, ...)

kd_binary_search(x, v)

# S3 method for arrayvec
kd_binary_search(x, v)

# S3 method for matrix
kd_binary_search(x, v)

Arguments

x

an object sorted by kd_sort

v

a vector specifying where to look

l

lower left corner of search region

u

upper right corner of search region

...

ignored

cols

integer or character vector or formula indicating columns

Value

kd_lower_bounda row of values (vector)
kd_upper_bounda row of values (vector)
kd_range_querya set of rows in the same format as the sorted input
kd_rq_indicesa vector of integer indices specifying rows in the input
kd_binary_searcha boolean

Examples

if (has_cxx17()) {
x = matrix(runif(200), 100)
y = matrix_to_tuples(x)
kd_sort(y, inplace = TRUE)
y[kd_lower_bound(y, c(1/2, 1/2)),]
y[kd_upper_bound(y, c(1/2, 1/2)),]
kd_binary_search(y, c(1/2, 1/2))
kd_range_query(y, c(1/3, 1/3), c(2/3, 2/3))
kd_rq_indices(y, c(1/3, 1/3), c(2/3, 2/3))
}
#> [1] 24 25 60 61 77 80 81 82