Draft PitQueue implementation using virtual time concept (good thing, but most likely not be used, at least initially)
diff --git a/utils/ndn-pit-queue.cc b/utils/ndn-pit-queue.cc
new file mode 100644
index 0000000..c051be8
--- /dev/null
+++ b/utils/ndn-pit-queue.cc
@@ -0,0 +1,160 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ndn-pit-queue.h"
+
+#include "ns3/ndn-face.h"
+#include "ns3/ndn-pit-entry.h"
+
+#include "ns3/assert.h"
+
+using namespace std;
+
+namespace ns3 {
+namespace ndn {
+
+PitQueue::Entry::Entry (Ptr<Face> inFace, Ptr<pit::Entry> pitEntry, double virtualTime)
+  : m_inFace (inFace)
+  , m_pitEntry (pitEntry)
+  , m_virtualTime (virtualTime)
+{
+}
+
+bool
+PitQueue::Entry::operator < (const Entry &otherEntry) const
+{
+  return this->m_virtualTime < otherEntry.m_virtualTime;
+}
+
+
+bool
+PitQueue::Enqueue (Ptr<Face> inFace,
+		   Ptr<pit::Entry> pitEntry)
+{
+  return false;
+}
+
+Ptr<pit::Entry>
+PitQueue::Pop ()
+{
+  if (m_queue.size () == 0)
+    return 0;
+
+  PendingInterestsQueue::iterator topEntryIterator = m_queue.begin ();
+  Entry entry = *topEntryIterator; // copy entry
+  m_queue.erase (topEntryIterator); // remove entry
+
+  DecreasePerFaceCount (entry.m_inFace);
+  
+  if (m_queue.size () == 0)
+    m_lastProcessedVirtualTime = 0;
+  else
+    m_lastProcessedVirtualTime = entry.m_virtualTime;
+
+
+  return entry.m_pitEntry;
+}
+
+void
+PitQueue::DecreasePerFaceCount (Ptr<Face> inFace)
+{
+  PerInFaceMapOfNumberOfIncomingInterests::iterator numberOfEnqueued = m_numberEnqueuedInterests.find (inFace);
+  NS_ASSERT_MSG (numberOfEnqueued != m_numberEnqueuedInterests.end () &&
+		 numberOfEnqueued->second > 0,
+		 "Logic error");
+  
+  numberOfEnqueued->second --;
+  if (numberOfEnqueued->second == 0)
+    {
+      m_numberEnqueuedInterests.erase (numberOfEnqueued);
+      m_lastVirtualTime.erase (inFace);
+    }
+}
+
+void
+PitQueue::Remove (Ptr<Face> face)
+{
+  m_numberEnqueuedInterests.erase (face);
+  m_lastVirtualTime.erase (face);
+
+  for (PendingInterestsQueue::iterator item = m_queue.begin ();
+       item != m_queue.end ();
+       /* manual iterator advancement */)
+    {
+      if (item->m_inFace == face)
+	{
+	  PendingInterestsQueue::iterator toRemove = item;
+	  item ++;
+	  m_queue.erase (toRemove); // hopefully a safe operation
+	}
+      else
+	item ++;
+    }
+}
+
+void
+PitQueue::Remove (Ptr<pit::Entry> entry)
+{
+  for (PendingInterestsQueue::iterator item = m_queue.begin ();
+       item != m_queue.end ();
+       /* manual iterator advancement */)
+    {
+      // compare addresses
+      if (&(*entry) == &(**item))
+	{
+	  PendingInterestsQueue::iterator toRemove = item;
+	  item ++;
+
+	  DecreasePerFaceCount (toRemove->m_inFace);
+	  UpdateLastVirtTime (toRemove->m_inFace);
+	  
+	  m_queue.erase (toRemove); // hopefully a safe operation
+	  break; // there should be at most one item for one pit entry
+	}
+      else
+	item ++;
+    }  
+}
+
+void
+PitQueue::UpdateLastVirtTime (Ptr<Face> inFace)
+{
+  PerInFaceMapOfNumberOfIncomingInterests::iterator numberOfEnqueued = m_numberEnqueuedInterests.find (inFace);
+  if (numberOfEnqueued->second == 0)
+    return;
+
+  double lastTime = 0;
+  for (PendingInterestsQueue::iterator item = m_queue.begin ();
+       item != m_queue.end ();
+       item ++)
+    {
+      if (inFace == item->m_inFace)
+	{
+	  if (lastTime < item->m_virtualTime)
+	    lastTime = item->m_virtualTime;
+	}
+    }
+
+  m_lastVirtualTime [inFace] = lastTime; 
+}
+
+
+} // namespace ndn
+} // namespace ns3
diff --git a/utils/ndn-pit-queue.h b/utils/ndn-pit-queue.h
new file mode 100644
index 0000000..e986852
--- /dev/null
+++ b/utils/ndn-pit-queue.h
@@ -0,0 +1,89 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef NDN_PIT_QUEUE_H
+#define NDN_PIT_QUEUE_H
+
+#include <map>
+#include <set>
+
+#include "ns3/ptr.h"
+
+namespace ns3 {
+namespace ndn {
+
+class Face;
+namespace pit { class Entry; }
+
+class PitQueue
+{
+public:
+  bool
+  Enqueue (Ptr<Face> inFace,
+           Ptr<pit::Entry> pitEntry);
+
+  Ptr<pit::Entry>
+  Pop ();
+
+  // cleanup procedures
+  void
+  Remove (Ptr<Face> face);
+
+  void
+  Remove (Ptr<pit::Entry> entry);
+
+private:
+  void
+  DecreasePerFaceCount (Ptr<Face> inFace);
+
+  void
+  UpdateLastVirtTime (Ptr<Face> inFace);
+  
+private:
+  // all maps here consider incoming face (the whole Queue structure is per outgoing face)
+  
+  double m_lastProcessedVirtualTime;
+
+  typedef std::map< Ptr<Face>, uint32_t > PerInFaceMapOfNumberOfIncomingInterests;
+  PerInFaceMapOfNumberOfIncomingInterests m_numberEnqueuedInterests;
+
+  typedef std::map< Ptr<Face>, double > PerInFaceMapOfLastVirtualTimes;
+  PerInFaceMapOfLastVirtualTimes m_lastVirtualTime;
+
+  struct Entry
+  {
+    Entry (Ptr<Face> inFace, Ptr<pit::Entry> pitEntry, double virtualTime);
+
+    bool
+    operator < (const Entry &otherEntry) const;
+
+    Ptr<Face> m_inFace;
+    Ptr<pit::Entry> m_pitEntry;
+    double m_virtualTime;
+  };
+
+  typedef std::multiset< Entry > PendingInterestsQueue;
+  PendingInterestsQueue m_queue;
+};
+
+} // namespace ndn
+} // namespace ns3
+
+#endif // NDN_PIT_QUEUE_H