diff options
| author | KunoiSayami <[email protected]> | 2023-05-27 23:19:14 +0800 |
|---|---|---|
| committer | KunoiSayami <[email protected]> | 2023-05-27 23:19:14 +0800 |
| commit | 8d98c61aa03969d064e0081a40a5c22c8e29eadf (patch) | |
| tree | 4e730ba7277f679641f5c1f3578f946585065ff7 /read_helper.h | |
| parent | 74a5230d639686b71d0fb0fb57ff246913c15c3e (diff) | |
fix: Fix wrong std::vector function call in read_helper.h
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'read_helper.h')
| -rw-r--r-- | read_helper.h | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/read_helper.h b/read_helper.h index 292eaac..54ca77a 100644 --- a/read_helper.h +++ b/read_helper.h @@ -22,16 +22,18 @@ class ReadHelper { static constexpr size_t REVERSED_BLOCK = 256; public: - size_t sample_length, needed_read_length; + const size_t sample_length, needed_read_length; ReadHelper(char const *filename, size_t sample_length, size_t insertion_length) : filename(filename), sample_length(sample_length), - needed_read_length(insertion_length + sample_length) {} + needed_read_length(insertion_length + sample_length) { + // printf("%zu %zu\n", sample_length, needed_read_length); + } unsigned long long maxValue() const { return max_value; } unsigned long long minValue() const { return min_value; } - std::vector<unsigned long long> population_vector; - inline void store_into_vector(unsigned long long value) { + std::vector<key_type> population_vector; + inline void store_into_vector(key_type value) { if (max_value < value) { max_value = value; } @@ -53,32 +55,32 @@ public: return dst(mt19937); } - void readFile(unsigned long &total_row) { + void readFile(unsigned long *total_row) { this->population_vector.clear(); auto read_number = 0UL; FILE *file = fopen(filename, "r"); assert(file); P_ERR("Reading sample"); - for (long long i; - read_number < needed_read_length && fscanf(file, "%lld ", &i) != EOF; + for (key_type i; + read_number < sample_length && fscanf(file, "%lld ", &i) != EOF; store_into_vector(i)) read_number++; - if (total_row > 0) { + if (total_row != nullptr) { P_ERR("\rReading skip"); - read_number = randomRow(total_row - sample_length - needed_read_length - + read_number = randomRow(*total_row - sample_length - needed_read_length - REVERSED_BLOCK); - total_row = read_number; + *total_row = read_number; // fprintf(stderr, "Skip %lu\n", read_number); - for (long long i; read_number > 0 && fscanf(file, "%lld ", &i) != EOF;) + for (key_type i; read_number > 0 && fscanf(file, "%lld ", &i) != EOF;) read_number--; } P_ERR("\rReading population"); read_number = 0; - auto remain = sample_length + REVERSED_BLOCK; - for (long long i; read_number < remain && fscanf(file, "%lld ", &i) != EOF; + auto remain = needed_read_length - sample_length + REVERSED_BLOCK; + for (key_type i; read_number < remain && fscanf(file, "%lld ", &i) != EOF; store_into_vector(i)) read_number++; fclose(file); @@ -87,8 +89,9 @@ public: } void split_into(std::vector<key_type> &sample, std::vector<key_type> &p) { - sample.reserve(sample_length); - p.reserve(needed_read_length - sample_length); + sample.resize(sample_length); + 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); memcpy(p.data(), population_vector.data() + sample_length, @@ -102,6 +105,8 @@ public: memcpy(p, population_vector.data() + sample_length, sizeof(key_type) * (needed_read_length - sample_length)); } + + size_t size() const { return this->population_vector.size(); } }; #endif
\ No newline at end of file |
