wifi: Replace linear search with map lookup in MinstrelHtWifiManager

This commit is contained in:
Alexander Krotov
2018-05-04 13:08:29 +03:00
parent a5ffde77d9
commit 04406a3c8e
2 changed files with 9 additions and 22 deletions

View File

@@ -339,44 +339,32 @@ Time
MinstrelHtWifiManager::GetFirstMpduTxTime (uint32_t groupId, WifiMode mode) const
{
NS_LOG_FUNCTION (this << groupId << mode);
for (TxTime::const_iterator i = m_minstrelGroups[groupId].ratesFirstMpduTxTimeTable.begin (); i != m_minstrelGroups[groupId].ratesFirstMpduTxTimeTable.end (); i++)
{
if (mode == i->second)
{
return i->first;
}
}
NS_ASSERT (false);
return Seconds (0);
auto it = m_minstrelGroups[groupId].ratesFirstMpduTxTimeTable.find (mode);
NS_ASSERT (it != m_minstrelGroups[groupId].ratesFirstMpduTxTimeTable.end ());
return it->second;
}
void
MinstrelHtWifiManager::AddFirstMpduTxTime (uint32_t groupId, WifiMode mode, Time t)
{
NS_LOG_FUNCTION (this << groupId << mode << t);
m_minstrelGroups[groupId].ratesFirstMpduTxTimeTable.push_back (std::make_pair (t, mode));
m_minstrelGroups[groupId].ratesFirstMpduTxTimeTable.insert (std::make_pair (mode, t));
}
Time
MinstrelHtWifiManager::GetMpduTxTime (uint32_t groupId, WifiMode mode) const
{
NS_LOG_FUNCTION (this << groupId << mode);
for (TxTime::const_iterator i = m_minstrelGroups[groupId].ratesTxTimeTable.begin (); i != m_minstrelGroups[groupId].ratesTxTimeTable.end (); i++)
{
if (mode == i->second)
{
return i->first;
}
}
NS_ASSERT (false);
return Seconds (0);
auto it = m_minstrelGroups[groupId].ratesTxTimeTable.find (mode);
NS_ASSERT (it != m_minstrelGroups[groupId].ratesTxTimeTable.end ());
return it->second;
}
void
MinstrelHtWifiManager::AddMpduTxTime (uint32_t groupId, WifiMode mode, Time t)
{
NS_LOG_FUNCTION (this << groupId << mode << t);
m_minstrelGroups[groupId].ratesTxTimeTable.push_back (std::make_pair (t, mode));
m_minstrelGroups[groupId].ratesTxTimeTable.insert (std::make_pair (mode, t));
}
WifiRemoteStation *

View File

@@ -33,9 +33,8 @@ namespace ns3 {
/**
* Data structure to save transmission time calculations per rate.
* A vector of Time, WifiMode pairs.
*/
typedef std::vector<std::pair<Time, WifiMode> > TxTime;
typedef std::map<WifiMode, Time> TxTime;
/**
* Data structure to contain the information that defines a group.