Skip to content

Commit 4756953

Browse files
committed
required more constructors, equality check
1 parent 7687d11 commit 4756953

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

include/sketch/sketch_columns.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ class FixedSizeSketchColumn {
3838
void reset_sample_state() {
3939
//no-op
4040
};
41+
bool operator==(const FixedSizeSketchColumn &other) const {
42+
for (size_t i = 0; i < capacity; ++i) {
43+
if (buckets[i] != other.buckets[i]) {
44+
return false;
45+
}
46+
}
47+
return true;
48+
}
4149
friend std::ostream& operator<<(std::ostream &os, const FixedSizeSketchColumn &sketch) {
4250
os << "FixedSizeSketchColumn: " << std::endl;
4351
os << "Capacity: " << (int)sketch.capacity << std::endl;
@@ -140,6 +148,14 @@ class ResizeableSketchColumn {
140148
//no-op
141149
};
142150
void serialize(std::ostream &binary_out) const;
151+
bool operator==(const ResizeableSketchColumn &other) const {
152+
for (size_t i = 0; i < capacity; ++i) {
153+
if (aligned_buckets[i] != other.aligned_buckets[i]) {
154+
return false;
155+
}
156+
}
157+
return true;
158+
}
143159
private:
144160
void reallocate(uint8_t new_capacity);
145161
};

include/sketch/sketch_concept.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include <format>
3+
#include <concepts>
34
#include "bucket.h"
45

56
enum SampleResult {
@@ -23,13 +24,15 @@ struct ExhaustiveSketchSample {
2324
};
2425

2526
template <typename T, typename V>
26-
concept ConnectivitySketchConcept = requires(T t) {
27+
concept ConnectivitySketchConcept = requires(T t, T other) {
2728
{ t.sample() } -> std::same_as<SketchSample<V>>;
2829
{ t.clear()} -> std::same_as<void>;
2930
{ t.update(std::declval<V>()) };
3031
{ t.merge(std::declval<T>()) };
3132
{ t.range_merge(std::declval<T>(), std::declval<size_t>(), std::declval<size_t>()) };
3233
{ t.serialize(std::declval<std::ostream&>()) };
34+
{ t == other } -> std::same_as<bool>;
35+
requires std::constructible_from<T, const T&>;
3336
};
3437

3538
template <typename T, typename V>
@@ -43,6 +46,11 @@ concept SketchColumnConcept = requires(T t, T other) {
4346

4447
{ t.serialize(std::declval<std::ostream&>()) };
4548
{ t.reset_sample_state()} -> std::same_as<void>;
49+
{ t == other } -> std::same_as<bool>;
50+
// copy constructor required
51+
requires std::constructible_from<T, const T&>;
52+
// constructor with capacity hint, column index for seeding
53+
requires std::constructible_from<T, uint8_t, uint16_t>;
4654
};
4755

4856
/*

0 commit comments

Comments
 (0)