From 646eb165f8cd13becc591208168bce192b4ec214 Mon Sep 17 00:00:00 2001 From: consti10 Date: Sun, 13 Aug 2023 22:38:40 +0200 Subject: [PATCH] optimize imports --- executables/wfb_keygen.cpp | 3 +++ src/FEC.hpp | 13 +++++++------ src/FECEnabled.cpp | 16 +++++++++------- src/FECEnabled.h | 4 ++-- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/executables/wfb_keygen.cpp b/executables/wfb_keygen.cpp index fdc5221f..4dbe64c7 100644 --- a/executables/wfb_keygen.cpp +++ b/executables/wfb_keygen.cpp @@ -19,6 +19,9 @@ #include +#include +#include + #include "../src/Encryption.h" /** diff --git a/src/FEC.hpp b/src/FEC.hpp index 377a6226..7917d581 100644 --- a/src/FEC.hpp +++ b/src/FEC.hpp @@ -52,7 +52,8 @@ void fecEncode(unsigned int fragmentSize, //std::cout<<"fec_encode step took:"<(delta).count()<<"us\n"; } -enum FragmentStatus { UNAVAILABLE = 0, AVAILABLE = 1 }; +static constexpr auto FRAGMENT_STATUS_UNAVAILABLE=false; +static constexpr auto FRAGMENT_STATUS_AVAILABLE=true; /** * @param fragmentSize size of each fragment @@ -66,14 +67,14 @@ template std::vector fecDecode(unsigned int fragmentSize, std::vector> &blockBuffer, const unsigned int nPrimaryFragments, - const std::vector &fragmentStatusList) { + const std::vector &fragmentStatusList) { assert(fragmentSize <= S); assert(fragmentStatusList.size() <= blockBuffer.size()); assert(fragmentStatusList.size() == blockBuffer.size()); std::vector indicesMissingPrimaryFragments; std::vector primaryFragmentP(nPrimaryFragments); for (unsigned int idx = 0; idx < nPrimaryFragments; idx++) { - if (fragmentStatusList[idx] == UNAVAILABLE) { + if (fragmentStatusList[idx] == FRAGMENT_STATUS_UNAVAILABLE) { indicesMissingPrimaryFragments.push_back(idx); } primaryFragmentP[idx] = blockBuffer[idx].data(); @@ -83,7 +84,7 @@ std::vector fecDecode(unsigned int fragmentSize, std::vector secondaryFragmentIndices; for (int i = 0; i < fragmentStatusList.size() - nPrimaryFragments; i++) { const auto idx = nPrimaryFragments + i; - if (fragmentStatusList[idx] == AVAILABLE) { + if (fragmentStatusList[idx] == FRAGMENT_STATUS_AVAILABLE) { secondaryFragmentP.push_back(blockBuffer[idx].data()); secondaryFragmentIndices.push_back(i); } @@ -124,10 +125,10 @@ static void testFecCPlusPlusWrapperY(const int nPrimaryFragments, const int nSec std::cout << "(Emulated) receivedFragmentIndices" << StringHelper::vectorAsString(receivedFragmentIndices) << "\n"; auto rxBlockBuffer = std::vector>(nPrimaryFragments + nSecondaryFragments); - std::vector fragmentMap(nPrimaryFragments + nSecondaryFragments, FragmentStatus::UNAVAILABLE); + std::vector fragmentMap(nPrimaryFragments + nSecondaryFragments, FRAGMENT_STATUS_UNAVAILABLE); for (const auto idx: receivedFragmentIndices) { rxBlockBuffer[idx] = txBlockBuffer[idx]; - fragmentMap[idx] = FragmentStatus::AVAILABLE; + fragmentMap[idx] = FRAGMENT_STATUS_AVAILABLE; } fecDecode(FRAGMENT_SIZE, rxBlockBuffer, nPrimaryFragments, fragmentMap); diff --git a/src/FECEnabled.cpp b/src/FECEnabled.cpp index a83049fd..e4a31f02 100644 --- a/src/FECEnabled.cpp +++ b/src/FECEnabled.cpp @@ -5,6 +5,8 @@ #include "FECEnabled.h" #include "wifibroadcast-spdlog.h" +#include "FEC.hpp" + void FECEncoder::encode_block( std::vector>> data_packets, int n_secondary_fragments) { @@ -87,7 +89,7 @@ void FECEncoder::encode_block( bool RxBlock::hasFragment(const int fragment_idx) { assert(fragment_idx RxBlock::pullAvailablePrimaryFragments( // note: when pulling the available fragments, we do not need to know how many primary fragments this block actually contains std::vector ret; for (int i = nAlreadyForwardedPrimaryFragments; i < m_n_available_primary_fragments; i++) { - if (fragment_map[i] == FragmentStatus::UNAVAILABLE) { + if (fragment_map[i] == FRAGMENT_STATUS_UNAVAILABLE) { if (discardMissingPackets) { continue; } else { @@ -177,7 +179,7 @@ std::vector RxBlock::pullAvailablePrimaryFragments( } const uint8_t* RxBlock::get_primary_fragment_data_p(const int fragment_index) { - assert(fragment_map[fragment_index] == AVAILABLE); + assert(fragment_map[fragment_index] == FRAGMENT_STATUS_AVAILABLE); assert(m_n_primary_fragments_in_block !=-1); assert(fragment_index< m_n_primary_fragments_in_block); //return blockBuffer[fragment_index].data()+sizeof(FECPayloadHdr); @@ -185,7 +187,7 @@ const uint8_t* RxBlock::get_primary_fragment_data_p(const int fragment_index) { } const int RxBlock::get_primary_fragment_data_size(const int fragment_index) { - assert(fragment_map[fragment_index] == AVAILABLE); + assert(fragment_map[fragment_index] == FRAGMENT_STATUS_AVAILABLE); assert(m_n_primary_fragments_in_block !=-1); assert(fragment_index< m_n_primary_fragments_in_block); uint16_t* len_p=(uint16_t*)blockBuffer[fragment_index].data(); @@ -205,7 +207,7 @@ int RxBlock::reconstructAllMissingData() { m_n_primary_fragments_in_block, fragment_map); // now mark them as available for (const auto idx: recoveredFragmentIndices) { - fragment_map[idx] = AVAILABLE; + fragment_map[idx] = FRAGMENT_STATUS_AVAILABLE; } m_n_available_primary_fragments += recoveredFragmentIndices.size(); // n of reconstructed packets diff --git a/src/FECEnabled.h b/src/FECEnabled.h index b0fc8708..059fb31c 100644 --- a/src/FECEnabled.h +++ b/src/FECEnabled.h @@ -117,7 +117,7 @@ class RxBlock { // allocate much more memory every time for a new RX block than needed. explicit RxBlock(const unsigned int maxNFragmentsPerBlock, const uint64_t blockIdx1) :blockIdx(blockIdx1), - fragment_map(maxNFragmentsPerBlock,FragmentStatus::UNAVAILABLE), //after creation of the RxBlock every f. is marked as unavailable + fragment_map(maxNFragmentsPerBlock,FRAGMENT_STATUS_UNAVAILABLE), //after creation of the RxBlock every f. is marked as unavailable blockBuffer(maxNFragmentsPerBlock) { assert(fragment_map.size() == blockBuffer.size()); } @@ -185,7 +185,7 @@ class RxBlock { // n of primary fragments that are already pulled out int nAlreadyForwardedPrimaryFragments = 0; // for each fragment (via fragment_idx) store if it has been received yet - std::vector fragment_map; + std::vector fragment_map; // holds all the data for all received fragments (if fragment_map says UNAVALIABLE at this position, content is undefined) std::vector> blockBuffer; // time point when the first fragment for this block was received (via addFragment() )