Search sorted data

kd_lower_bound(x, v)

kd_upper_bound(x, v)

kd_range_query(x, l, u)

kd_rq_indices(x, l, u)

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

Examples

x = matrix(runif(200), 100) y = matrix_to_tuples(x) kd_sort(y, inplace = TRUE)
#> [,1] [,2] #> [1,] 0.02806097 0.004496308 #> [2,] 0.03424133 0.011479538 #> [3,] 0.03123033 0.164569248 #> [4,] 0.05861411 0.163623198 #> [5,] 0.18033877 0.044617158 #> (continues for 95 more rows)
y[kd_lower_bound(y, c(1/2, 1/2)),]
#> [1] 0.7328820 0.5117913
y[kd_upper_bound(y, c(1/2, 1/2)),]
#> [1] 0.7328820 0.5117913
kd_binary_search(y, c(1/2, 1/2))
#> [1] FALSE
kd_range_query(y, c(1/3, 1/3), c(2/3, 2/3))
#> [,1] [,2] #> [1,] 0.4035381 0.3589670 #> [2,] 0.3900314 0.4381372 #> [3,] 0.3357191 0.5813660 #> [4,] 0.3887013 0.5844753 #> [5,] 0.4007202 0.4848028 #> (continues for 9 more rows)
kd_rq_indices(y, c(1/3, 1/3), c(2/3, 2/3))
#> [1] 19 20 21 23 24 25 58 59 60 61 62 63 77 80