FastLED 3.10.6
Loading...
Searching...
No Matches
unordered_map_basic.h
Go to the documentation of this file.
1#pragma once
2
3// unordered_map_basic: type-erased probing-sequence helpers shared by
4// all `fl::unordered_map<K, V, Hash, Equal>` instantiations.
5//
6// FastLED's `unordered_map` is open-addressed with linear probing
7// (cap ≤ 8) or quadratic-then-linear probing (cap > 8). The probe
8// index sequence is purely a function of (hash, cap) -- it has no
9// dependency on K, V, Hash, or Equal beyond the hash value the caller
10// already computed. Extracting the probing math into a non-template
11// helper lets every distinct unordered_map instantiation share one
12// body (~30-50 B) instead of duplicating it (per the audit, the bulk
13// of the per-instantiation cost is in `find_slot` / `find_index` /
14// `find_unoccupied_index_using_bitset`).
15//
16// Design: caller passes (hash, attempt_index, cap, mask); we return the
17// next probe index in the sequence. Caller handles bucket inspection,
18// equality, and bitset state because those depend on K/V/Equal.
19//
20// The split is intentionally narrow: only the index-computation logic
21// is shared. Full type erasure of `find_slot` would require also
22// erasing the bucket-state checks (which touch K via `_equal(bucket.key,
23// key)`) and the bitset reads; doing that pays back only on builds
24// with many distinct unordered_map types. This narrow-scope helper
25// captures the part that's purely arithmetic with no leverage threshold.
26//
27// `FL_NO_INLINE` on the implementations is load-bearing under LTO -
28// without it the compiler would inline the body back into each call
29// site, defeating the dedup. The single indirect call per probe step is
30// dwarfed by the bucket inspection + bitset read it gates.
31//
32// See FastLED #3235 Tier 1C.
33
34#include "fl/stl/int.h"
35#include "fl/stl/cstddef.h"
36#include "fl/stl/compiler_control.h" // for FL_NO_INLINE
37#include "fl/stl/noexcept.h"
38
39namespace fl {
40namespace detail {
41
42// Probing constants -- exposed publicly so callers can match their fast-path
43// detection (cap <= 8 means linear-only).
44enum {
47};
48
49// Returns the i-th probe index for an open-addressed table of capacity `cap`
50// (must be a power of two) given an initial hash slot `h`. `mask` is
51// `cap - 1` (passed separately so the caller can cache it across probes).
52//
53// Probing sequence:
54// - cap <= 8: pure linear: (h + i) & mask
55// - cap > 8, i < 8: quadratic: (h + i + i*i) & mask
56// - cap > 8, i >= 8: linear fallback
57//
58// Caller is expected to terminate the sequence when it has examined all
59// `cap` slots or found an empty / matching slot.
61fl::size unordered_map_probe_idx(fl::size h, fl::size i,
62 fl::size mask, fl::size cap) FL_NO_EXCEPT;
63
64} // namespace detail
65} // namespace fl
#define FL_NO_INLINE
@ kUnorderedMapQuadraticProbingTries
@ kUnorderedMapLinearProbeOnlyThreshold
FL_NO_INLINE fl::size unordered_map_probe_idx(fl::size h, fl::size i, fl::size mask, fl::size cap) FL_NO_EXCEPT
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_info.h:57
InputGamut g FL_NO_EXCEPT
Definition rgbw.h:121
Base definition for an LED controller.
Definition crgb.hpp:179