From 77796af33c0b45189b03839f725899c62db8ae71 Mon Sep 17 00:00:00 2001 From: KunoiSayami Date: Tue, 30 May 2023 02:09:17 +0800 Subject: fix: Fix read helper bug Signed-off-by: KunoiSayami --- read_helper.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'read_helper.h') diff --git a/read_helper.h b/read_helper.h index 2e87b0b..d19834a 100644 --- a/read_helper.h +++ b/read_helper.h @@ -46,10 +46,6 @@ public: key_type minValue() const { return min_value; } std::vector population_vector; - void finish_read() { - this->population_vector.push_back(this->max_value); - this->population_vector.push_back(this->min_value); - } static unsigned long randomRow(unsigned long max_value_) { std::random_device randomDevice; @@ -92,15 +88,16 @@ public: read_number++; fclose(file); P_ERR("\r"); - finish_read(); } void split_into(std::vector &sample, std::vector &p) { - sample.resize(sample_length); + sample.resize(sample_length - 2); p.resize(needed_read_length - sample_length); // printf("%zu\n", needed_read_length - sample_length); memcpy(sample.data(), population_vector.data(), - sizeof(key_type) * sample_length); + sizeof(key_type) * (sample_length - 2)); + sample.push_back(this->max_value); + sample.push_back(this->min_value); memcpy(p.data(), population_vector.data() + sample_length, sizeof(key_type) * (needed_read_length - sample_length)); } @@ -108,7 +105,10 @@ public: void split_into(key_type *&sample, key_type *&p) { sample = new key_type[sample_length]; p = new key_type[needed_read_length - sample_length]; - memcpy(sample, population_vector.data(), sizeof(key_type) * sample_length); + memcpy(sample, population_vector.data(), + sizeof(key_type) * (sample_length - 2)); + sample[sample_length - 2] = this->max_value; + sample[sample_length - 1] = this->min_value; memcpy(p, population_vector.data() + sample_length, sizeof(key_type) * (needed_read_length - sample_length)); } -- cgit v1.3.1