11#include " sketch/sketch_columns.h"
22
3- FixedSizeSketchColumn::FixedSizeSketchColumn (uint8_t capacity, uint16_t col_idx ) :
4- capacity(capacity), col_idx(col_idx ) {
3+ FixedSizeSketchColumn::FixedSizeSketchColumn (uint8_t capacity, uint64_t seed ) :
4+ capacity(capacity), seed(seed ) {
55 buckets = new Bucket[capacity];
66 std::memset (buckets, 0 , capacity * sizeof (Bucket));
77}
88
99FixedSizeSketchColumn::FixedSizeSketchColumn (const FixedSizeSketchColumn &other) :
10- capacity(other.capacity), col_idx (other.col_idx ), deterministic_bucket(other.deterministic_bucket) {
10+ capacity(other.capacity), seed (other.seed ), deterministic_bucket(other.deterministic_bucket) {
1111 buckets = new Bucket[capacity];
1212 std::memcpy (buckets, other.buckets , capacity * sizeof (Bucket));
1313}
1414
15+ FixedSizeSketchColumn::FixedSizeSketchColumn (FixedSizeSketchColumn &&other) :
16+ capacity(other.capacity), seed(other.seed), deterministic_bucket(other.deterministic_bucket) {
17+ buckets = std::move (other.buckets );
18+ }
19+
20+ FixedSizeSketchColumn& FixedSizeSketchColumn::operator =(FixedSizeSketchColumn &&other) {
21+ if (this != &other) {
22+ delete[] buckets;
23+ capacity = other.capacity ;
24+ seed = other.seed ;
25+ deterministic_bucket = other.deterministic_bucket ;
26+
27+ buckets = other.buckets ;
28+ other.buckets = nullptr ;
29+ }
30+ return *this ;
31+ }
32+
1533FixedSizeSketchColumn::~FixedSizeSketchColumn () {
34+ // note nullptr is safe to delete
1635 delete[] buckets;
1736}
1837
@@ -29,8 +48,8 @@ uint8_t FixedSizeSketchColumn::get_depth() const {
2948void FixedSizeSketchColumn::serialize (std::ostream &binary_out) const {
3049 binary_out.write ((char *) buckets, capacity * sizeof (Bucket));
3150 binary_out.write ((char *) &deterministic_bucket, sizeof (Bucket));
51+ binary_out.write ((char *) &seed, sizeof (uint64_t ));
3252 binary_out.write ((char *) &capacity, sizeof (uint8_t ));
33- binary_out.write ((char *) &col_idx, sizeof (uint8_t ));
3453}
3554
3655SketchSample<vec_t > FixedSizeSketchColumn::sample () const {
@@ -59,25 +78,45 @@ void FixedSizeSketchColumn::merge(FixedSizeSketchColumn &other) {
5978
6079void FixedSizeSketchColumn::update (const vec_t update) {
6180 vec_hash_t checksum = Bucket_Boruvka::get_index_hash (update, seed);
62- col_hash_t depth = Bucket_Boruvka::get_index_depth_legacy (update, seed + col_idx , capacity-1 );
81+ col_hash_t depth = Bucket_Boruvka::get_index_depth_legacy (update, seed, capacity-1 );
6382 // assert(depth < capacity);
6483 buckets[depth] ^= {update, checksum};
6584 deterministic_bucket ^= {update, checksum};
6685}
6786
6887
69- ResizeableSketchColumn::ResizeableSketchColumn (uint8_t start_capacity, uint16_t col_idx ) :
70- capacity(start_capacity), col_idx(col_idx ) {
88+ ResizeableSketchColumn::ResizeableSketchColumn (uint8_t start_capacity, uint64_t seed ) :
89+ capacity(start_capacity), seed(seed ) {
7190 buckets = new Bucket[start_capacity];
7291 std::memset (buckets, 0 , capacity * sizeof (Bucket));
7392}
7493
7594ResizeableSketchColumn::ResizeableSketchColumn (const ResizeableSketchColumn &other) :
76- capacity(other.capacity), col_idx (other.col_idx ), deterministic_bucket(other.deterministic_bucket) {
95+ capacity(other.capacity), seed (other.seed ), deterministic_bucket(other.deterministic_bucket) {
7796 buckets = new Bucket[capacity];
7897 std::memcpy (buckets, other.buckets , capacity * sizeof (Bucket));
7998}
8099
100+ ResizeableSketchColumn::ResizeableSketchColumn (ResizeableSketchColumn &&other) :
101+ capacity(other.capacity), seed(other.seed), deterministic_bucket(other.deterministic_bucket) {
102+ // move constructor
103+ buckets = other.buckets ;
104+ other.buckets = nullptr ;
105+ }
106+
107+ ResizeableSketchColumn& ResizeableSketchColumn::operator =(ResizeableSketchColumn &&other) {
108+ if (this != &other) {
109+ delete[] buckets;
110+ capacity = other.capacity ;
111+ seed = other.seed ;
112+ deterministic_bucket = other.deterministic_bucket ;
113+
114+ buckets = other.buckets ;
115+ other.buckets = nullptr ;
116+ }
117+ return *this ;
118+ }
119+
81120ResizeableSketchColumn::~ResizeableSketchColumn () {
82121 delete[] buckets;
83122}
@@ -107,8 +146,8 @@ void ResizeableSketchColumn::clear() {
107146void ResizeableSketchColumn::serialize (std::ostream &binary_out) const {
108147 binary_out.write ((char *) buckets, capacity * sizeof (Bucket));
109148 binary_out.write ((char *) &deterministic_bucket, sizeof (Bucket));
149+ binary_out.write ((char *) &seed, sizeof (uint64_t ));
110150 binary_out.write ((char *) &capacity, sizeof (uint8_t ));
111- binary_out.write ((char *) &col_idx, sizeof (uint8_t ));
112151}
113152
114153SketchSample<vec_t > ResizeableSketchColumn::sample () const {
@@ -128,7 +167,7 @@ void ResizeableSketchColumn::update(const vec_t update) {
128167 // TODO - remove magic number
129168 // TODO - get_index_depth needs to be fixed. hashes need to be longer
130169 // than 32 bits if we're not using the deep bucket buffer idea.
131- col_hash_t depth = Bucket_Boruvka::get_index_depth_legacy (update, seed + col_idx , 60 );
170+ col_hash_t depth = Bucket_Boruvka::get_index_depth_legacy (update, seed, 60 );
132171 deterministic_bucket ^= {update, checksum};
133172
134173 if (depth >= capacity) {
@@ -160,16 +199,16 @@ uint8_t ResizeableSketchColumn::get_depth() const {
160199
161200
162201
163- ResizeableAlignedSketchColumn::ResizeableAlignedSketchColumn (uint8_t start_capacity, uint16_t col_idx ) :
164- capacity(start_capacity), col_idx(col_idx ) {
202+ ResizeableAlignedSketchColumn::ResizeableAlignedSketchColumn (uint8_t start_capacity, uint64_t seed ) :
203+ capacity(start_capacity), seed(seed ) {
165204
166205 // auto aligned_memptr = hwy::MakeUniqueAlignedArray<Bucket>(start_capacity);
167206 aligned_buckets = hwy::AllocateAligned<Bucket>(start_capacity);
168207 std::memset (aligned_buckets.get (), 0 , capacity * sizeof (Bucket));
169208}
170209
171210ResizeableAlignedSketchColumn::ResizeableAlignedSketchColumn (const ResizeableAlignedSketchColumn &other) :
172- capacity(other.capacity), col_idx (other.col_idx ), deterministic_bucket(other.deterministic_bucket) {
211+ capacity(other.capacity), seed (other.seed ), deterministic_bucket(other.deterministic_bucket) {
173212 aligned_buckets = hwy::AllocateAligned<Bucket>(capacity);
174213 std::memcpy (aligned_buckets.get (), other.aligned_buckets .get (), capacity * sizeof (Bucket));
175214}
@@ -200,8 +239,8 @@ void ResizeableAlignedSketchColumn::clear() {
200239void ResizeableAlignedSketchColumn::serialize (std::ostream &binary_out) const {
201240 binary_out.write ((char *) aligned_buckets.get (), capacity * sizeof (Bucket));
202241 binary_out.write ((char *) &deterministic_bucket, sizeof (Bucket));
242+ binary_out.write ((char *) &seed, sizeof (uint64_t ));
203243 binary_out.write ((char *) &capacity, sizeof (uint8_t ));
204- binary_out.write ((char *) &col_idx, sizeof (uint8_t ));
205244}
206245
207246SketchSample<vec_t > ResizeableAlignedSketchColumn::sample () const {
@@ -221,7 +260,7 @@ void ResizeableAlignedSketchColumn::update(const vec_t update) {
221260 // TODO - remove magic number
222261 // TODO - get_index_depth needs to be fixed. hashes need to be longer
223262 // than 32 bits if we're not using the deep bucket buffer idea.
224- col_hash_t depth = Bucket_Boruvka::get_index_depth_legacy (update, seed + col_idx , 60 );
263+ col_hash_t depth = Bucket_Boruvka::get_index_depth_legacy (update, seed, 60 );
225264 deterministic_bucket ^= {update, checksum};
226265
227266 if (depth >= capacity) {
@@ -252,11 +291,6 @@ uint8_t ResizeableAlignedSketchColumn::get_depth() const {
252291 return 0 ;
253292}
254293
255- uint64_t ResizeableSketchColumn::seed = 0 ;
256- uint64_t FixedSizeSketchColumn::seed = 0 ;
257- uint64_t ResizeableAlignedSketchColumn::seed = 0 ;
258-
259-
260294
261295static_assert (SketchColumnConcept<FixedSizeSketchColumn, vec_t >,
262296 " FixedSizeSketchColumn does not satisfy SketchColumnConcept" );
0 commit comments