mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-10 18:05:44 +02:00
chore: add Dash::Prefetch function (#4476)
* chore: add Dash::Prefetch function It's not being used at this time. * chore: fixes
This commit is contained in:
parent
6265f52bff
commit
a936dfe8a5
2 changed files with 21 additions and 0 deletions
|
@ -149,6 +149,9 @@ class DashTable : public detail::DashTableBase {
|
|||
template <typename U> const_iterator Find(U&& key) const;
|
||||
template <typename U> iterator Find(U&& key);
|
||||
|
||||
// Prefetches the memory where the key would resize into the cache.
|
||||
template <typename U> void Prefetch(U&& key) const;
|
||||
|
||||
// Find first entry with given key hash that evaulates to true on pred.
|
||||
// Pred accepts either (const key&) or (const key&, const value&)
|
||||
template <typename Pred> iterator FindFirst(uint64_t key_hash, Pred&& pred);
|
||||
|
@ -699,6 +702,14 @@ auto DashTable<_Key, _Value, Policy>::Find(U&& key) -> iterator {
|
|||
return FindFirst(DoHash(key), EqPred(key));
|
||||
}
|
||||
|
||||
template <typename _Key, typename _Value, typename Policy>
|
||||
template <typename U>
|
||||
void DashTable<_Key, _Value, Policy>::Prefetch(U&& key) const {
|
||||
uint64_t key_hash = DoHash(key);
|
||||
uint32_t seg_id = SegmentId(key_hash);
|
||||
segment_[seg_id]->Prefetch(key_hash);
|
||||
}
|
||||
|
||||
template <typename _Key, typename _Value, typename Policy>
|
||||
template <typename Pred>
|
||||
auto DashTable<_Key, _Value, Policy>::FindFirst(uint64_t key_hash, Pred&& pred) -> iterator {
|
||||
|
|
|
@ -502,6 +502,7 @@ template <typename _Key, typename _Value, typename Policy = DefaultSegmentPolicy
|
|||
|
||||
// Find item with given key hash and truthy predicate
|
||||
template <typename Pred> Iterator FindIt(Hash_t key_hash, Pred&& pred) const;
|
||||
void Prefetch(Hash_t key_hash) const;
|
||||
|
||||
// Returns valid iterator if succeeded or invalid if not (it's full).
|
||||
// Requires: key should be not present in the segment.
|
||||
|
@ -1188,6 +1189,15 @@ auto Segment<Key, Value, Policy>::FindIt(Hash_t key_hash, Pred&& pred) const ->
|
|||
return Iterator{};
|
||||
}
|
||||
|
||||
template <typename Key, typename Value, typename Policy>
|
||||
void Segment<Key, Value, Policy>::Prefetch(Hash_t key_hash) const {
|
||||
uint8_t bidx = BucketIndex(key_hash);
|
||||
const Bucket& target = bucket_[bidx];
|
||||
|
||||
// Prefetch the home bucket that might hold the key with high probability.
|
||||
__builtin_prefetch(&target, 0, 1);
|
||||
}
|
||||
|
||||
template <typename Key, typename Value, typename Policy>
|
||||
template <typename Cb>
|
||||
void Segment<Key, Value, Policy>::TraverseAll(Cb&& cb) const {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue