FastLED
3.9.15
Loading...
Searching...
No Matches
◆
find_slot()
template<typename
Key
, typename T, typename
Hash
= Hash<Key>, typename KeyEqual = EqualTo<Key>, int INLINED_COUNT = FASTLED_HASHMAP_INLINED_COUNT>
pair
< fl::size, bool >
fl::HashMap
<
Key
, T,
Hash
, KeyEqual, INLINED_COUNT >::find_slot
(
const
Key
&
key
)
const
inline
private
Definition at line
452
of file
hash_map.h
.
452
{
453
const
fl::size
cap
=
_buckets
.size();
454
const
fl::size
mask
=
cap
- 1;
455
const
fl::size
h
=
_hash
(
key
) &
mask
;
456
fl::size
first_tomb
=
npos
();
457
458
if
(
cap
<= 8) {
459
// linear probing
460
for
(
fl::size
i
= 0;
i
<
cap
; ++
i
) {
461
const
fl::size
idx
= (
h
+
i
) &
mask
;
462
463
if
(
is_empty
(
idx
))
464
return
{
first_tomb
!=
npos
() ?
first_tomb
:
idx
,
true
};
465
if
(
is_deleted
(
idx
)) {
466
if
(
first_tomb
==
npos
())
467
first_tomb
=
idx
;
468
}
else
if
(
is_occupied
(
idx
) &&
_equal
(
_buckets
[
idx
].
key
,
key
)) {
469
return
{
idx
,
false
};
470
}
471
}
472
}
else
{
473
// quadratic probing up to 8 tries
474
fl::size
i
= 0;
475
for
(;
i
< 8; ++
i
) {
476
const
fl::size
idx
= (
h
+
i
+
i
*
i
) &
mask
;
477
478
if
(
is_empty
(
idx
))
479
return
{
first_tomb
!=
npos
() ?
first_tomb
:
idx
,
true
};
480
if
(
is_deleted
(
idx
)) {
481
if
(
first_tomb
==
npos
())
482
first_tomb
=
idx
;
483
}
else
if
(
is_occupied
(
idx
) &&
_equal
(
_buckets
[
idx
].
key
,
key
)) {
484
return
{
idx
,
false
};
485
}
486
}
487
// fallback to linear for the rest
488
for
(;
i
<
cap
; ++
i
) {
489
const
fl::size
idx
= (
h
+
i
) &
mask
;
490
491
if
(
is_empty
(
idx
))
492
return
{
first_tomb
!=
npos
() ?
first_tomb
:
idx
,
true
};
493
if
(
is_deleted
(
idx
)) {
494
if
(
first_tomb
==
npos
())
495
first_tomb
=
idx
;
496
}
else
if
(
is_occupied
(
idx
) &&
_equal
(
_buckets
[
idx
].
key
,
key
)) {
497
return
{
idx
,
false
};
498
}
499
}
500
}
501
502
return
{
npos
(),
false
};
503
}
fl::HashMap::npos
static fl::size npos()
Definition
hash_map.h:408
fl::HashMap::_equal
KeyEqual _equal
Definition
hash_map.h:708
fl::HashMap::is_deleted
bool is_deleted(fl::size idx) const
Definition
hash_map.h:415
fl::HashMap::is_occupied
bool is_occupied(fl::size idx) const
Definition
hash_map.h:413
fl::HashMap::_buckets
FL_DISABLE_WARNING_POP fl::vector_inlined< Entry, INLINED_COUNT > _buckets
Definition
hash_map.h:701
fl::HashMap::is_empty
bool is_empty(fl::size idx) const
Definition
hash_map.h:417
fl::HashMap::_hash
Hash _hash
Definition
hash_map.h:707
fl::HashMap
Definition
hash_map.h:60
fl
HashMap
Generated on Fri Aug 22 2025 20:59:36 for FastLED by
1.13.2