MCPcopy Create free account
hub / github.com/StereoKit/StereoKit / binary_search

Method binary_search

StereoKitC/libraries/array.h:189–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

187 // Does not work on pointers.
188 template <typename _T, typename D>
189 int32_t binary_search(const D _T::*key, const D &item) const {
190 array_view_t<D> view = array_view_t<D>{data, count, sizeof(_T), (size_t)&((_T*)nullptr->*key)};
191 int32_t l = 0, r = view.count - 1;
192 while (l <= r) {
193 int32_t mid = (l+r) / 2;
194 D mid_val = view[mid];
195 if (mid_val < item) l = mid + 1;
196 else if (mid_val > item) r = mid - 1;
197 else return mid;
198 }
199 return r < 0 ? r : -(r+2);
200 }
201
202 /*template <typename D>
203 int32_t binary_search(D (*get_key)(T item), D item) const {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected