FastLED 3.10.6
Loading...
Searching...
No Matches
flat_map_basic.cpp.hpp
Go to the documentation of this file.
1// IWYU pragma: private, include "fl/stl/flat_map_basic.h"
2//
3// flat_map_basic: implementation of the type-erased binary-search
4// helpers shared across all `fl::flat_map<K, V, Less>` instantiations.
5// See `flat_map_basic.h` for design rationale (FastLED #3235 Tier 2D).
6
8
9namespace fl {
10namespace detail {
11
13fl::size flat_map_lower_bound_idx(const void* data, fl::size n,
14 const void* key,
15 const flat_map_ops& ops) FL_NO_EXCEPT {
16 const char* base = static_cast<const char*>(data);
17 fl::size first_idx = 0;
18 fl::size count = n;
19 while (count > 0) {
20 fl::size step = count / 2;
21 fl::size mid_idx = first_idx + step;
22 // `.first` of `pair<Key, Value>` is at offset 0 (standard layout).
23 const void* mid_key = base + mid_idx * ops.element_size;
24 if (ops.less_fn(ops.less_ctx, mid_key, key)) {
25 first_idx = mid_idx + 1;
26 count -= step + 1;
27 } else {
28 count = step;
29 }
30 }
31 return first_idx;
32}
33
35fl::size flat_map_upper_bound_idx(const void* data, fl::size n,
36 const void* key,
37 const flat_map_ops& ops) FL_NO_EXCEPT {
38 const char* base = static_cast<const char*>(data);
39 fl::size first_idx = 0;
40 fl::size count = n;
41 while (count > 0) {
42 fl::size step = count / 2;
43 fl::size mid_idx = first_idx + step;
44 const void* mid_key = base + mid_idx * ops.element_size;
45 // upper_bound: advance past elements where !(key < elem.first).
46 if (!ops.less_fn(ops.less_ctx, key, mid_key)) {
47 first_idx = mid_idx + 1;
48 count -= step + 1;
49 } else {
50 count = step;
51 }
52 }
53 return first_idx;
54}
55
56} // namespace detail
57} // namespace fl
#define FL_NO_INLINE
FL_NO_INLINE fl::size flat_map_lower_bound_idx(const void *data, fl::size n, const void *key, const flat_map_ops &ops) FL_NO_EXCEPT
FL_NO_INLINE fl::size flat_map_upper_bound_idx(const void *data, fl::size n, const void *key, const flat_map_ops &ops) FL_NO_EXCEPT
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_info.h:57
constexpr enable_if< is_fixed_point< T >::value, T >::type step(T edge, T x) FL_NO_EXCEPT
InputGamut g FL_NO_EXCEPT
Definition rgbw.h:121
Base definition for an LED controller.
Definition crgb.hpp:179