Skip to content

Commit 678b393

Browse files
committed
serialization updat4s
1 parent 3c74865 commit 678b393

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

include/bucket_buffer.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ class BucketBuffer {
9595
// std::array<BufferEntry, BUFFER_CAPACITY> thread_local_buffer {};
9696
// std::array<BufferEntry, BUFFER_CAPACITY> thread_local_otherbuffer {};
9797

98+
void serialize(std::ostream& binary_out) const {
99+
binary_out.write((char *) &_capacity, sizeof(size_t));
100+
size_t _size = entries.size();
101+
binary_out.write((char *) &_size, sizeof(size_t));
102+
binary_out.write((char *) entries.data(), sizeof(BufferEntry) * _size);
103+
}
104+
void deserialize(std::istream& binary_in) {
105+
binary_in.read((char *) &_capacity, sizeof(size_t));
106+
entries.reserve(_capacity);
107+
size_t _size;
108+
binary_in.read((char *) &_size, sizeof(size_t));
109+
entries.resize(_size);
110+
// TODO - no me gusta
111+
binary_in.read((char *) entries.data(), sizeof(BufferEntry) * _size);
112+
// for (size_t i = 0; i < _size; ++i) {
113+
// binary_in.read((char *) &entries[i], sizeof(BufferEntry));
114+
// }
115+
}
116+
98117
public:
99118
BucketBuffer(): _capacity(128) {
100119
entries = std::vector<BufferEntry>();

src/sketch.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ Sketch::Sketch(vec_t vector_len, uint64_t seed, bool compressed, std::istream &b
4949
num_samples = _samples;
5050
cols_per_sample = _cols;
5151
num_columns = num_samples * cols_per_sample;
52-
bkt_per_col = calc_bkt_per_col(vector_len);
52+
binary_in.read((char *) &bkt_per_col, sizeof(size_t));
53+
// bkt_per_col = calc_bkt_per_col(vector_len);
5354
num_buckets = num_columns * bkt_per_col + 1; // plus 1 for deterministic bucket
5455
// bucket_buffer = BucketBuffer(new BufferEntry[_cols * 2], _cols * 2);
5556
bucket_buffer = BucketBuffer();
@@ -373,7 +374,8 @@ ExhaustiveSketchSample Sketch::exhaustive_sample() {
373374

374375

375376
void Sketch::merge(const Sketch &other) {
376-
if (other.calc_deepest_depth() > bkt_per_col) {
377+
unlikely_if (other.bkt_per_col > bkt_per_col && other.calc_deepest_depth() > bkt_per_col)
378+
{
377379
reallocate(other.calc_deepest_depth());
378380
inject_buffer_buckets();
379381
}
@@ -578,6 +580,7 @@ uint8_t Sketch::effective_depth() const
578580
}
579581

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

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

0 commit comments

Comments
 (0)