Skip to content

Commit

Permalink
serialization updat4s
Browse files Browse the repository at this point in the history
  • Loading branch information
Gillgamesh committed Dec 30, 2024
1 parent 3c74865 commit 678b393
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
19 changes: 19 additions & 0 deletions include/bucket_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ class BucketBuffer {
// std::array<BufferEntry, BUFFER_CAPACITY> thread_local_buffer {};
// std::array<BufferEntry, BUFFER_CAPACITY> thread_local_otherbuffer {};

void serialize(std::ostream& binary_out) const {
binary_out.write((char *) &_capacity, sizeof(size_t));
size_t _size = entries.size();
binary_out.write((char *) &_size, sizeof(size_t));
binary_out.write((char *) entries.data(), sizeof(BufferEntry) * _size);
}
void deserialize(std::istream& binary_in) {
binary_in.read((char *) &_capacity, sizeof(size_t));
entries.reserve(_capacity);
size_t _size;
binary_in.read((char *) &_size, sizeof(size_t));
entries.resize(_size);
// TODO - no me gusta
binary_in.read((char *) entries.data(), sizeof(BufferEntry) * _size);
// for (size_t i = 0; i < _size; ++i) {
// binary_in.read((char *) &entries[i], sizeof(BufferEntry));
// }
}

public:
BucketBuffer(): _capacity(128) {
entries = std::vector<BufferEntry>();
Expand Down
8 changes: 6 additions & 2 deletions src/sketch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ Sketch::Sketch(vec_t vector_len, uint64_t seed, bool compressed, std::istream &b
num_samples = _samples;
cols_per_sample = _cols;
num_columns = num_samples * cols_per_sample;
bkt_per_col = calc_bkt_per_col(vector_len);
binary_in.read((char *) &bkt_per_col, sizeof(size_t));
// bkt_per_col = calc_bkt_per_col(vector_len);
num_buckets = num_columns * bkt_per_col + 1; // plus 1 for deterministic bucket
// bucket_buffer = BucketBuffer(new BufferEntry[_cols * 2], _cols * 2);
bucket_buffer = BucketBuffer();
Expand Down Expand Up @@ -373,7 +374,8 @@ ExhaustiveSketchSample Sketch::exhaustive_sample() {


void Sketch::merge(const Sketch &other) {
if (other.calc_deepest_depth() > bkt_per_col) {
unlikely_if (other.bkt_per_col > bkt_per_col && other.calc_deepest_depth() > bkt_per_col)
{
reallocate(other.calc_deepest_depth());
inject_buffer_buckets();
}
Expand Down Expand Up @@ -578,6 +580,7 @@ uint8_t Sketch::effective_depth() const
}

void Sketch::compressed_serialize(std::ostream &binary_out) const {
binary_out.write((char*) &bkt_per_col, sizeof(size_t));
#ifdef ROW_MAJOR_SKETCHES
// write out max depth, nonempty flags, determinstic bucket, everything else
// then all other buckets
Expand Down Expand Up @@ -607,6 +610,7 @@ void Sketch::compressed_serialize(std::ostream &binary_out) const {
}

void Sketch::serialize(std::ostream &binary_out) const {
binary_out.write((char*) &bkt_per_col, sizeof(size_t));
// note that these will include the flag bits, if used.
binary_out.write((char*) buckets, bucket_array_bytes());
}
Expand Down

0 comments on commit 678b393

Please sign in to comment.