From d7d3893b67c44cb1e9f06c877a25c7c2fa9177ac Mon Sep 17 00:00:00 2001
From: Matthew D Jones <matthew.d.jones@tessella.com>
Date: Fri, 19 Feb 2016 09:14:46 +0000
Subject: [PATCH] Re #15287 Use unordered_set in place of set

---
 .../MantidDataHandling/DownloadInstrument.h   |  2 +-
 .../inc/MantidDataHandling/Load.h             |  2 +-
 .../inc/MantidDataHandling/LoadRKH.h          |  4 ++--
 .../DataHandling/src/DownloadInstrument.cpp   |  4 ++--
 .../src/EventWorkspaceCollection.cpp          |  2 +-
 .../src/FilterEventsByLogValuePreNexus.cpp    | 19 ++++++++-----------
 .../DataHandling/src/LoadEventPreNexus2.cpp   |  3 +--
 Framework/DataHandling/src/LoadIsawDetCal.cpp |  5 ++---
 .../DataHandling/src/LoadVulcanCalFile.cpp    |  3 +--
 .../src/ScriptRepositoryImpl.cpp              |  4 ++--
 MantidPlot/src/PythonScript.cpp               |  5 ++---
 .../API/inc/MantidQtAPI/InterfaceFactory.h    |  6 ++----
 .../inc/MantidQtMantidWidgets/CatalogSearch.h |  4 ++--
 MantidQt/MantidWidgets/src/CatalogSearch.cpp  | 12 ++++++------
 .../MantidWidgets/src/InstrumentSelector.cpp  | 12 +++++-------
 15 files changed, 38 insertions(+), 49 deletions(-)

diff --git a/Framework/DataHandling/inc/MantidDataHandling/DownloadInstrument.h b/Framework/DataHandling/inc/MantidDataHandling/DownloadInstrument.h
index e9e4453764f..52b68a65418 100644
--- a/Framework/DataHandling/inc/MantidDataHandling/DownloadInstrument.h
+++ b/Framework/DataHandling/inc/MantidDataHandling/DownloadInstrument.h
@@ -63,7 +63,7 @@ private:
 
   size_t
   removeOrphanedFiles(const std::string &directoryPath,
-                      const std::set<std::string> &filenamesToKeep) const;
+                      const std::unordered_set<std::string> &filenamesToKeep) const;
 
   Kernel::ProxyInfo m_proxyInfo;
 };
diff --git a/Framework/DataHandling/inc/MantidDataHandling/Load.h b/Framework/DataHandling/inc/MantidDataHandling/Load.h
index 521d80f563f..40c66ae8d75 100644
--- a/Framework/DataHandling/inc/MantidDataHandling/Load.h
+++ b/Framework/DataHandling/inc/MantidDataHandling/Load.h
@@ -105,7 +105,7 @@ private:
   groupWsList(const std::vector<API::Workspace_sptr> &wsList);
 
   /// The base properties
-  std::set<std::string> m_baseProps;
+  std::unordered_set<std::string> m_baseProps;
   /// The actual loader
   API::IAlgorithm_sptr m_loader;
   /// The name of the property that will be passed the property from our
diff --git a/Framework/DataHandling/inc/MantidDataHandling/LoadRKH.h b/Framework/DataHandling/inc/MantidDataHandling/LoadRKH.h
index 20bef365ca9..14b68523a43 100644
--- a/Framework/DataHandling/inc/MantidDataHandling/LoadRKH.h
+++ b/Framework/DataHandling/inc/MantidDataHandling/LoadRKH.h
@@ -70,9 +70,9 @@ public:
 
 private:
   /// Store the units known to the UnitFactory
-  std::set<std::string> m_unitKeys;
+  std::unordered_set<std::string> m_unitKeys;
   /// Store the units added as options for this algorithm
-  std::set<std::string> m_RKHKeys;
+  std::unordered_set<std::string> m_RKHKeys;
   /// the input stream for the file being loaded
   std::ifstream m_fileIn;
 
diff --git a/Framework/DataHandling/src/DownloadInstrument.cpp b/Framework/DataHandling/src/DownloadInstrument.cpp
index 8df3f25d29e..2ac3f74bca8 100644
--- a/Framework/DataHandling/src/DownloadInstrument.cpp
+++ b/Framework/DataHandling/src/DownloadInstrument.cpp
@@ -177,7 +177,7 @@ DownloadInstrument::StringToStringMap DownloadInstrument::processRepository() {
   }
   fileStream.close();
 
-  std::set<std::string> repoFilenames;
+  std::unordered_set<std::string> repoFilenames;
 
   for (auto &serverElement : serverContents) {
     std::string name = serverElement.get("name", "").asString();
@@ -268,7 +268,7 @@ DownloadInstrument::getFileShas(const std::string &directoryPath) {
 **/
 size_t DownloadInstrument::removeOrphanedFiles(
     const std::string &directoryPath,
-    const std::set<std::string> &filenamesToKeep) const {
+    const std::unordered_set<std::string> &filenamesToKeep) const {
   // hold files to delete in a set so we don't remove files while iterating over
   // the directory.
   std::vector<std::string> filesToDelete;
diff --git a/Framework/DataHandling/src/EventWorkspaceCollection.cpp b/Framework/DataHandling/src/EventWorkspaceCollection.cpp
index 353375c27dd..80f7e581ab9 100644
--- a/Framework/DataHandling/src/EventWorkspaceCollection.cpp
+++ b/Framework/DataHandling/src/EventWorkspaceCollection.cpp
@@ -80,7 +80,7 @@ void EventWorkspaceCollection::setNPeriods(
   m_WsVec = std::vector<DataObjects::EventWorkspace_sptr>(nPeriods);
 
   std::vector<int> periodNumbers = periodLog->valuesAsVector();
-  std::set<int> uniquePeriods(periodNumbers.begin(), periodNumbers.end());
+  std::unordered_set<int> uniquePeriods(periodNumbers.begin(), periodNumbers.end());
   const bool addBoolTimeSeries = (uniquePeriods.size() == nPeriods);
 
   for (size_t i = 0; i < m_WsVec.size(); ++i) {
diff --git a/Framework/DataHandling/src/FilterEventsByLogValuePreNexus.cpp b/Framework/DataHandling/src/FilterEventsByLogValuePreNexus.cpp
index e46079a5b52..9e62bf78ddc 100644
--- a/Framework/DataHandling/src/FilterEventsByLogValuePreNexus.cpp
+++ b/Framework/DataHandling/src/FilterEventsByLogValuePreNexus.cpp
@@ -598,9 +598,9 @@ FilterEventsByLogValuePreNexus::setupOutputEventWorkspace() {
   * (3) (Optionally) write out information
   */
 void FilterEventsByLogValuePreNexus::processEventLogs() {
-  std::set<PixelType>::iterator pit;
   std::map<PixelType, size_t>::iterator mit;
-  for (pit = this->wrongdetids.begin(); pit != this->wrongdetids.end(); ++pit) {
+  for (auto pit = this->wrongdetids.begin(); pit != this->wrongdetids.end();
+       ++pit) {
     // Convert Pixel ID to 'wrong detectors ID' map's index
     PixelType pid = *pit;
     mit = this->wrongdetidmap.find(pid);
@@ -1110,8 +1110,7 @@ void FilterEventsByLogValuePreNexus::procEvents(
                    << "Number of Wrong Detector IDs = " << wrongdetids.size()
                    << "\n";
 
-    std::set<PixelType>::iterator wit;
-    for (wit = this->wrongdetids.begin(); wit != this->wrongdetids.end();
+    for (auto wit = this->wrongdetids.begin(); wit != this->wrongdetids.end();
          ++wit) {
       g_log.notice() << "Wrong Detector ID : " << *wit << std::endl;
     }
@@ -1360,8 +1359,8 @@ void FilterEventsByLogValuePreNexus::procEventsLinear(
     this->m_numBadEvents += local_numBadEvents;
     this->m_numWrongdetidEvents += local_numWrongdetidEvents;
 
-    std::set<PixelType>::iterator it;
-    for (it = local_wrongdetids.begin(); it != local_wrongdetids.end(); ++it) {
+    for (auto it = local_wrongdetids.begin(); it != local_wrongdetids.end();
+         ++it) {
       PixelType tmpid = *it;
       this->wrongdetids.insert(*it);
 
@@ -1757,14 +1756,12 @@ void FilterEventsByLogValuePreNexus::filterEvents() {
                    << " microsec; longest TOF: " << m_longestTof << " microsec."
                    << "\n";
 
-    std::set<PixelType>::iterator wit;
-    for (wit = this->wrongdetids.begin(); wit != this->wrongdetids.end();
+    for (auto wit = this->wrongdetids.begin(); wit != this->wrongdetids.end();
          ++wit) {
       g_log.notice() << "Wrong Detector ID : " << *wit << std::endl;
     }
-    std::map<PixelType, size_t>::iterator git;
-    for (git = this->wrongdetidmap.begin(); git != this->wrongdetidmap.end();
-         ++git) {
+    for (auto git = this->wrongdetidmap.begin();
+         git != this->wrongdetidmap.end(); ++git) {
       PixelType tmpid = git->first;
       size_t vindex = git->second;
       g_log.notice() << "Pixel " << tmpid << ":  Total number of events = "
diff --git a/Framework/DataHandling/src/LoadEventPreNexus2.cpp b/Framework/DataHandling/src/LoadEventPreNexus2.cpp
index 068211abfc7..1a1a554d6be 100644
--- a/Framework/DataHandling/src/LoadEventPreNexus2.cpp
+++ b/Framework/DataHandling/src/LoadEventPreNexus2.cpp
@@ -529,9 +529,8 @@ LoadEventPreNexus2::generateEventDistribtionWorkspace() {
 /** Process imbed logs (marked by bad pixel IDs)
  */
 void LoadEventPreNexus2::processImbedLogs() {
-  std::set<PixelType>::iterator pit;
   std::map<PixelType, size_t>::iterator mit;
-  for (pit = this->wrongdetids.begin(); pit != this->wrongdetids.end(); ++pit) {
+  for (auto pit = this->wrongdetids.begin(); pit != this->wrongdetids.end(); ++pit) {
     // a. pixel ID -> index
     PixelType pid = *pit;
     mit = this->wrongdetidmap.find(pid);
diff --git a/Framework/DataHandling/src/LoadIsawDetCal.cpp b/Framework/DataHandling/src/LoadIsawDetCal.cpp
index dc4210e84fe..1896c1a09b3 100644
--- a/Framework/DataHandling/src/LoadIsawDetCal.cpp
+++ b/Framework/DataHandling/src/LoadIsawDetCal.cpp
@@ -130,7 +130,7 @@ void LoadIsawDetCal::exec() {
       }
     }
   }
-  std::set<int> uniqueBanks; // for CORELLI and WISH
+  std::unordered_set<int> uniqueBanks; // for CORELLI and WISH
   std::string bankPart = "bank";
   if (instname.compare("WISH") == 0)
     bankPart = "WISHpanel";
@@ -295,8 +295,7 @@ void LoadIsawDetCal::exec() {
     }
     // Loop through tube detectors to match names with number from DetCal file
     idnum = -1;
-    std::set<int>::iterator it;
-    for (it = uniqueBanks.begin(); it != uniqueBanks.end(); ++it)
+    for (auto it = uniqueBanks.begin(); it != uniqueBanks.end(); ++it)
       if (*it == id)
         idnum = *it;
     if (idnum < 0)
diff --git a/Framework/DataHandling/src/LoadVulcanCalFile.cpp b/Framework/DataHandling/src/LoadVulcanCalFile.cpp
index 4e0b22c9fdd..0c69f3d9fb6 100644
--- a/Framework/DataHandling/src/LoadVulcanCalFile.cpp
+++ b/Framework/DataHandling/src/LoadVulcanCalFile.cpp
@@ -435,11 +435,10 @@ void LoadVulcanCalFile::processOffsets(
   }
 
   // Get the global correction
-  std::set<int>::iterator biter;
   g_log.information() << "Number of bankds to process = " << set_bankID.size()
                       << "\n";
   map<int, double> map_bankLogCorr;
-  for (biter = set_bankID.begin(); biter != set_bankID.end(); ++biter) {
+  for (auto biter = set_bankID.begin(); biter != set_bankID.end(); ++biter) {
     // Locate inter bank and inter pack correction (log)
     int bankid = *biter;
     double globalfactor = 0.;
diff --git a/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp b/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp
index feefdddd7f4..6d412c2749d 100644
--- a/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp
+++ b/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp
@@ -1482,7 +1482,7 @@ void ScriptRepositoryImpl::parseDownloadedEntries(Repository &repo) {
   std::string filename = std::string(local_repository).append(".local.json");
   std::vector<std::string> entries_to_delete;
   Repository::iterator entry_it;
-  std::set<std::string> folders_of_deleted;
+  std::unordered_set<std::string> folders_of_deleted;
 
   try {
     Json::Value pt = readJsonFile(filename, "Error reading .local.json file");
@@ -1530,7 +1530,7 @@ void ScriptRepositoryImpl::parseDownloadedEntries(Repository &repo) {
     if (entries_to_delete.size() > 0) {
 
       // clear the auto_update flag from the folders if the user deleted files
-      BOOST_FOREACH (const std::string &folder, folders_of_deleted) {
+      for (const auto &folder : folders_of_deleted) {
         if (!pt.isMember(folder))
           continue;
 
diff --git a/MantidPlot/src/PythonScript.cpp b/MantidPlot/src/PythonScript.cpp
index 7453f5b3397..ef4158b60c2 100644
--- a/MantidPlot/src/PythonScript.cpp
+++ b/MantidPlot/src/PythonScript.cpp
@@ -698,7 +698,7 @@ bool PythonScript::executeString()
   if(!result)
   {
     emit_error();
-    // If a script was aborted we both raise a KeyboardInterrupt and 
+    // If a script was aborted we both raise a KeyboardInterrupt and
     // call Algorithm::cancel to make sure we capture it. The doubling
     // can leave an interrupt in the pipeline so we clear it was we've
     // got the error info out
@@ -926,8 +926,7 @@ void PythonScript::postDeleteHandle(const std::string& wsName)
  */
 void PythonScript::clearADSHandle()
 {
-  std::set<std::string>::const_iterator iend = m_workspaceHandles.end();
-  for( std::set<std::string>::const_iterator itr = m_workspaceHandles.begin(); itr != iend; )
+  for( auto itr = m_workspaceHandles.cbegin(); itr != m_workspaceHandles.cend(); )
   {
     // This also erases the element from current set. The standard says that erase only invalidates
     // iterators of erased elements so we need to increment the iterator and get back the previous value
diff --git a/MantidQt/API/inc/MantidQtAPI/InterfaceFactory.h b/MantidQt/API/inc/MantidQtAPI/InterfaceFactory.h
index 96265d85f96..dae2a6d3b5c 100644
--- a/MantidQt/API/inc/MantidQtAPI/InterfaceFactory.h
+++ b/MantidQt/API/inc/MantidQtAPI/InterfaceFactory.h
@@ -172,11 +172,9 @@ template<typename TYPE>
 void UserSubWindowFactoryImpl::saveAliasNames(const std::string & realName)
 {
   std::set<std::string> aliases = TYPE::aliases();
-  std::set<std::string>::const_iterator iend = aliases.end();
-  for( std::set<std::string>::const_iterator itr = aliases.begin(); itr != iend;
-       ++itr )
+  for(const auto &alias_std_str : aliases)
   {
-    QString alias = QString::fromStdString(*itr);
+    QString alias = QString::fromStdString(alias_std_str);
     if( m_aliasLookup.contains(alias) )
     {
       if( m_badAliases.contains(alias) )
diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/CatalogSearch.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/CatalogSearch.h
index e1cc2314bb8..b518db5b06e 100644
--- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/CatalogSearch.h
+++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/CatalogSearch.h
@@ -111,9 +111,9 @@ namespace MantidQt
       /// Updates the dataFile text boxes with relevant info about the selected dataFile.
       void updateDataFileLabels(QTableWidgetItem* item);
       /// Obtain all file extensions from the provided column (dataFileResults -> File name).
-      std::set<std::string> getDataFileExtensions(Mantid::API::Column_sptr column);
+      std::unordered_set<std::string> getDataFileExtensions(Mantid::API::Column_sptr column);
       /// Add the list of file extensions to the "Filter type..." drop-down.
-      void populateDataFileType(const std::set<std::string> &extensions);
+      void populateDataFileType(const std::unordered_set<std::string> &extensions);
       /// Disable the download button if user can access the files locally from the archives.
       void disableDownloadButtonIfArchives(int row);
 
diff --git a/MantidQt/MantidWidgets/src/CatalogSearch.cpp b/MantidQt/MantidWidgets/src/CatalogSearch.cpp
index e167dd5e634..1930ad929a2 100644
--- a/MantidQt/MantidWidgets/src/CatalogSearch.cpp
+++ b/MantidQt/MantidWidgets/src/CatalogSearch.cpp
@@ -968,7 +968,7 @@ namespace MantidQt
 
       // Obtain the list of extensions of all dataFiles for the chosen investigation.
       // "File name" is the first column of "dataFileResults" so we make use of it.
-      std::set<std::string> extensions = getDataFileExtensions(workspace.get()->getColumn(headerIndexByName(dataFileTable, "Name")));
+      auto extensions = getDataFileExtensions(workspace.get()->getColumn(headerIndexByName(dataFileTable, "Name")));
 
       // Populate the "Filter type..." combo-box with all possible file extensions.
       populateDataFileType(extensions);
@@ -1057,9 +1057,9 @@ namespace MantidQt
      * @param column :: The fileName column in the dataFile workspace.
      * @return A set containing all file extensions.
      */
-    std::set<std::string> CatalogSearch::getDataFileExtensions(Mantid::API::Column_sptr column)
+    std::unordered_set<std::string> CatalogSearch::getDataFileExtensions(Mantid::API::Column_sptr column)
     {
-      std::set<std::string> extensions;
+      std::unordered_set<std::string> extensions;
 
       // For every filename in the column...
       for (unsigned row = 0; row < column->size(); row++)
@@ -1075,11 +1075,11 @@ namespace MantidQt
     /**
      * Add the list of file extensions to the "Filter type..." drop-down.
      */
-    void CatalogSearch::populateDataFileType(const std::set<std::string> &extensions)
+    void CatalogSearch::populateDataFileType(const std::unordered_set<std::string> &extensions)
     {
-      for( std::set<std::string>::const_iterator iter = extensions.begin(); iter != extensions.end(); ++iter)
+      for(const auto &extension : extensions)
       {
-        m_icatUiForm.dataFileFilterCombo->addItem(QString::fromStdString("." + *iter));
+        m_icatUiForm.dataFileFilterCombo->addItem(QString::fromStdString("." + extension));
       }
     }
 
diff --git a/MantidQt/MantidWidgets/src/InstrumentSelector.cpp b/MantidQt/MantidWidgets/src/InstrumentSelector.cpp
index 16651765060..8663d5bf323 100644
--- a/MantidQt/MantidWidgets/src/InstrumentSelector.cpp
+++ b/MantidQt/MantidWidgets/src/InstrumentSelector.cpp
@@ -180,18 +180,16 @@ namespace MantidWidgets
       m_currentFacility = &(mantidSettings.getFacility(mantidSettings.getFacilityNames()[0]));
     }
 
-    const std::vector<InstrumentInfo> & instruments = m_currentFacility->instruments();
-    std::vector<InstrumentInfo>::const_iterator iend = instruments.end();
+    const auto &instruments = m_currentFacility->instruments();
     std::set<std::string> alphabetizedNames;
-    for( std::vector<InstrumentInfo>::const_iterator itr = instruments.begin(); itr != iend; ++itr )
+    for( auto itr = instruments.cbegin(); itr != instruments.cend(); ++itr )
     {
       alphabetizedNames.insert(itr->name());
     }
-    std::set<std::string>::const_iterator namesEnd = alphabetizedNames.end();
-    for( std::set<std::string>::const_iterator itr = alphabetizedNames.begin(); itr != namesEnd; ++itr )
+    for(const auto &name_std_str : alphabetizedNames)
     {
-      QString name = QString::fromStdString(*itr);
-      std::string prefix = m_currentFacility->instrument(*itr).shortName();
+      QString name = QString::fromStdString(name_std_str);
+      std::string prefix = m_currentFacility->instrument(name_std_str).shortName();
       QString shortName = QString::fromStdString(prefix);
       this->addItem(name, QVariant(shortName));
     }
-- 
GitLab