diff options
| author | Douglas Rumbaugh <dbr4@psu.edu> | 2023-07-03 16:52:11 -0400 |
|---|---|---|
| committer | Douglas Rumbaugh <dbr4@psu.edu> | 2023-07-03 16:52:11 -0400 |
| commit | 369dc4c8b3331aa318f2a98eb973d0840541297d (patch) | |
| tree | abea889188a5bd7539ff093096db26c1a0a1b0af /include/shard/PGM.h | |
| parent | 5323632210b0e17c33a77abc1be2c3a62c1f47ed (diff) | |
| download | dynamic-extension-369dc4c8b3331aa318f2a98eb973d0840541297d.tar.gz | |
Slightly optimized merge function
Diffstat (limited to 'include/shard/PGM.h')
| -rw-r--r-- | include/shard/PGM.h | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/include/shard/PGM.h b/include/shard/PGM.h index 73688ae..20bdbf2 100644 --- a/include/shard/PGM.h +++ b/include/shard/PGM.h @@ -342,12 +342,20 @@ public: } static std::vector<R> merge(std::vector<std::vector<R>> &results) { + size_t total = 0; + for (size_t i=0; i<results.size(); i++) { + total += results[i].size(); + } + + if (total == 0) { + return std::vector<R>(); + } + std::vector<R> output; + output.reserve(total); for (size_t i=0; i<results.size(); i++) { - for (size_t j=0; j<results[i].size(); j++) { - output.emplace_back(results[i][j]); - } + std::move(results[i].begin(), results[i].end(), std::back_inserter(output)); } return output; |