# HG changeset patch # User Alexander Krotov # Date 1482441731 -10800 # Fri Dec 23 00:22:11 2016 +0300 # Node ID 516a62142f78e6bb1749c4fce72a096ac7245dd1 # Parent 4115fe790dc3cef236a8654ac356961c3f966d98 spectrum: store Ptrs in vector to avoid sorting pointers diff --git a/src/spectrum/model/multi-model-spectrum-channel.cc b/src/spectrum/model/multi-model-spectrum-channel.cc --- a/src/spectrum/model/multi-model-spectrum-channel.cc +++ b/src/spectrum/model/multi-model-spectrum-channel.cc @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include "multi-model-spectrum-channel.h" @@ -159,13 +160,14 @@ rxInfoIterator != m_rxSpectrumModelInfoMap.end (); ++rxInfoIterator) { - std::set >::iterator phyIt = rxInfoIterator->second.m_rxPhySet.find (phy); - if (phyIt != rxInfoIterator->second.m_rxPhySet.end ()) + std::vector> &rxPhys = rxInfoIterator->second.m_rxPhys; + std::vector>::iterator phyIt = std::find (begin (rxPhys), end (rxPhys), phy); + if (phyIt != rxInfoIterator->second.m_rxPhys.end ()) { - rxInfoIterator->second.m_rxPhySet.erase (phyIt); + rxPhys.erase (phyIt); --m_numDevices; break; // there should be at most one entry - } + } } ++m_numDevices; @@ -179,8 +181,7 @@ ret = m_rxSpectrumModelInfoMap.insert (std::make_pair (rxSpectrumModelUid, RxSpectrumModelInfo (rxSpectrumModel))); NS_ASSERT (ret.second); // also add the phy to the newly created set of SpectrumPhy for this RxSpectrumModel - std::pair >::iterator, bool> ret2 = ret.first->second.m_rxPhySet.insert (phy); - NS_ASSERT (ret2.second); + ret.first->second.m_rxPhys.push_back (phy); // and create the necessary converters for all the TX spectrum models that we know of for (TxSpectrumModelInfoMap_t::iterator txInfoIterator = m_txSpectrumModelInfoMap.begin (); @@ -203,8 +204,7 @@ else { // spectrum model is already known, just add the device to the corresponding list - std::pair >::iterator, bool> ret2 = rxInfoIterator->second.m_rxPhySet.insert (phy); - NS_ASSERT (ret2.second); + rxInfoIterator->second.m_rxPhys.push_back (phy); } } @@ -301,8 +301,8 @@ } - for (std::set >::const_iterator rxPhyIterator = rxInfoIterator->second.m_rxPhySet.begin (); - rxPhyIterator != rxInfoIterator->second.m_rxPhySet.end (); + for (std::vector>::const_iterator rxPhyIterator = rxInfoIterator->second.m_rxPhys.begin (); + rxPhyIterator != rxInfoIterator->second.m_rxPhys.end (); ++rxPhyIterator) { NS_ASSERT_MSG ((*rxPhyIterator)->GetRxSpectrumModel ()->GetUid () == rxSpectrumModelUid, @@ -412,21 +412,16 @@ // acceptable as it is not used much at run time (often not at all). // On the other hand, having slow SpectrumModel conversion would be // less acceptable. - uint32_t j = 0; for (RxSpectrumModelInfoMap_t::const_iterator rxInfoIterator = m_rxSpectrumModelInfoMap.begin (); rxInfoIterator != m_rxSpectrumModelInfoMap.end (); ++rxInfoIterator) { - for (std::set >::const_iterator phyIt = rxInfoIterator->second.m_rxPhySet.begin (); - phyIt != rxInfoIterator->second.m_rxPhySet.end (); - ++phyIt) + const std::vector> &rxPhys = rxInfoIterator->second.m_rxPhys; + if (i < rxPhys.size ()) { - if (j == i) - { - return (*phyIt)->GetDevice (); - } - j++; + return rxPhys[i]->GetDevice (); } + i -= rxPhys.size (); } NS_FATAL_ERROR ("m_numDevice > actual number of devices"); return 0; diff --git a/src/spectrum/model/multi-model-spectrum-channel.h b/src/spectrum/model/multi-model-spectrum-channel.h --- a/src/spectrum/model/multi-model-spectrum-channel.h +++ b/src/spectrum/model/multi-model-spectrum-channel.h @@ -28,7 +28,6 @@ #include #include #include -#include namespace ns3 { @@ -80,7 +79,7 @@ RxSpectrumModelInfo (Ptr rxSpectrumModel); Ptr m_rxSpectrumModel; //!< Rx Spectrum model. - std::set > m_rxPhySet; //!< Container of the Rx Spectrum phy objects. + std::vector> m_rxPhys; //!< Container of the Rx Spectrum phy objects. }; /**