From 9997c1c0437c53cf0e16d7da388bce825f02b23d Mon Sep 17 00:00:00 2001 From: Lam Pham-Sy Date: Fri, 22 Jun 2018 12:37:07 +0200 Subject: [PATCH] FEC NF4: fix --- src/fec_rs_nf4.h | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/fec_rs_nf4.h b/src/fec_rs_nf4.h index ec0d8007..a8387be9 100644 --- a/src/fec_rs_nf4.h +++ b/src/fec_rs_nf4.h @@ -305,26 +305,36 @@ class RsNf4 : public FecCode { for (unsigned i = 0; i < this->n_data; ++i) { const int frag_id = fragments_ids.get(i); T* chunk = words->get(i); - size_t curr_frag_index = 0; - // loop over marked symbols + + // the vector will contain marked symbols that will be packed + // firstly. Since locations are stored in unordered map, the vector + // will be sorted later to facilitate packing un-marked symbols + std::vector packed_symbs; + // pack marked symbols for (auto const& data : props[frag_id].get_map()) { off_t loc_offset = data.first.get_offset(); if (loc_offset >= offset && loc_offset < offset_max) { // As loc.offset := offset + j * this->word_size const size_t j = (loc_offset - offset) / this->word_size; - - // pack symbols from `curr_frag_index` to `j-1` - for (; curr_frag_index < j; ++curr_frag_index) { - chunk[curr_frag_index] = - ngff4->pack(chunk[curr_frag_index]); - } - // increment curr_frag_index to pass found index `j` - curr_frag_index++; + packed_symbs.push_back(j); // pack symbol at index `j` uint32_t flag = std::stoul(data.second); chunk[j] = ngff4->pack(chunk[j], flag); } } + // sort the list of packed symbols + std::sort(packed_symbs.begin(), packed_symbs.end()); + + // pack un-marked symbols + size_t curr_frag_index = 0; + for (auto const& done_id : packed_symbs) { + // pack symbols from `curr_frag_index` to `j-1` + for (; curr_frag_index < done_id; ++curr_frag_index) { + chunk[curr_frag_index] = + ngff4->pack(chunk[curr_frag_index]); + } + curr_frag_index++; + } // pack last symbols from `curr_frag_index` to `this->pkt_size-1` for (; curr_frag_index < this->pkt_size; ++curr_frag_index) { chunk[curr_frag_index] = ngff4->pack(chunk[curr_frag_index]);