table: simplify pit::Entry API

refs #3546

Change-Id: I6a9cb83b9e56ce1d1bb6047049378c51781605af
diff --git a/daemon/fw/access-strategy.cpp b/daemon/fw/access-strategy.cpp
index 8d53168..862e165 100644
--- a/daemon/fw/access-strategy.cpp
+++ b/daemon/fw/access-strategy.cpp
@@ -195,14 +195,14 @@
     pi->rtoTimer.cancel();
   }
 
-  if (pitEntry->getInRecords().empty()) { // already satisfied by another upstream
+  if (!pitEntry->hasInRecords()) { // already satisfied by another upstream
     NFD_LOG_DEBUG(pitEntry->getInterest() << " dataFrom " << inFace.getId() <<
                   " not-fastest");
     return;
   }
 
-  pit::OutRecordCollection::const_iterator outRecord = pitEntry->getOutRecord(inFace);
-  if (outRecord == pitEntry->getOutRecords().end()) { // no OutRecord
+  pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(inFace);
+  if (outRecord == pitEntry->out_end()) { // no out-record
     NFD_LOG_DEBUG(pitEntry->getInterest() << " dataFrom " << inFace.getId() <<
                   " no-out-record");
     return;
diff --git a/daemon/fw/best-route-strategy2.cpp b/daemon/fw/best-route-strategy2.cpp
index 96791be..0644ba9 100644
--- a/daemon/fw/best-route-strategy2.cpp
+++ b/daemon/fw/best-route-strategy2.cpp
@@ -50,7 +50,7 @@
  *  \param pitEntry PIT entry
  *  \param nexthop next hop
  *  \param currentDownstream incoming FaceId of current Interest
- *  \param wantUnused if true, NextHop must not have unexpired OutRecord
+ *  \param wantUnused if true, NextHop must not have unexpired out-record
  *  \param now time::steady_clock::now(), ignored if !wantUnused
  */
 static inline bool
@@ -70,10 +70,9 @@
     return false;
 
   if (wantUnused) {
-    // NextHop must not have unexpired OutRecord
-    pit::OutRecordCollection::const_iterator outRecord = pitEntry->getOutRecord(*upstream);
-    if (outRecord != pitEntry->getOutRecords().end() &&
-        outRecord->getExpiry() > now) {
+    // NextHop must not have unexpired out-record
+    pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(*upstream);
+    if (outRecord != pitEntry->out_end() && outRecord->getExpiry() > now) {
       return false;
     }
   }
@@ -81,8 +80,8 @@
   return true;
 }
 
-/** \brief pick an eligible NextHop with earliest OutRecord
- *  \note It is assumed that every nexthop has an OutRecord
+/** \brief pick an eligible NextHop with earliest out-record
+ *  \note It is assumed that every nexthop has an out-record.
  */
 static inline fib::NextHopList::const_iterator
 findEligibleNextHopWithEarliestOutRecord(const shared_ptr<pit::Entry>& pitEntry,
@@ -94,8 +93,8 @@
   for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) {
     if (!predicate_NextHop_eligible(pitEntry, *it, currentDownstream))
       continue;
-    pit::OutRecordCollection::const_iterator outRecord = pitEntry->getOutRecord(*it->getFace());
-    BOOST_ASSERT(outRecord != pitEntry->getOutRecords().end());
+    pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(*it->getFace());
+    BOOST_ASSERT(outRecord != pitEntry->out_end());
     if (outRecord->getLastRenewed() < earliestRenewed) {
       found = it;
       earliestRenewed = outRecord->getLastRenewed();
@@ -209,8 +208,8 @@
 
   if (nOutRecordsNotNacked == 1) {
     BOOST_ASSERT(lastFaceNotNacked != nullptr);
-    pit::InRecordCollection::const_iterator inR = pitEntry->getInRecord(*lastFaceNotNacked);
-    if (inR != pitEntry->getInRecords().end()) {
+    pit::InRecordCollection::iterator inR = pitEntry->getInRecord(*lastFaceNotNacked);
+    if (inR != pitEntry->in_end()) {
       // one out-record not Nacked, which is also a downstream
       NFD_LOG_DEBUG(nack.getInterest() << " nack-from=" << inFace.getId() <<
                     " nack=" << nack.getReason() <<
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index ef792ae..b575e3b 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -142,9 +142,7 @@
   this->cancelUnsatisfyAndStragglerTimer(pitEntry);
 
   // is pending?
-  const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
-  bool isPending = inRecords.begin() != inRecords.end();
-  if (!isPending) {
+  if (!pitEntry->hasInRecords()) {
     m_cs.find(interest,
               bind(&Forwarder::onContentStoreHit, this, ref(inFace), pitEntry, _1, _2),
               bind(&Forwarder::onContentStoreMiss, this, ref(inFace), pitEntry, _1));
@@ -184,7 +182,7 @@
   NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName());
 
   shared_ptr<Face> face = const_pointer_cast<Face>(inFace.shared_from_this());
-  // insert InRecord
+  // insert in-record
   pitEntry->insertOrUpdateInRecord(face, interest);
 
   // set PIT unsatisfy timer
@@ -261,14 +259,14 @@
   this->onOutgoingData(data, *const_pointer_cast<Face>(inFace.shared_from_this()));
 }
 
-/** \brief compare two InRecords for picking outgoing Interest
+/** \brief compare two in-records for picking outgoing Interest
  *  \return true if b is preferred over a
  *
  *  This function should be passed to std::max_element over InRecordCollection.
  *  The outgoing Interest picked is the last incoming Interest
  *  that does not come from outFace.
- *  If all InRecords come from outFace, it's fine to pick that. This happens when
- *  there's only one InRecord that comes from outFace. The legit use is for
+ *  If all in-records come from outFace, it's fine to pick that. This happens when
+ *  there's only one in-record that comes from outFace. The legit use is for
  *  vehicular network; otherwise, strategy shouldn't send to the sole inFace.
  */
 static inline bool
@@ -306,12 +304,10 @@
   }
 
   // pick Interest
-  const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
-  pit::InRecordCollection::const_iterator pickedInRecord = std::max_element(
-    inRecords.begin(), inRecords.end(), bind(&compare_pickInterest, _1, _2, &outFace));
-  BOOST_ASSERT(pickedInRecord != inRecords.end());
-  shared_ptr<Interest> interest = const_pointer_cast<Interest>(
-    pickedInRecord->getInterest().shared_from_this());
+  pit::InRecordCollection::iterator pickedInRecord = std::max_element(
+    pitEntry->in_begin(), pitEntry->in_end(), bind(&compare_pickInterest, _1, _2, &outFace));
+  BOOST_ASSERT(pickedInRecord != pitEntry->in_end());
+  auto interest = const_pointer_cast<Interest>(pickedInRecord->getInterest().shared_from_this());
 
   if (wantNewNonce) {
     interest = make_shared<Interest>(*interest);
@@ -319,7 +315,7 @@
     interest->setNonce(dist(getGlobalRng()));
   }
 
-  // insert OutRecord
+  // insert out-record
   pitEntry->insertOrUpdateOutRecord(outFace.shared_from_this(), *interest);
 
   // send Interest
@@ -403,6 +399,7 @@
 
   std::set<Face*> pendingDownstreams;
   // foreach PitEntry
+  auto now = time::steady_clock::now();
   for (const shared_ptr<pit::Entry>& pitEntry : pitMatches) {
     NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName());
 
@@ -410,9 +407,8 @@
     this->cancelUnsatisfyAndStragglerTimer(pitEntry);
 
     // remember pending downstreams
-    const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
-    for (const pit::InRecord& inRecord : inRecords) {
-      if (inRecord.getExpiry() > time::steady_clock::now()) {
+    for (const pit::InRecord& inRecord : pitEntry->getInRecords()) {
+      if (inRecord.getExpiry() > now) {
         pendingDownstreams.insert(inRecord.getFace().get());
       }
     }
@@ -421,11 +417,11 @@
     this->dispatchToStrategy(pitEntry, bind(&Strategy::beforeSatisfyInterest, _1,
                                             pitEntry, cref(inFace), cref(data)));
 
-    // Dead Nonce List insert if necessary (for OutRecord of inFace)
+    // Dead Nonce List insert if necessary (for out-record of inFace)
     this->insertDeadNonceList(*pitEntry, true, data.getFreshnessPeriod(), &inFace);
 
     // mark PIT satisfied
-    pitEntry->deleteInRecords();
+    pitEntry->clearInRecords();
     pitEntry->deleteOutRecord(inFace);
 
     // set PIT straggler timer
@@ -511,7 +507,7 @@
   // has out-record?
   pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(inFace);
   // if no out-record found, drop
-  if (outRecord == pitEntry->getOutRecords().end()) {
+  if (outRecord == pitEntry->out_end()) {
     NFD_LOG_DEBUG("onIncomingNack face=" << inFace.getId() <<
                   " nack=" << nack.getInterest().getName() <<
                   "~" << nack.getReason() << " no-out-record");
@@ -552,10 +548,10 @@
   }
 
   // has in-record?
-  pit::InRecordCollection::const_iterator inRecord = pitEntry->getInRecord(outFace);
+  pit::InRecordCollection::iterator inRecord = pitEntry->getInRecord(outFace);
 
   // if no in-record found, drop
-  if (inRecord == pitEntry->getInRecords().end()) {
+  if (inRecord == pitEntry->in_end()) {
     NFD_LOG_DEBUG("onOutgoingNack face=" << outFace.getId() <<
                   " nack=" << pitEntry->getInterest().getName() <<
                   "~" << nack.getReason() << " no-in-record");
@@ -595,15 +591,13 @@
 void
 Forwarder::setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry)
 {
-  const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
-  pit::InRecordCollection::const_iterator lastExpiring =
-    std::max_element(inRecords.begin(), inRecords.end(),
-    &compare_InRecord_expiry);
+  pit::InRecordCollection::iterator lastExpiring =
+    std::max_element(pitEntry->in_begin(), pitEntry->in_end(), &compare_InRecord_expiry);
 
   time::steady_clock::TimePoint lastExpiry = lastExpiring->getExpiry();
-  time::nanoseconds lastExpiryFromNow = lastExpiry  - time::steady_clock::now();
-  if (lastExpiryFromNow <= time::seconds(0)) {
-    // TODO all InRecords are already expired; will this happen?
+  time::nanoseconds lastExpiryFromNow = lastExpiry - time::steady_clock::now();
+  if (lastExpiryFromNow <= time::seconds::zero()) {
+    // TODO all in-records are already expired; will this happen?
   }
 
   scheduler::cancel(pitEntry->m_unsatisfyTimer);
@@ -666,7 +660,7 @@
   }
   else {
     // insert outgoing Nonce of a specific face
-    pit::OutRecordCollection::const_iterator outRecord = pitEntry.getOutRecord(*upstream);
+    pit::OutRecordCollection::iterator outRecord = pitEntry.getOutRecord(*upstream);
     if (outRecord != pitEntry.getOutRecords().end()) {
       m_deadNonceList.add(pitEntry.getName(), outRecord->getLastNonce());
     }
diff --git a/daemon/fw/forwarder.hpp b/daemon/fw/forwarder.hpp
index 2bac6b0..bb3935c 100644
--- a/daemon/fw/forwarder.hpp
+++ b/daemon/fw/forwarder.hpp
@@ -206,8 +206,8 @@
   cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
 
   /** \brief insert Nonce to Dead Nonce List if necessary
-   *  \param upstream if null, insert Nonces from all OutRecords;
-   *                  if not null, insert Nonce only on the OutRecord of this face
+   *  \param upstream if null, insert Nonces from all out-records;
+   *                  if not null, insert Nonce only on the out-records of this face
    */
   VIRTUAL_WITH_TESTS void
   insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
diff --git a/daemon/fw/ncc-strategy.cpp b/daemon/fw/ncc-strategy.cpp
index ef91c6b..c096fe1 100644
--- a/daemon/fw/ncc-strategy.cpp
+++ b/daemon/fw/ncc-strategy.cpp
@@ -192,7 +192,7 @@
 NccStrategy::beforeSatisfyInterest(shared_ptr<pit::Entry> pitEntry,
                                    const Face& inFace, const Data& data)
 {
-  if (pitEntry->getInRecords().empty()) {
+  if (!pitEntry->hasInRecords()) {
     // PIT entry has already been satisfied (and is now waiting for straggler timer to expire)
     // NCC does not collect measurements for non-best face
     return;
diff --git a/daemon/fw/pit-algorithm.cpp b/daemon/fw/pit-algorithm.cpp
index ac04e2a..ca54dfe 100644
--- a/daemon/fw/pit-algorithm.cpp
+++ b/daemon/fw/pit-algorithm.cpp
@@ -48,7 +48,7 @@
 
   if (scope_prefix::LOCALHOP.isPrefixOf(pitEntry.getName())) {
     // face is non-local, violates localhop scope unless PIT entry has local in-record
-    return std::none_of(pitEntry.getInRecords().begin(), pitEntry.getInRecords().end(),
+    return std::none_of(pitEntry.in_begin(), pitEntry.in_end(),
       [] (const pit::InRecord& inRecord) { return inRecord.getFace()->getScope() == ndn::nfd::FACE_SCOPE_LOCAL; });
   }
 
@@ -61,7 +61,7 @@
 {
   time::steady_clock::TimePoint now = time::steady_clock::now();
 
-  bool hasUnexpiredOutRecord = std::any_of(pitEntry.getOutRecords().begin(), pitEntry.getOutRecords().end(),
+  bool hasUnexpiredOutRecord = std::any_of(pitEntry.out_begin(), pitEntry.out_end(),
     [&face, &now] (const pit::OutRecord& outRecord) {
       return outRecord.getFace().get() == &face && outRecord.getExpiry() >= now;
     });
@@ -69,7 +69,7 @@
     return false;
   }
 
-  bool hasUnexpiredOtherInRecord = std::any_of(pitEntry.getInRecords().begin(), pitEntry.getInRecords().end(),
+  bool hasUnexpiredOtherInRecord = std::any_of(pitEntry.in_begin(), pitEntry.in_end(),
     [&face, &now] (const pit::InRecord& inRecord) {
       return inRecord.getFace().get() != &face && inRecord.getExpiry() >= now;
     });
@@ -114,7 +114,7 @@
 hasPendingOutRecords(const pit::Entry& pitEntry)
 {
   time::steady_clock::TimePoint now = time::steady_clock::now();
-  return std::any_of(pitEntry.getOutRecords().begin(), pitEntry.getOutRecords().end(),
+  return std::any_of(pitEntry.out_begin(), pitEntry.out_end(),
     [&now] (const pit::OutRecord& outRecord) { return outRecord.getExpiry() >= now; });
 }
 
diff --git a/daemon/fw/retx-suppression.cpp b/daemon/fw/retx-suppression.cpp
index a420581..9ae122a 100644
--- a/daemon/fw/retx-suppression.cpp
+++ b/daemon/fw/retx-suppression.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Regents of the University of California,
+ * Copyright (c) 2014-2016,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -31,13 +31,12 @@
 time::steady_clock::TimePoint
 RetxSuppression::getLastOutgoing(const pit::Entry& pitEntry) const
 {
-  const pit::OutRecordCollection& outRecords = pitEntry.getOutRecords();
   pit::OutRecordCollection::const_iterator lastOutgoing = std::max_element(
-      outRecords.begin(), outRecords.end(),
-      [] (const pit::OutRecord& a, const pit::OutRecord& b) {
-        return a.getLastRenewed() < b.getLastRenewed();
-      });
-  BOOST_ASSERT(lastOutgoing != outRecords.end()); // otherwise it's new PIT entry
+    pitEntry.out_begin(), pitEntry.out_end(),
+    [] (const pit::OutRecord& a, const pit::OutRecord& b) {
+      return a.getLastRenewed() < b.getLastRenewed();
+    });
+  BOOST_ASSERT(lastOutgoing != pitEntry.out_end()); // otherwise it's new PIT entry
 
   return lastOutgoing->getLastRenewed();
 }
diff --git a/daemon/fw/strategy.cpp b/daemon/fw/strategy.cpp
index 00fe82f..e0dca89 100644
--- a/daemon/fw/strategy.cpp
+++ b/daemon/fw/strategy.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Regents of the University of California,
+ * Copyright (c) 2014-2016,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -74,8 +74,7 @@
 {
   // populate downstreams with all downstreams faces
   std::unordered_set<const Face*> downstreams;
-  const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
-  std::transform(inRecords.begin(), inRecords.end(), std::inserter(downstreams, downstreams.end()),
+  std::transform(pitEntry->in_begin(), pitEntry->in_end(), std::inserter(downstreams, downstreams.end()),
                  [] (const pit::InRecord& inR) { return inR.getFace().get(); });
 
   // delete excluded faces
@@ -88,7 +87,7 @@
   for (const Face* downstream : downstreams) {
     this->sendNack(pitEntry, *downstream, header);
   }
-  // warning: don't loop on pitEntry->getInRecords(), because InRecord is erased when sending Nack
+  // warning: don't loop on pitEntry->getInRecords(), because in-record is deleted when sending Nack
 }
 
 } // namespace fw