blob: 36e52acc6f76580c7153f235408883ae4cfaf25b [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"
23#include "../utils/trie.h"
24
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 Afanasyev89fb5352012-06-12 22:43:16 -070049 typedef indexed_trie<ns3::CcnxNameComponents, Integer, smart_pointer_payload_traits<Integer> > trie;
50 trie x;
51 x.getPolicy ().set_max_size (2);
52
53 // x.getTrie ().PrintStat (std::cout);
54
55 ns3::CcnxNameComponents n1,n2,n3,n4;
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070056 n1("a")("b")("c");
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070057 n2("a")("b")("d");
58 n3("a")("b")("f");
59 n4("a")("b");
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070060
61 ns3::Ptr<Integer> i = ns3::Create<Integer> (1);
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070062 x.insert (n4, ns3::Create<Integer> (4));
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070063
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070064
65
66 x.insert (n3, ns3::Create<Integer> (3));
67
68 std::pair< trie::iterator, bool > item =
69 x.insert (n2, ns3::Create<Integer> (2));
70 x.erase (item.first);
71
72 x.insert (n1, ns3::Create<Integer> (1));
73 x.find (n1);
74 x.insert (n4, ns3::Create<Integer> (4));
75
76 // std::cout << x.getTrie ();
77 BOOST_FOREACH (const trie::parent_trie &item, x.getPolicy ())
78 {
79 std::cout << *item.payload () << " " << std::endl;
80 }
81
82 // ns3::CcnxNameComponents n4;
83 // n4("a")("c");
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070084
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070085 // // std::cout << *x->find (n4).get<0> ();
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070086
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070087 // x->prune ();
88 // // x->find (n5).get<0> ()->erase ();
89 // x->find (n1).get<0> ()->erase ();
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070090
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070091 // std::cout << "digraph trie {\n";
92 // std::cout << *x;
93 // std::cout << "}\n";
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070094
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070095 // x->PrintStat (std::cout);
96
97 // delete x;
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070098
99 return 0;
100}
101