Skip to content

Commit d36f57e

Browse files
committed
copy-based assignment
1 parent b53a116 commit d36f57e

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

include/sketch/sketch_columns.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ class FixedSizeSketchColumn {
2828

2929
FixedSizeSketchColumn(uint8_t capacity, uint64_t seed);
3030
FixedSizeSketchColumn(const FixedSizeSketchColumn &other);
31+
FixedSizeSketchColumn& operator=(const FixedSizeSketchColumn &other);
32+
3133
FixedSizeSketchColumn(FixedSizeSketchColumn &&other);
34+
FixedSizeSketchColumn& operator=(FixedSizeSketchColumn &&other);
35+
3236
~FixedSizeSketchColumn();
3337
SketchSample<vec_t> sample() const;
3438
void clear();
@@ -63,8 +67,6 @@ class FixedSizeSketchColumn {
6367
}
6468
return true;
6569
}
66-
// move assignment operator
67-
FixedSizeSketchColumn& operator=(FixedSizeSketchColumn &&other);
6870

6971
friend std::ostream& operator<<(std::ostream &os, const FixedSizeSketchColumn &sketch) {
7072
os << "FixedSizeSketchColumn: " << std::endl;
@@ -92,6 +94,8 @@ class ResizeableSketchColumn {
9294

9395
ResizeableSketchColumn(uint8_t start_capacity, uint64_t seed);
9496
ResizeableSketchColumn(const ResizeableSketchColumn &other);
97+
ResizeableSketchColumn& operator=(const ResizeableSketchColumn &other);
98+
9599
ResizeableSketchColumn(ResizeableSketchColumn &&other);
96100
ResizeableSketchColumn& operator=(ResizeableSketchColumn &&other);
97101
~ResizeableSketchColumn();
@@ -160,6 +164,8 @@ class ResizeableAlignedSketchColumn {
160164

161165
ResizeableAlignedSketchColumn(uint8_t start_capacity, uint64_t seed);
162166
ResizeableAlignedSketchColumn(const ResizeableAlignedSketchColumn &other);
167+
ResizeableAlignedSketchColumn& operator=(const ResizeableAlignedSketchColumn &other);
168+
163169
ResizeableAlignedSketchColumn(ResizeableAlignedSketchColumn &&other);
164170
ResizeableAlignedSketchColumn& operator=(ResizeableAlignedSketchColumn &&other);
165171
~ResizeableAlignedSketchColumn();

src/sketch_columns.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ FixedSizeSketchColumn& FixedSizeSketchColumn::operator=(FixedSizeSketchColumn &&
4242
}
4343
return *this;
4444
}
45+
FixedSizeSketchColumn& FixedSizeSketchColumn::operator=(const FixedSizeSketchColumn &other) {
46+
if (this != &other) {
47+
delete[] buckets;
48+
capacity = other.capacity;
49+
seed = other.seed;
50+
deterministic_bucket = other.deterministic_bucket;
51+
52+
buckets = new Bucket[capacity];
53+
std::memcpy(buckets, other.buckets, capacity * sizeof(Bucket));
54+
}
55+
// TODO - an else case?
56+
return *this;
57+
}
4558

4659
FixedSizeSketchColumn::~FixedSizeSketchColumn() {
4760
// note nullptr is safe to delete
@@ -141,6 +154,19 @@ ResizeableSketchColumn& ResizeableSketchColumn::operator=(ResizeableSketchColumn
141154
}
142155
return *this;
143156
}
157+
ResizeableSketchColumn& ResizeableSketchColumn::operator=(const ResizeableSketchColumn &other) {
158+
if (this != &other) {
159+
delete[] buckets;
160+
capacity = other.capacity;
161+
seed = other.seed;
162+
deterministic_bucket = other.deterministic_bucket;
163+
164+
buckets = new Bucket[capacity];
165+
std::memcpy(buckets, other.buckets, capacity * sizeof(Bucket));
166+
}
167+
// TODO - an else case?
168+
return *this;
169+
}
144170

145171
ResizeableSketchColumn::~ResizeableSketchColumn() {
146172
delete[] buckets;

0 commit comments

Comments
 (0)