@@ -252,17 +252,28 @@ void SparseSketch::update(const vec_t update_idx) {
252252 SketchBucket::Depths depths;
253253
254254 // Update higher depth buckets
255- for (size_t i = 0 ; i < num_columns; i++) {
256- size_t bit = i & 0x1 ;
257- if (bit == 0 ) {
258- depths = SketchBucket::get_index_depths (update_idx, column_seed (i), bkt_per_col);
255+ for (size_t i = 0 ; i < num_columns - 1 ; i += 2 ) {
256+ depths = SketchBucket::get_index_depths (update_idx, column_seed (i), bkt_per_col);
257+ for (size_t j = 0 ; j < 2 ; j++) {
258+ col_hash_t depth = depths[j];
259+ likely_if (depth < bkt_per_col) {
260+ likely_if (depth < num_dense_rows) {
261+ SketchBucket::update (bucket (i + j, depth), update_idx, checksum);
262+ } else {
263+ update_sparse (i + j, {uint8_t (-1 ), uint8_t (depth), {update_idx, checksum}});
264+ }
265+ }
259266 }
260- col_hash_t depth = depths[bit];
267+ }
268+ if ((num_columns & 0x1 ) == 1 ) {
269+ size_t col = num_columns - 1 ;
270+
271+ size_t depth = SketchBucket::get_index_depth (update_idx, column_seed (col), bkt_per_col);
261272 likely_if (depth < bkt_per_col) {
262273 likely_if (depth < num_dense_rows) {
263- SketchBucket::update (bucket (i , depth), update_idx, checksum);
274+ SketchBucket::update (bucket (col , depth), update_idx, checksum);
264275 } else {
265- update_sparse (i , {uint8_t (-1 ), uint8_t (depth), {update_idx, checksum}});
276+ update_sparse (col , {uint8_t (-1 ), uint8_t (depth), {update_idx, checksum}});
266277 }
267278 }
268279 }
@@ -325,8 +336,14 @@ SketchSample SparseSketch::sample() {
325336 return sample;
326337 }
327338
339+ // if dense region is densely populated then only check the "deepest" few rows
340+ int dense_row_min = 0 ;
341+ if (number_of_sparse_buckets > num_columns || num_dense_rows > min_num_dense_rows) {
342+ dense_row_min = num_dense_rows - num_dense_to_sample;
343+ }
344+
328345 for (size_t c = 0 ; c < cols_per_sample; ++c) {
329- for (int r = num_dense_rows - 1 ; r >= 0 ; --r) { // TODO: Consider reducing the number of dense rows checked to 1 or 2
346+ for (int r = num_dense_rows - 1 ; r >= dense_row_min ; --r) {
330347 if (SketchBucket::is_good (bucket (c + first_column, r), checksum_seed ())) {
331348 // std::cout << "Found GOOD dense bucket" << std::endl;
332349 return {bucket (c + first_column, r).alpha , GOOD};
0 commit comments