NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
name-tree.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_TABLE_NAME_TREE_HPP
27 #define NFD_DAEMON_TABLE_NAME_TREE_HPP
28 
29 #include "common.hpp"
30 #include "name-tree-entry.hpp"
31 
32 namespace nfd {
33 namespace name_tree {
34 
38 size_t
39 computeHash(const Name& prefix);
40 
45 std::vector<size_t>
46 computeHashSet(const Name& prefix);
47 
49 typedef function<bool (const Entry& entry)> EntrySelector;
50 
56 typedef function<std::pair<bool,bool> (const Entry& entry)> EntrySubTreeSelector;
57 
58 struct AnyEntry {
59  bool
60  operator()(const Entry& entry)
61  {
62  return true;
63  }
64 };
65 
67  std::pair<bool, bool>
68  operator()(const Entry& entry)
69  {
70  return std::make_pair(true, true);
71  }
72 };
73 
74 } // namespace name_tree
75 
79 class NameTree : noncopyable
80 {
81 public:
82  class const_iterator;
83 
84  explicit
85  NameTree(size_t nBuckets = 1024);
86 
87  ~NameTree();
88 
89 public: // information
93  size_t
94  size() const;
95 
101  size_t
102  getNBuckets() const;
103 
107  void
108  dump(std::ostream& output) const;
109 
110 public: // mutation
121  shared_ptr<name_tree::Entry>
122  lookup(const Name& prefix);
123 
132  bool
133  eraseEntryIfEmpty(shared_ptr<name_tree::Entry> entry);
134 
135 public: // shortcut access
140  shared_ptr<name_tree::Entry>
141  get(const fib::Entry& fibEntry) const;
142 
147  shared_ptr<name_tree::Entry>
148  get(const pit::Entry& pitEntry);
149 
154  shared_ptr<name_tree::Entry>
155  get(const measurements::Entry& measurementsEntry) const;
156 
161  shared_ptr<name_tree::Entry>
162  get(const strategy_choice::Entry& strategyChoiceEntry) const;
163 
164 public: // matching
170  shared_ptr<name_tree::Entry>
171  findExactMatch(const Name& prefix) const;
172 
178  shared_ptr<name_tree::Entry>
179  findLongestPrefixMatch(const Name& prefix,
180  const name_tree::EntrySelector& entrySelector =
181  name_tree::AnyEntry()) const;
182 
183  shared_ptr<name_tree::Entry>
184  findLongestPrefixMatch(shared_ptr<name_tree::Entry> entry,
185  const name_tree::EntrySelector& entrySelector =
186  name_tree::AnyEntry()) const;
187 
192  shared_ptr<name_tree::Entry>
193  findLongestPrefixMatch(const pit::Entry& pitEntry) const;
194 
209  boost::iterator_range<const_iterator>
210  findAllMatches(const Name& prefix,
211  const name_tree::EntrySelector& entrySelector = name_tree::AnyEntry()) const;
212 
213 public: // enumeration
228  boost::iterator_range<const_iterator>
229  fullEnumerate(const name_tree::EntrySelector& entrySelector = name_tree::AnyEntry()) const;
230 
245  boost::iterator_range<const_iterator>
246  partialEnumerate(const Name& prefix,
247  const name_tree::EntrySubTreeSelector& entrySubTreeSelector =
249 
255  begin() const;
256 
262  end() const;
263 
267  FIND_ALL_MATCHES_TYPE
268  };
269 
270  class const_iterator : public std::iterator<std::forward_iterator_tag, const name_tree::Entry>
271  {
272  public:
273  friend class NameTree;
274 
275  const_iterator();
276 
278  const NameTree& nameTree,
279  shared_ptr<name_tree::Entry> entry,
280  const name_tree::EntrySelector& entrySelector = name_tree::AnyEntry(),
281  const name_tree::EntrySubTreeSelector& entrySubTreeSelector = name_tree::AnyEntrySubTree());
282 
283  ~const_iterator();
284 
285  const name_tree::Entry&
286  operator*() const;
287 
288  shared_ptr<name_tree::Entry>
289  operator->() const;
290 
292  operator++();
293 
295  operator++(int);
296 
297  bool
298  operator==(const const_iterator& other) const;
299 
300  bool
301  operator!=(const const_iterator& other) const;
302 
303  private:
304  const NameTree* m_nameTree;
305  shared_ptr<name_tree::Entry> m_entry;
306  shared_ptr<name_tree::Entry> m_subTreeRoot;
307  shared_ptr<name_tree::EntrySelector> m_entrySelector;
308  shared_ptr<name_tree::EntrySubTreeSelector> m_entrySubTreeSelector;
309  NameTree::IteratorType m_type;
310  bool m_shouldVisitChildren;
311  };
312 
313 private:
321  void
322  resize(size_t newNBuckets);
323 
324 private:
325  size_t m_nItems; // Number of items being stored
326  size_t m_nBuckets; // Number of hash buckets
327  size_t m_minNBuckets; // Minimum number of hash buckets
328  double m_enlargeLoadFactor;
329  size_t m_enlargeThreshold;
330  int m_enlargeFactor;
331  double m_shrinkLoadFactor;
332  size_t m_shrinkThreshold;
333  double m_shrinkFactor;
334  name_tree::Node** m_buckets; // Name Tree Buckets in the NPHT
335  shared_ptr<name_tree::Entry> m_end;
336  const_iterator m_endIterator;
337 
346  std::pair<shared_ptr<name_tree::Entry>, bool>
347  insert(const Name& prefix);
348 };
349 
351 {
352 }
353 
354 inline size_t
356 {
357  return m_nItems;
358 }
359 
360 inline size_t
362 {
363  return m_nBuckets;
364 }
365 
366 inline shared_ptr<name_tree::Entry>
367 NameTree::get(const fib::Entry& fibEntry) const
368 {
369  return fibEntry.m_nameTreeEntry;
370 }
371 
372 inline shared_ptr<name_tree::Entry>
373 NameTree::get(const measurements::Entry& measurementsEntry) const
374 {
375  return measurementsEntry.m_nameTreeEntry;
376 }
377 
378 inline shared_ptr<name_tree::Entry>
379 NameTree::get(const strategy_choice::Entry& strategyChoiceEntry) const
380 {
381  return strategyChoiceEntry.m_nameTreeEntry;
382 }
383 
386 {
387  return fullEnumerate().begin();
388 }
389 
392 {
393  return m_endIterator;
394 }
395 
396 inline const name_tree::Entry&
398 {
399  return *m_entry;
400 }
401 
402 inline shared_ptr<name_tree::Entry>
404 {
405  return m_entry;
406 }
407 
410 {
411  NameTree::const_iterator temp(*this);
412  ++(*this);
413  return temp;
414 }
415 
416 inline bool
418 {
419  return m_entry == other.m_entry;
420 }
421 
422 inline bool
424 {
425  return m_entry != other.m_entry;
426 }
427 
428 } // namespace nfd
429 
430 #endif // NFD_DAEMON_TABLE_NAME_TREE_HPP
size_t computeHash(const Name &prefix)
Compute the hash value of the given name prefix&#39;s WIRE FORMAT.
Definition: name-tree.cpp:77
Name Tree Node Class.
represents a FIB entry
Definition: fib-entry.hpp:53
shared_ptr< name_tree::Entry > operator->() const
Definition: name-tree.hpp:403
function< std::pair< bool, bool >const Entry &entry)> EntrySubTreeSelector
a predicate to accept or reject an Entry and its children
Definition: name-tree.hpp:56
bool operator==(const const_iterator &other) const
Definition: name-tree.hpp:417
size_t getNBuckets() const
Get the number of buckets in the Name Tree (NPHT)
Definition: name-tree.hpp:361
shared_ptr< name_tree::Entry > get(const fib::Entry &fibEntry) const
get NameTree entry from FIB entry
Definition: name-tree.hpp:367
std::vector< size_t > computeHashSet(const Name &prefix)
Incrementally compute hash values.
Definition: name-tree.cpp:95
size_t size() const
Get the number of occupied entries in the Name Tree.
Definition: name-tree.hpp:355
represents a Measurements entry
Table::const_iterator iterator
Definition: cs-internal.hpp:41
std::pair< bool, bool > operator()(const Entry &entry)
Definition: name-tree.hpp:68
const_iterator begin() const
Get an iterator pointing to the first NameTree entry.
Definition: name-tree.hpp:385
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
represents a PIT entry
Definition: pit-entry.hpp:69
Class Name Tree.
Definition: name-tree.hpp:79
Name abstraction to represent an absolute name.
Definition: name.hpp:46
represents a Strategy Choice entry
const_iterator operator++()
Definition: name-tree.cpp:642
bool operator!=(const GlobalRouter::Incidency &a, const GlobalRouter::Incidency &b)
NameTree
Definition: name-tree.cpp:36
const_iterator end() const
Get an iterator referring to the past-the-end FIB entry.
Definition: name-tree.hpp:391
function< bool(const Entry &entry)> EntrySelector
a predicate to accept or reject an Entry in find operations
Definition: name-tree.hpp:49
const name_tree::Entry & operator*() const
Definition: name-tree.hpp:397
bool operator!=(const const_iterator &other) const
Definition: name-tree.hpp:423
bool operator()(const Entry &entry)
Definition: name-tree.hpp:60
Name Tree Entry Class.
bool operator==(const GlobalRouter::Incidency &a, const GlobalRouter::Incidency &b)