Skip to content

Commit 3408521

Browse files
committed
added zero_contents and suggest_capacity to column concept
1 parent fd43708 commit 3408521

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

include/sketch/sketch_columns.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "bucket.h"
33
#include "sketch_concept.h"
44

5+
#include <cmath>
6+
57
#include "util.h"
68

79
#include <hwy/highway.h>
@@ -31,13 +33,28 @@ class FixedSizeSketchColumn {
3133
~FixedSizeSketchColumn();
3234
SketchSample<vec_t> sample() const;
3335
void clear();
36+
3437
void update(const vec_t update);
3538
void merge(FixedSizeSketchColumn &other);
3639
uint8_t get_depth() const;
3740
void serialize(std::ostream &binary_out) const;
41+
42+
static uint8_t suggest_capacity(size_t num_vertices) {
43+
size_t num_edges = num_vertices * (num_vertices - 1) / 2;
44+
return static_cast<uint8_t>(1 + ceil(log2(num_edges)));
45+
}
46+
47+
[[deprecated]]
48+
3849
void reset_sample_state() {
3950
//no-op
4051
};
52+
53+
[[deprecated]]
54+
void zero_contents() {
55+
clear();
56+
}
57+
4158
bool operator==(const FixedSizeSketchColumn &other) const {
4259
for (size_t i = 0; i < capacity; ++i) {
4360
if (buckets[i] != other.buckets[i]) {
@@ -56,6 +73,7 @@ class FixedSizeSketchColumn {
5673
}
5774
return os;
5875
}
76+
5977
};
6078

6179

@@ -78,9 +96,20 @@ class ResizeableSketchColumn {
7896
void update(const vec_t update);
7997
void merge(ResizeableSketchColumn &other);
8098
uint8_t get_depth() const;
99+
100+
[[deprecated]]
101+
void zero_contents() {
102+
clear();
103+
}
104+
81105
void reset_sample_state() {
82106
//no-op
83107
};
108+
109+
static uint8_t suggest_capacity(size_t num_vertices) {
110+
return 4;
111+
}
112+
84113
void serialize(std::ostream &binary_out) const;
85114
bool operator==(const ResizeableSketchColumn &other) const {
86115
for (size_t i = 0; i < capacity; ++i) {

include/sketch/sketch_concept.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ concept SketchColumnConcept = requires(T t, T other) {
4242
{ t.update(std::declval<V>()) } -> std::same_as<void>;
4343
{ t.merge(other) } -> std::same_as<void>;
4444

45+
{ t.clear()} -> std::same_as<void>;
46+
{ t.zero_contents()} -> std::same_as<void>;
47+
4548
{ t.get_depth() } -> std::same_as<uint8_t>;
4649
{ t.get_seed() } -> std::same_as<uint64_t>;
4750

@@ -52,6 +55,7 @@ concept SketchColumnConcept = requires(T t, T other) {
5255
requires std::constructible_from<T, const T&>;
5356
// constructor with capacity hint, column index for seeding
5457
requires std::constructible_from<T, uint8_t, uint16_t>;
58+
{ T::suggest_capacity(std::declval<size_t>()) } -> std::same_as<uint8_t>;
5559
};
5660

5761
/*

0 commit comments

Comments
 (0)