FindIdx: Find indices

Description Usage Arguments Value Examples

Description

this niche function compares key to val by cmpf(val, key), and returns the indices that passed cmpf(). FindIdx assumes that val and key are sorted by cmpf and finds indices in O(n). FindIdxUnsorted assumes that val and key are not sorted and finds indices in O(n^2). Since cmpf is arbitrary, binary search is not used.

Usage

1
2
3
FindIdx(val, key, cmpf = `>=`)

FindIdxUnsorted(val, key, cmpf = `>=`)

Arguments

val

a vector of values.

key

a vector of keys to find in val.

cmpf

a comparison function.

Value

a vector of found indices.

Examples

1
2
3
4
measured <- sort(sample(seq(1000000), 500000))
sampled <- sort(sample(measured, 20000) + runif(20000, -100, 0))
indices <- FindIdx(measured, sampled, cmpf = `>=`)
stopifnot(all(measured[indices] >= sampled))

imlijunda/AwkwardMLTools documentation built on May 13, 2019, 11:33 a.m.