route: rename Map to NameMap

The `Map` type is renamed to `NameMap` to better reflect what it does.

`createFromAdjLsdb` and `createFromCoordinateLsdb` functions are changed
to static functions, to match how they are used in callsites.

Unnecessary shared_ptr usage in `createFromAdjLsdb` is eliminated.

Doxygen of `NameMap` is added or improved.

refs #5308

Change-Id: I05db235efc1c6719f14b96758e3acde7826aabe7
diff --git a/src/common.hpp b/src/common.hpp
index a0db086..2076cae 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2022,  The University of Memphis,
+ * Copyright (c) 2014-2024,  The University of Memphis,
  *                           Regents of the University of California
  *
  * This file is part of NLSR (Named-data Link State Routing).
@@ -39,21 +39,6 @@
 
 constexpr ndn::time::seconds TIME_ALLOWED_FOR_CANONIZATION = 4_s;
 
-template<typename T, typename = void>
-struct is_iterator
-{
-  static constexpr bool value = false;
-};
-
-/*! Use C++11 iterator_traits to check if some type is an iterator
- */
-template<typename T>
-struct is_iterator<T, std::enable_if_t<!std::is_same_v<
-  typename std::iterator_traits<T>::value_type, void>>>
-{
-  static constexpr bool value = true;
-};
-
 } // namespace nlsr
 
 #endif // NLSR_COMMON_HPP
diff --git a/src/route/map.hpp b/src/route/map.hpp
deleted file mode 100644
index c43a777..0000000
--- a/src/route/map.hpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2024,  The University of Memphis,
- *                           Regents of the University of California
- *
- * This file is part of NLSR (Named-data Link State Routing).
- * See AUTHORS.md for complete list of NLSR authors and contributors.
- *
- * NLSR is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NLSR, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NLSR_MAP_HPP
-#define NLSR_MAP_HPP
-
-#include "common.hpp"
-#include "lsa/adj-lsa.hpp"
-
-#include <boost/bimap.hpp>
-#include <boost/bimap/unordered_set_of.hpp>
-
-#include <optional>
-
-namespace nlsr {
-
-class Map
-{
-public:
-  /*! \brief Add a map entry to this map.
-    \param rtrName The name of the router.
-
-    Adds a router to this map. Each entry is also given an arbitrary,
-    ascending mappingNo (mapping number).
-  */
-  void
-  addEntry(const ndn::Name& rtrName);
-
-  /*! Populates the Map with AdjacencyLsas.
-
-    \note IteratorType must an iterator type, and begin to end must represent a valid range.
-  */
-  template<typename IteratorType>
-  void
-  createFromAdjLsdb(IteratorType begin, IteratorType end)
-  {
-    BOOST_STATIC_ASSERT_MSG(is_iterator<IteratorType>::value, "IteratorType must be an iterator!");
-    for (auto lsa = begin; lsa != end; lsa++) {
-      auto adjLsa = std::static_pointer_cast<AdjLsa>(*lsa);
-      addEntry(adjLsa->getOriginRouter());
-      for (const auto& adjacent : adjLsa->getAdl().getAdjList()) {
-        addEntry(adjacent.getName());
-      }
-    }
-  }
-
-  /*! Populates the Map with CoordinateLsas.
-
-    \note IteratorType must an iterator type, and begin to end must represent a valid range.
-  */
-  template<typename IteratorType>
-  void
-  createFromCoordinateLsdb(IteratorType begin, IteratorType end)
-  {
-    BOOST_STATIC_ASSERT_MSG(is_iterator<IteratorType>::value, "IteratorType must be an iterator!");
-    for (auto lsa = begin; lsa != end; lsa++) {
-      addEntry((*lsa)->getOriginRouter());
-    }
-  }
-
-  std::optional<ndn::Name>
-  getRouterNameByMappingNo(int32_t mn) const;
-
-  std::optional<int32_t>
-  getMappingNoByRouterName(const ndn::Name& rName);
-
-  size_t
-  size() const
-  {
-    return m_bimap.size();
-  }
-
-private:
-  struct MappingNo;
-  boost::bimap<
-    boost::bimaps::unordered_set_of<
-      boost::bimaps::tagged<ndn::Name, ndn::Name>,
-      std::hash<ndn::Name>
-    >,
-    boost::bimaps::unordered_set_of<
-      boost::bimaps::tagged<int32_t, MappingNo>
-    >
-  > m_bimap;
-
-  friend std::ostream&
-  operator<<(std::ostream& os, const Map& map);
-};
-
-std::ostream&
-operator<<(std::ostream& os, const Map& map);
-
-} // namespace nlsr
-
-#endif // NLSR_MAP_HPP
diff --git a/src/route/map.cpp b/src/route/name-map.cpp
similarity index 79%
rename from src/route/map.cpp
rename to src/route/name-map.cpp
index 17b7113..3bc9de5 100644
--- a/src/route/map.cpp
+++ b/src/route/name-map.cpp
@@ -18,7 +18,7 @@
  * NLSR, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "map.hpp"
+#include "name-map.hpp"
 #include "nlsr.hpp"
 #include "adjacent.hpp"
 #include "lsa/lsa.hpp"
@@ -27,14 +27,14 @@
 namespace nlsr {
 
 void
-Map::addEntry(const ndn::Name& rtrName)
+NameMap::addEntry(const ndn::Name& rtrName)
 {
   int32_t mappingNo = static_cast<int32_t>(m_bimap.size());
   m_bimap.by<ndn::Name>().insert({rtrName, mappingNo});
 }
 
 std::optional<ndn::Name>
-Map::getRouterNameByMappingNo(int32_t mn) const
+NameMap::getRouterNameByMappingNo(int32_t mn) const
 {
   auto it = m_bimap.by<MappingNo>().find(mn);
   if (it == m_bimap.by<MappingNo>().end()) {
@@ -44,22 +44,22 @@
 }
 
 std::optional<int32_t>
-Map::getMappingNoByRouterName(const ndn::Name& rName)
+NameMap::getMappingNoByRouterName(const ndn::Name& rtrName) const
 {
-  auto it = m_bimap.by<ndn::Name>().find(rName);
+  auto it = m_bimap.by<ndn::Name>().find(rtrName);
   if (it == m_bimap.by<ndn::Name>().end()) {
     return std::nullopt;
   }
-  return it->get<Map::MappingNo>();
+  return it->get<MappingNo>();
 }
 
 std::ostream&
-operator<<(std::ostream& os, const Map& map)
+operator<<(std::ostream& os, const NameMap& map)
 {
-  os << "---------------Map----------------------";
+  os << "---------------NameMap---------------";
   for (const auto& entry : map.m_bimap) {
     os << "\nMapEntry: ( Router: " << entry.get<ndn::Name>()
-       << " Mapping No: " << entry.get<Map::MappingNo>() << " )";
+       << " Mapping No: " << entry.get<NameMap::MappingNo>() << " )";
   }
   return os;
 }
diff --git a/src/route/name-map.hpp b/src/route/name-map.hpp
new file mode 100644
index 0000000..00585a5
--- /dev/null
+++ b/src/route/name-map.hpp
@@ -0,0 +1,146 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2024,  The University of Memphis,
+ *                           Regents of the University of California
+ *
+ * This file is part of NLSR (Named-data Link State Routing).
+ * See AUTHORS.md for complete list of NLSR authors and contributors.
+ *
+ * NLSR is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NLSR, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NLSR_NAME_MAP_HPP
+#define NLSR_NAME_MAP_HPP
+
+#include "common.hpp"
+#include "lsa/adj-lsa.hpp"
+
+#include <boost/bimap.hpp>
+#include <boost/bimap/unordered_set_of.hpp>
+#include <boost/concept_check.hpp>
+
+#include <optional>
+
+namespace nlsr {
+
+/**
+ * @brief Assigning numbers to router names.
+ *
+ * NameMap assigns a "mapping number" to each inserted router name. It then provides bidirectional
+ * lookups between router names and their mapping numbers.
+ *
+ * These numbers are non-negative integers assigned sequentially, starting from zero. They can
+ * support constructing a matrix of routers, where the mapping numbers are used as row and column
+ * indices in place of router names.
+ */
+class NameMap
+{
+public:
+  /**
+   * @brief Create a NameMap populated with router names in Adjacency LSAs.
+   * @tparam IteratorType A *LegacyInputIterator* whose value type is convertible to
+   *                      `std::shared_ptr<AdjLsa>`.
+   * @param first Range begin iterator.
+   * @param last Range past-end iterator. It must be reachable by incrementing @p first .
+   * @returns NameMap populated with origin and adjacent router names.
+   */
+  template<typename IteratorType>
+  static NameMap
+  createFromAdjLsdb(IteratorType first, IteratorType last)
+  {
+    BOOST_CONCEPT_ASSERT((boost::InputIterator<IteratorType>));
+    NameMap map;
+    for (auto it = first; it != last; ++it) {
+      // *it has type std::shared_ptr<Lsa> ; it->get() has type Lsa*
+      auto lsa = static_cast<const AdjLsa*>(it->get());
+      map.addEntry(lsa->getOriginRouter());
+      for (const auto& adjacent : lsa->getAdl().getAdjList()) {
+        map.addEntry(adjacent.getName());
+      }
+    }
+    return map;
+  }
+
+  /**
+   * @brief Create a NameMap populated with router names in Coordinate LSAs.
+   * @tparam IteratorType A *LegacyInputIterator* whose value type is `std::shared_ptr<Lsa>`.
+   * @param first Range begin iterator.
+   * @param last Range past-end iterator. It must be reachable by incrementing @p first .
+   * @returns NameMap populated with origin router names.
+   */
+  template<typename IteratorType>
+  static NameMap
+  createFromCoordinateLsdb(IteratorType first, IteratorType last)
+  {
+    BOOST_CONCEPT_ASSERT((boost::InputIterator<IteratorType>));
+    NameMap map;
+    for (auto it = first; it != last; ++it) {
+      map.addEntry((*it)->getOriginRouter());
+    }
+    return map;
+  }
+
+  /**
+   * @brief Insert a router name.
+   * @param rtrName Router name.
+   */
+  void
+  addEntry(const ndn::Name& rtrName);
+
+  /**
+   * @brief Find router name by its mapping number.
+   * @param mn Mapping number.
+   * @returns Router name, or @c std::nullopt if it does not exist.
+   */
+  std::optional<ndn::Name>
+  getRouterNameByMappingNo(int32_t mn) const;
+
+  /**
+   * @brief Find mapping number of a router name.
+   * @param rtrName Router name.
+   * @returns Mapping number, or @c std::nullopt if it does not exist.
+   */
+  std::optional<int32_t>
+  getMappingNoByRouterName(const ndn::Name& rtrName) const;
+
+  /**
+   * @brief Return number of entries in this container.
+   * @returns Number of entries in this container.
+   */
+  size_t
+  size() const
+  {
+    return m_bimap.size();
+  }
+
+private:
+  struct MappingNo;
+  boost::bimap<
+    boost::bimaps::unordered_set_of<
+      boost::bimaps::tagged<ndn::Name, ndn::Name>,
+      std::hash<ndn::Name>
+    >,
+    boost::bimaps::unordered_set_of<
+      boost::bimaps::tagged<int32_t, MappingNo>
+    >
+  > m_bimap;
+
+  friend std::ostream&
+  operator<<(std::ostream& os, const NameMap& map);
+};
+
+std::ostream&
+operator<<(std::ostream& os, const NameMap& map);
+
+} // namespace nlsr
+
+#endif // NLSR_NAME_MAP_HPP
diff --git a/src/route/routing-table-calculator.cpp b/src/route/routing-table-calculator.cpp
index e65f5c0..061e151 100644
--- a/src/route/routing-table-calculator.cpp
+++ b/src/route/routing-table-calculator.cpp
@@ -21,7 +21,7 @@
 
 #include "routing-table-calculator.hpp"
 #include "lsdb.hpp"
-#include "map.hpp"
+#include "name-map.hpp"
 #include "nexthop.hpp"
 #include "nlsr.hpp"
 #include "logger.hpp"
@@ -63,7 +63,7 @@
 }
 
 void
-RoutingTableCalculator::makeAdjMatrix(const Lsdb& lsdb, Map& pMap)
+RoutingTableCalculator::makeAdjMatrix(const Lsdb& lsdb, NameMap& pMap)
 {
   // For each LSA represented in the map
   auto lsaRange = lsdb.getLsdbIterator<AdjLsa>();
@@ -120,7 +120,7 @@
 }
 
 void
-RoutingTableCalculator::writeAdjMatrixLog(const Map& map) const
+RoutingTableCalculator::writeAdjMatrixLog(const NameMap& map) const
 {
   if (!ndn_cxx_getLogger().isLevelEnabled(ndn::util::LogLevel::DEBUG)) {
     return;
@@ -232,7 +232,7 @@
 }
 
 void
-LinkStateRoutingTableCalculator::calculatePath(Map& pMap, RoutingTable& rt,
+LinkStateRoutingTableCalculator::calculatePath(NameMap& pMap, RoutingTable& rt,
                                                ConfParameter& confParam,
                                                const Lsdb& lsdb)
 {
@@ -327,7 +327,7 @@
 
 void
 LinkStateRoutingTableCalculator::addAllLsNextHopsToRoutingTable(AdjacencyList& adjacencies,
-                                                                RoutingTable& rt, Map& pMap,
+                                                                RoutingTable& rt, NameMap& pMap,
                                                                 uint32_t sourceRouter)
 {
   NLSR_LOG_DEBUG("LinkStateRoutingTableCalculator::addAllNextHopsToRoutingTable Called");
@@ -426,7 +426,7 @@
 }
 
 void
-HyperbolicRoutingCalculator::calculatePath(Map& map, RoutingTable& rt,
+HyperbolicRoutingCalculator::calculatePath(NameMap& map, RoutingTable& rt,
                                            Lsdb& lsdb, AdjacencyList& adjacencies)
 {
   NLSR_LOG_TRACE("Calculating hyperbolic paths");
diff --git a/src/route/routing-table-calculator.hpp b/src/route/routing-table-calculator.hpp
index 45af713..35e08eb 100644
--- a/src/route/routing-table-calculator.hpp
+++ b/src/route/routing-table-calculator.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2023,  The University of Memphis,
+ * Copyright (c) 2014-2024,  The University of Memphis,
  *                           Regents of the University of California
  *
  * This file is part of NLSR (Named-data Link State Routing).
@@ -29,7 +29,7 @@
 
 namespace nlsr {
 
-class Map;
+class NameMap;
 class RoutingTable;
 
 class RoutingTableCalculator
@@ -55,13 +55,13 @@
     \param pMap The map to populate with the adj. data.
   */
   void
-  makeAdjMatrix(const Lsdb& lsdb, Map& pMap);
+  makeAdjMatrix(const Lsdb& lsdb, NameMap& pMap);
 
   /*! \brief Writes a formated adjacent matrix to DEBUG log
     \param map The map containing adjacent matrix data
   */
   void
-  writeAdjMatrixLog(const Map& map) const;
+  writeAdjMatrixLog(const NameMap& map) const;
 
   /*! \brief Returns how many links a router in the matrix has.
     \param sRouter The router to count the links of.
@@ -131,7 +131,7 @@
   }
 
   void
-  calculatePath(Map& pMap, RoutingTable& rt, ConfParameter& confParam,
+  calculatePath(NameMap& pMap, RoutingTable& rt, ConfParameter& confParam,
                 const Lsdb& lsdb);
 
 private:
@@ -167,7 +167,7 @@
 
   void
   addAllLsNextHopsToRoutingTable(AdjacencyList& adjacencies, RoutingTable& rt,
-                                 Map& pMap, uint32_t sourceRouter);
+                                 NameMap& pMap, uint32_t sourceRouter);
 
   /*! \brief Determines a destination's next hop.
     \param dest The router whose next hop we want to determine.
@@ -207,7 +207,7 @@
   }
 
   void
-  calculatePath(Map& map, RoutingTable& rt, Lsdb& lsdb, AdjacencyList& adjacencies);
+  calculatePath(NameMap& map, RoutingTable& rt, Lsdb& lsdb, AdjacencyList& adjacencies);
 
 private:
   double
diff --git a/src/route/routing-table.cpp b/src/route/routing-table.cpp
index fa7dee7..16bf2df 100644
--- a/src/route/routing-table.cpp
+++ b/src/route/routing-table.cpp
@@ -20,7 +20,7 @@
 
 #include "routing-table.hpp"
 #include "nlsr.hpp"
-#include "map.hpp"
+#include "name-map.hpp"
 #include "conf-parameter.hpp"
 #include "routing-table-calculator.hpp"
 #include "routing-table-entry.hpp"
@@ -127,9 +127,8 @@
 
   clearRoutingTable();
 
-  Map map;
   auto lsaRange = m_lsdb.getLsdbIterator<AdjLsa>();
-  map.createFromAdjLsdb(lsaRange.first, lsaRange.second);
+  auto map = NameMap::createFromAdjLsdb(lsaRange.first, lsaRange.second);
   NLSR_LOG_DEBUG(map);
 
   size_t nRouters = map.size();
@@ -153,9 +152,8 @@
     clearRoutingTable();
   }
 
-  Map map;
   auto lsaRange = m_lsdb.getLsdbIterator<CoordinateLsa>();
-  map.createFromCoordinateLsdb(lsaRange.first, lsaRange.second);
+  auto map = NameMap::createFromCoordinateLsdb(lsaRange.first, lsaRange.second);
   NLSR_LOG_DEBUG(map);
 
   size_t nRouters = map.size();
diff --git a/tests/route/test-hyperbolic-calculator.cpp b/tests/route/test-hyperbolic-calculator.cpp
index 5f22a53..7d50298 100644
--- a/tests/route/test-hyperbolic-calculator.cpp
+++ b/tests/route/test-hyperbolic-calculator.cpp
@@ -24,7 +24,7 @@
 #include "adjacency-list.hpp"
 #include "lsdb.hpp"
 #include "nlsr.hpp"
-#include "route/map.hpp"
+#include "route/name-map.hpp"
 #include "route/routing-table.hpp"
 
 #include "tests/io-key-chain-fixture.hpp"
@@ -100,7 +100,7 @@
     lsdb.installLsa(std::make_shared<CoordinateLsa>(coordC));
 
     auto lsaRange = lsdb.getLsdbIterator<CoordinateLsa>();
-    map.createFromCoordinateLsdb(lsaRange.first, lsaRange.second);
+    map = NameMap::createFromCoordinateLsdb(lsaRange.first, lsaRange.second);
   }
 
   void runTest(const double& expectedCost)
@@ -150,7 +150,7 @@
   ndn::DummyClientFace face;
   ConfParameter conf;
   Nlsr nlsr;
-  Map map;
+  NameMap map;
 
   RoutingTable& routingTable;
   AdjacencyList& adjacencies;
diff --git a/tests/route/test-link-state-calculator.cpp b/tests/route/test-link-state-calculator.cpp
index de1327f..40ed32f 100644
--- a/tests/route/test-link-state-calculator.cpp
+++ b/tests/route/test-link-state-calculator.cpp
@@ -25,7 +25,7 @@
 #include "adjacent.hpp"
 #include "lsdb.hpp"
 #include "nlsr.hpp"
-#include "route/map.hpp"
+#include "route/name-map.hpp"
 #include "route/routing-table.hpp"
 
 #include "tests/io-key-chain-fixture.hpp"
@@ -99,7 +99,7 @@
     lsdb.installLsa(std::make_shared<AdjLsa>(adjC));
 
     auto lsaRange = lsdb.getLsdbIterator<AdjLsa>();
-    map.createFromAdjLsdb(lsaRange.first, lsaRange.second);
+    map = NameMap::createFromAdjLsdb(lsaRange.first, lsaRange.second);
   }
 
 public:
@@ -107,7 +107,7 @@
   ConfParameter conf;
   DummyConfFileProcessor confProcessor;
   Nlsr nlsr;
-  Map map;
+  NameMap map;
 
   RoutingTable& routingTable;
   Lsdb& lsdb;
diff --git a/tests/route/test-map.cpp b/tests/route/test-name-map.cpp
similarity index 97%
rename from tests/route/test-map.cpp
rename to tests/route/test-name-map.cpp
index aabf055..e48f1aa 100644
--- a/tests/route/test-map.cpp
+++ b/tests/route/test-name-map.cpp
@@ -20,7 +20,7 @@
  * \author Ashlesh Gawande <agawande@memphis.edu>
  */
 
-#include "route/map.hpp"
+#include "route/name-map.hpp"
 
 #include "tests/boost-test.hpp"
 
@@ -30,7 +30,7 @@
 
 BOOST_AUTO_TEST_CASE(Basic)
 {
-  Map map1;
+  NameMap map1;
 
   ndn::Name name1("/r1");
   ndn::Name name2("/r2");