Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #include "ns3/core-module.h" |
| 22 | #include "ns3/ndnSIM-module.h" |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame^] | 23 | #include "../utils/trie-with-policy.h" |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 24 | |
| 25 | using namespace ns3; |
| 26 | |
| 27 | NS_LOG_COMPONENT_DEFINE ("Trie"); |
| 28 | |
| 29 | class Integer : public ns3::SimpleRefCount<Integer> |
| 30 | { |
| 31 | public: |
| 32 | Integer (int value) : value_ (value) {} |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 33 | |
| 34 | operator int () const { return value_; } |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 35 | private: |
| 36 | int value_; |
| 37 | }; |
| 38 | |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 39 | std::ostream & |
| 40 | operator << (std::ostream &os, const Integer &i) |
| 41 | { |
| 42 | os << (int)i; |
| 43 | return os; |
| 44 | } |
| 45 | |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 46 | int |
| 47 | main (int argc, char *argv[]) |
| 48 | { |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame^] | 49 | typedef trie_with_policy<ns3::CcnxNameComponents, |
| 50 | Integer, |
| 51 | smart_pointer_payload_traits<Integer>, |
| 52 | lru_policy_traits<CcnxNameComponents, |
| 53 | Integer, |
| 54 | smart_pointer_payload_traits<Integer> > |
| 55 | > trie; |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 56 | trie x; |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame^] | 57 | x.getPolicy ().set_max_size (100); |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 58 | |
| 59 | // x.getTrie ().PrintStat (std::cout); |
| 60 | |
| 61 | ns3::CcnxNameComponents n1,n2,n3,n4; |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 62 | n1("a")("b")("c"); |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 63 | n2("a")("b")("d"); |
| 64 | n3("a")("b")("f"); |
| 65 | n4("a")("b"); |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 66 | |
| 67 | ns3::Ptr<Integer> i = ns3::Create<Integer> (1); |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 68 | x.insert (n4, ns3::Create<Integer> (4)); |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 69 | |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 70 | x.insert (n3, ns3::Create<Integer> (3)); |
| 71 | |
| 72 | std::pair< trie::iterator, bool > item = |
| 73 | x.insert (n2, ns3::Create<Integer> (2)); |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame^] | 74 | // x.erase (item.first); |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 75 | |
| 76 | x.insert (n1, ns3::Create<Integer> (1)); |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 77 | x.insert (n4, ns3::Create<Integer> (4)); |
| 78 | |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame^] | 79 | std::cout << "digraph trie {\n"; |
| 80 | std::cout << x.getTrie (); |
| 81 | std::cout << "}\n"; |
| 82 | |
| 83 | // BOOST_FOREACH (const trie::parent_trie &item, x.getPolicy ()) |
| 84 | // { |
| 85 | // std::cout << *item.payload () << " " << std::endl; |
| 86 | // } |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 87 | |
| 88 | // ns3::CcnxNameComponents n4; |
| 89 | // n4("a")("c"); |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 90 | |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 91 | // // std::cout << *x->find (n4).get<0> (); |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 92 | |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 93 | // x->prune (); |
| 94 | // // x->find (n5).get<0> ()->erase (); |
| 95 | // x->find (n1).get<0> ()->erase (); |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 96 | |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 97 | // std::cout << "digraph trie {\n"; |
| 98 | // std::cout << *x; |
| 99 | // std::cout << "}\n"; |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 100 | |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 101 | // x->PrintStat (std::cout); |
| 102 | |
| 103 | // delete x; |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |