@@ -34,33 +34,21 @@ class DashTable : public detail::DashTableBase {
34
34
DashTable (const DashTable&) = delete ;
35
35
DashTable& operator =(const DashTable&) = delete ;
36
36
37
- struct SegmentPolicy {
38
- static constexpr unsigned NUM_SLOTS = Policy::kSlotNum ;
39
- static constexpr unsigned BUCKET_CNT = Policy::kBucketNum ;
40
- static constexpr unsigned STASH_BUCKET_NUM = Policy::kStashBucketNum ;
41
- static constexpr bool USE_VERSION = Policy::kUseVersion ;
42
- };
43
-
44
37
using Base = detail::DashTableBase;
45
- using SegmentType = detail::Segment<_Key, _Value, SegmentPolicy >;
38
+ using SegmentType = detail::Segment<_Key, _Value, Policy >;
46
39
using SegmentIterator = typename SegmentType::Iterator;
47
40
48
41
public:
49
42
using Key_t = _Key;
50
43
using Value_t = _Value;
51
44
using Segment_t = SegmentType;
52
45
53
- // ! Number of "official" buckets that are used to position a key. In other words, does not include
54
- // ! stash buckets.
55
- static constexpr unsigned kLogicalBucketNum = Policy::kBucketNum ;
56
-
57
46
// ! Total number of buckets in a segment (including stash).
58
- static constexpr unsigned kPhysicalBucketNum = SegmentType::kTotalBuckets ;
59
- static constexpr unsigned kBucketWidth = Policy::kSlotNum ;
60
47
static constexpr double kTaxAmount = SegmentType::kTaxSize ;
61
48
static constexpr size_t kSegBytes = sizeof (SegmentType);
62
49
static constexpr size_t kSegCapacity = SegmentType::capacity();
63
- static constexpr bool kUseVersion = Policy::kUseVersion ;
50
+ static constexpr size_t kSlotNum = SegmentType::kSlotNum ;
51
+ static constexpr size_t kBucketNum = SegmentType::kBucketNum ;
64
52
65
53
// if IsSingleBucket is true - iterates only over a single bucket.
66
54
template <bool IsConst, bool IsSingleBucket = false > class Iterator ;
@@ -556,11 +544,11 @@ void DashTable<_Key, _Value, Policy>::CVCUponInsert(uint64_t ver_threshold, cons
556
544
return ;
557
545
}
558
546
559
- static_assert (kPhysicalBucketNum < 0xFF , " " );
547
+ static_assert (SegmentType:: kTotalBuckets < 0xFF , " " );
560
548
561
549
// Segment is full, we need to return the whole segment, because it can be split
562
550
// and its entries can be reshuffled into different buckets.
563
- for (uint8_t i = 0 ; i < kPhysicalBucketNum ; ++i) {
551
+ for (uint8_t i = 0 ; i < SegmentType:: kTotalBuckets ; ++i) {
564
552
if (target->GetVersion (i) < ver_threshold && !target->GetBucket (i).IsEmpty ()) {
565
553
cb (bucket_iterator{this , seg_id, i});
566
554
}
@@ -646,8 +634,8 @@ bool DashTable<_Key, _Value, Policy>::ShiftRight(bucket_iterator it) {
646
634
typename Segment_t::Hash_t hash_val = 0 ;
647
635
auto & bucket = seg->GetBucket (it.bucket_id_ );
648
636
649
- if (bucket.GetBusy () & (1 << (kBucketWidth - 1 ))) {
650
- it.slot_id_ = kBucketWidth - 1 ;
637
+ if (bucket.GetBusy () & (1 << (kSlotNum - 1 ))) {
638
+ it.slot_id_ = kSlotNum - 1 ;
651
639
hash_val = DoHash (it->first );
652
640
policy_.DestroyKey (it->first );
653
641
policy_.DestroyValue (it->second );
@@ -800,7 +788,7 @@ auto DashTable<_Key, _Value, Policy>::InsertInternal(U&& key, V&& value, Evictio
800
788
801
789
for (unsigned i = 0 ; i < Policy::kStashBucketNum ; ++i) {
802
790
hotspot.probes .by_type .stash_buckets [i] =
803
- bucket_iterator{this , target_seg_id, uint8_t (kLogicalBucketNum + i), 0 };
791
+ bucket_iterator{this , target_seg_id, uint8_t (Policy:: kBucketNum + i), 0 };
804
792
}
805
793
hotspot.num_buckets = HotspotBuckets::kNumBuckets ;
806
794
@@ -910,7 +898,7 @@ auto DashTable<_Key, _Value, Policy>::TraverseBySegmentOrder(Cursor curs, Cb&& c
910
898
s->TraverseBucket (bid, std::move (dt_cb));
911
899
912
900
++bid;
913
- if (bid == kPhysicalBucketNum ) {
901
+ if (bid == SegmentType:: kTotalBuckets ) {
914
902
sid = NextSeg (sid);
915
903
bid = 0 ;
916
904
if (sid >= segment_.size ()) {
@@ -924,15 +912,15 @@ auto DashTable<_Key, _Value, Policy>::TraverseBySegmentOrder(Cursor curs, Cb&& c
924
912
template <typename _Key, typename _Value, typename Policy>
925
913
auto DashTable<_Key, _Value, Policy>::GetRandomCursor(absl::BitGen* bitgen) -> Cursor {
926
914
uint32_t sid = absl::Uniform<uint32_t >(*bitgen, 0 , segment_.size ());
927
- uint8_t bid = absl::Uniform<uint8_t >(*bitgen, 0 , kLogicalBucketNum );
915
+ uint8_t bid = absl::Uniform<uint8_t >(*bitgen, 0 , Policy:: kBucketNum );
928
916
929
917
return Cursor{global_depth_, sid, bid};
930
918
}
931
919
932
920
template <typename _Key, typename _Value, typename Policy>
933
921
template <typename Cb>
934
922
auto DashTable<_Key, _Value, Policy>::Traverse(Cursor curs, Cb&& cb) -> Cursor {
935
- if (curs.bucket_id () >= kLogicalBucketNum ) // sanity.
923
+ if (curs.bucket_id () >= Policy:: kBucketNum ) // sanity.
936
924
return 0 ;
937
925
938
926
uint32_t sid = curs.segment_id (global_depth_);
@@ -955,7 +943,7 @@ auto DashTable<_Key, _Value, Policy>::Traverse(Cursor curs, Cb&& cb) -> Cursor {
955
943
sid = 0 ;
956
944
++bid;
957
945
958
- if (bid >= kLogicalBucketNum )
946
+ if (bid >= Policy:: kBucketNum )
959
947
return 0 ; // "End of traversal" cursor.
960
948
}
961
949
} while (!fetched);
0 commit comments