@@ -194,15 +194,19 @@ Sketch::~Sketch() {
194194 * backwards until we reach the point where the columns are once again not
195195 * being stored
196196 */
197- bucket_buffer.sort_and_compact ();
197+ // bucket_buffer.sort_and_compact();
198198 size_t buffer_size = bucket_buffer.size ();
199+ // ACTUALLY - we dont need to sort. just need to partition
200+ size_t to_keep_sz = bucket_buffer.partition (bkt_per_col);
199201 int i = ((int ) buffer_size)-1 ;
200- while (i >= 0 && bucket_buffer[i].row_idx < bkt_per_col) {
202+ // while (i >= 0 && bucket_buffer[i].row_idx < bkt_per_col) {
203+ while (i >= 0 && i >= to_keep_sz) {
201204 // update the bucket
202205 get_bucket (bucket_buffer[i].col_idx , bucket_buffer[i].row_idx ) ^= bucket_buffer[i].value ;
203206 i--;
204207 }
205- bucket_buffer.entries .resize (i+1 );
208+ bucket_buffer.entries .resize (to_keep_sz);
209+ // bucket_buffer.entries.resize(i+1);
206210 // if (buffer_size > 3)
207211 // std::cout << "Injected buffer buckets:" << buffer_size << " to " << i+1 << std::endl;
208212 }
@@ -392,6 +396,11 @@ void Sketch::merge(const Sketch &other) {
392396 // TODO - when sketches have dynamic sizes, this will require more work
393397 // ie we would want to deal with some depths seperately.
394398 bool sufficient_space = bucket_buffer.merge (other.bucket_buffer );
399+ // TODO - make this procedure better. this isnt a great implementation
400+ if (!sufficient_space) {
401+ inject_buffer_buckets ();
402+ sufficient_space = !bucket_buffer.over_capacity ();
403+ }
395404 while (!sufficient_space) {
396405 // std::cout << "Merge: Buffer full, reallocating" << std::endl;
397406 // reallocate((bkt_per_col * 8) / 5);
@@ -485,6 +494,11 @@ void Sketch::range_merge(const Sketch &other, size_t start_sample, size_t n_samp
485494 }
486495#endif
487496 bool sufficient_space = bucket_buffer.merge (other.bucket_buffer );
497+ // TODO - make this procedure better. this isnt a great implementation
498+ if (!sufficient_space) {
499+ inject_buffer_buckets ();
500+ sufficient_space = !bucket_buffer.over_capacity ();
501+ }
488502 while (!sufficient_space) {
489503 // std::cout << "Merge: Buffer full, reallocating" << std::endl;
490504 // reallocate((bkt_per_col * 8) / 5);
0 commit comments