diff options
| author | KunoiSayami <[email protected]> | 2023-05-30 02:09:17 +0800 |
|---|---|---|
| committer | KunoiSayami <[email protected]> | 2023-05-30 02:09:17 +0800 |
| commit | 77796af33c0b45189b03839f725899c62db8ae71 (patch) | |
| tree | 54d379ce8b822fc0cb723e87a4aa850fe1e38022 /read_helper.h | |
| parent | d01ba96eb4ae147159f15d5f3cdb076fc60483e4 (diff) | |
fix: Fix read helper bug
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'read_helper.h')
| -rw-r--r-- | read_helper.h | 16 |
1 files changed, 8 insertions, 8 deletions
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<key_type> 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<key_type> &sample, std::vector<key_type> &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)); } |
