Skip to content

Commit

Permalink
FEC NF4: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lamphamsy committed Jun 22, 2018
1 parent 3453629 commit 9997c1c
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/fec_rs_nf4.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,26 +305,36 @@ class RsNf4 : public FecCode<T> {
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<size_t> 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]);
Expand Down

0 comments on commit 9997c1c

Please sign in to comment.