22
33FixedSizeSketchColumn::FixedSizeSketchColumn (uint8_t capacity, uint64_t seed) :
44 capacity(capacity), seed(seed) {
5- buckets = new Bucket[capacity];
6- std::memset (buckets, 0 , capacity * sizeof (Bucket));
5+ likely_if (capacity > 0 ) {
6+ buckets = new Bucket[capacity];
7+ std::memset (buckets, 0 , capacity * sizeof (Bucket));
8+ }
9+ else {
10+ buckets = nullptr ;
11+ }
712}
813
914FixedSizeSketchColumn::FixedSizeSketchColumn (const FixedSizeSketchColumn &other) :
1015 capacity(other.capacity), seed(other.seed), deterministic_bucket(other.deterministic_bucket) {
11- buckets = new Bucket[capacity];
12- std::memcpy (buckets, other.buckets , capacity * sizeof (Bucket));
16+ likely_if (capacity > 0 ) {
17+ buckets = new Bucket[capacity];
18+ std::memcpy (buckets, other.buckets , capacity * sizeof (Bucket));
19+ }
20+ else {
21+ buckets = nullptr ;
22+ }
1323}
1424
1525FixedSizeSketchColumn::FixedSizeSketchColumn (FixedSizeSketchColumn &&other) :
1626 capacity(other.capacity), seed(other.seed), deterministic_bucket(other.deterministic_bucket) {
17- buckets = std::move (other.buckets );
27+ buckets = other.buckets ;
28+ other.buckets = nullptr ;
29+ other.capacity = 0 ;
1830}
1931
2032FixedSizeSketchColumn& FixedSizeSketchColumn::operator =(FixedSizeSketchColumn &&other) {
@@ -26,6 +38,7 @@ FixedSizeSketchColumn& FixedSizeSketchColumn::operator=(FixedSizeSketchColumn &&
2638
2739 buckets = other.buckets ;
2840 other.buckets = nullptr ;
41+ other.capacity = 0 ;
2942 }
3043 return *this ;
3144}
@@ -84,24 +97,35 @@ void FixedSizeSketchColumn::update(const vec_t update) {
8497 deterministic_bucket ^= {update, checksum};
8598}
8699
87-
88- ResizeableSketchColumn::ResizeableSketchColumn (uint8_t start_capacity, uint64_t seed) :
89- capacity(start_capacity), seed(seed) {
100+ ResizeableSketchColumn::ResizeableSketchColumn (uint8_t start_capacity,
101+ uint64_t seed)
102+ : capacity(start_capacity), seed(seed) {
103+ likely_if (capacity > 0 ) {
90104 buckets = new Bucket[start_capacity];
91105 std::memset (buckets, 0 , capacity * sizeof (Bucket));
106+ }
107+ else {
108+ buckets = nullptr ;
109+ }
92110}
93111
94112ResizeableSketchColumn::ResizeableSketchColumn (const ResizeableSketchColumn &other) :
95113 capacity(other.capacity), seed(other.seed), deterministic_bucket(other.deterministic_bucket) {
96- buckets = new Bucket[capacity];
97- std::memcpy (buckets, other.buckets , capacity * sizeof (Bucket));
114+ likely_if (capacity > 0 ) {
115+ buckets = new Bucket[capacity];
116+ std::memcpy (buckets, other.buckets , capacity * sizeof (Bucket));
117+ }
118+ else {
119+ buckets = nullptr ;
120+ }
98121}
99122
100123ResizeableSketchColumn::ResizeableSketchColumn (ResizeableSketchColumn &&other) :
101124 capacity(other.capacity), seed(other.seed), deterministic_bucket(other.deterministic_bucket) {
102125 // move constructor
103126 buckets = other.buckets ;
104127 other.buckets = nullptr ;
128+ other.capacity = 0 ;
105129}
106130
107131ResizeableSketchColumn& ResizeableSketchColumn::operator =(ResizeableSketchColumn &&other) {
@@ -113,6 +137,7 @@ ResizeableSketchColumn& ResizeableSketchColumn::operator=(ResizeableSketchColumn
113137
114138 buckets = other.buckets ;
115139 other.buckets = nullptr ;
140+ other.capacity = 0 ;
116141 }
117142 return *this ;
118143}
0 commit comments