blob: 3e77a4f6ea890090c343e716ff289c649f3d3c86 [file] [log] [blame]
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -07001/* -*- 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 Afanasyev9a989702012-06-29 17:44:00 -070023#include "../utils/trie-with-policy.h"
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070024
25using namespace ns3;
26
27NS_LOG_COMPONENT_DEFINE ("Trie");
28
29class Integer : public ns3::SimpleRefCount<Integer>
30{
31public:
32 Integer (int value) : value_ (value) {}
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070033
34 operator int () const { return value_; }
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070035private:
36 int value_;
37};
38
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070039std::ostream &
40operator << (std::ostream &os, const Integer &i)
41{
42 os << (int)i;
43 return os;
44}
45
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070046int
47main (int argc, char *argv[])
48{
Alexander Afanasyev9a989702012-06-29 17:44:00 -070049 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 Afanasyev89fb5352012-06-12 22:43:16 -070056 trie x;
Alexander Afanasyev9a989702012-06-29 17:44:00 -070057 x.getPolicy ().set_max_size (100);
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070058
59 // x.getTrie ().PrintStat (std::cout);
60
61 ns3::CcnxNameComponents n1,n2,n3,n4;
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070062 n1("a")("b")("c");
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070063 n2("a")("b")("d");
64 n3("a")("b")("f");
65 n4("a")("b");
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070066
67 ns3::Ptr<Integer> i = ns3::Create<Integer> (1);
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070068 x.insert (n4, ns3::Create<Integer> (4));
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070069
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070070 x.insert (n3, ns3::Create<Integer> (3));
71
72 std::pair< trie::iterator, bool > item =
73 x.insert (n2, ns3::Create<Integer> (2));
Alexander Afanasyev9a989702012-06-29 17:44:00 -070074 // x.erase (item.first);
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070075
76 x.insert (n1, ns3::Create<Integer> (1));
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070077 x.insert (n4, ns3::Create<Integer> (4));
78
Alexander Afanasyev9a989702012-06-29 17:44:00 -070079 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 Afanasyev89fb5352012-06-12 22:43:16 -070087
88 // ns3::CcnxNameComponents n4;
89 // n4("a")("c");
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070090
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070091 // // std::cout << *x->find (n4).get<0> ();
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070092
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070093 // x->prune ();
94 // // x->find (n5).get<0> ()->erase ();
95 // x->find (n1).get<0> ()->erase ();
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070096
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070097 // std::cout << "digraph trie {\n";
98 // std::cout << *x;
99 // std::cout << "}\n";
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700100
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700101 // x->PrintStat (std::cout);
102
103 // delete x;
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700104
105 return 0;
106}
107