author | Craig Dowell <craigdo@ee.washington.edu> |
Wed, 18 Jul 2007 14:35:06 -0700 | |
changeset 1099 | 1e97c5a86b24 |
parent 1085 | c12d61407468 |
child 1100 | 4aeb2eaa21a7 |
permissions | -rw-r--r-- |
1074 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* This program is free software; you can redistribute it and/or modify |
|
4 |
* it under the terms of the GNU General Public License version 2 as |
|
5 |
* published by the Free Software Foundation; |
|
6 |
* |
|
7 |
* This program is distributed in the hope that it will be useful, |
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 |
* GNU General Public License for more details. |
|
11 |
* |
|
12 |
* You should have received a copy of the GNU General Public License |
|
13 |
* along with this program; if not, write to the Free Software |
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
15 |
*/ |
|
16 |
||
17 |
#include "ns3/debug.h" |
|
18 |
#include "ns3/assert.h" |
|
19 |
#include "candidate-queue.h" |
|
20 |
||
21 |
NS_DEBUG_COMPONENT_DEFINE ("CandidateQueue"); |
|
22 |
||
23 |
namespace ns3 { |
|
24 |
||
25 |
CandidateQueue::CandidateQueue() |
|
26 |
: m_candidates () |
|
27 |
{ |
|
28 |
NS_DEBUG("CandidateQueue::CandidateQueue ()"); |
|
29 |
} |
|
30 |
||
31 |
CandidateQueue::~CandidateQueue() |
|
32 |
{ |
|
33 |
NS_DEBUG("CandidateQueue::~CandidateQueue ()"); |
|
34 |
Clear (); |
|
35 |
} |
|
36 |
||
37 |
void |
|
38 |
CandidateQueue::Clear (void) |
|
39 |
{ |
|
40 |
NS_DEBUG("CandidateQueue::Clear ()"); |
|
41 |
||
42 |
while (!m_candidates.empty ()) |
|
43 |
{ |
|
1085
c12d61407468
delete vertices, fix candidate queue pop/top semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
1081
diff
changeset
|
44 |
SPFVertex *p = Pop (); |
c12d61407468
delete vertices, fix candidate queue pop/top semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
1081
diff
changeset
|
45 |
delete p; |
c12d61407468
delete vertices, fix candidate queue pop/top semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
1081
diff
changeset
|
46 |
p = 0; |
1074 | 47 |
} |
48 |
} |
|
49 |
||
50 |
void |
|
51 |
CandidateQueue::Push (SPFVertex *vNew) |
|
52 |
{ |
|
53 |
NS_DEBUG("CandidateQueue::Push (" << vNew << ")"); |
|
54 |
||
55 |
CandidateList_t::iterator i = m_candidates.begin (); |
|
56 |
||
57 |
for (; i != m_candidates.end (); i++) |
|
58 |
{ |
|
59 |
SPFVertex *v = *i; |
|
60 |
if (vNew->m_distanceFromRoot < v->m_distanceFromRoot) |
|
61 |
{ |
|
62 |
break; |
|
63 |
} |
|
64 |
} |
|
65 |
m_candidates.insert(i, vNew); |
|
66 |
} |
|
67 |
||
1085
c12d61407468
delete vertices, fix candidate queue pop/top semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
1081
diff
changeset
|
68 |
SPFVertex * |
1074 | 69 |
CandidateQueue::Pop (void) |
70 |
{ |
|
71 |
NS_DEBUG("CandidateQueue::Pop ()"); |
|
72 |
||
73 |
if (m_candidates.empty ()) |
|
74 |
{ |
|
1085
c12d61407468
delete vertices, fix candidate queue pop/top semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
1081
diff
changeset
|
75 |
return 0; |
1074 | 76 |
} |
77 |
||
78 |
SPFVertex *v = m_candidates.front (); |
|
79 |
m_candidates.pop_front (); |
|
1085
c12d61407468
delete vertices, fix candidate queue pop/top semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
1081
diff
changeset
|
80 |
return v; |
1074 | 81 |
} |
82 |
||
83 |
SPFVertex * |
|
1099
1e97c5a86b24
General cleanup -- const correctness, encapsulation, documentation, etc.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1085
diff
changeset
|
84 |
CandidateQueue::Top (void) const |
1074 | 85 |
{ |
86 |
NS_DEBUG("CandidateQueue::Top ()"); |
|
87 |
||
88 |
if (m_candidates.empty ()) |
|
89 |
{ |
|
90 |
return 0; |
|
91 |
} |
|
92 |
||
93 |
return m_candidates.front (); |
|
94 |
} |
|
95 |
||
96 |
bool |
|
1099
1e97c5a86b24
General cleanup -- const correctness, encapsulation, documentation, etc.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1085
diff
changeset
|
97 |
CandidateQueue::Empty (void) const |
1074 | 98 |
{ |
99 |
NS_DEBUG("CandidateQueue::Empty ()"); |
|
100 |
||
101 |
return m_candidates.empty (); |
|
102 |
} |
|
103 |
||
104 |
uint32_t |
|
1099
1e97c5a86b24
General cleanup -- const correctness, encapsulation, documentation, etc.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1085
diff
changeset
|
105 |
CandidateQueue::Size (void) const |
1074 | 106 |
{ |
107 |
NS_DEBUG("CandidateQueue::Size ()"); |
|
108 |
||
109 |
return m_candidates.size (); |
|
110 |
} |
|
111 |
||
112 |
SPFVertex * |
|
1099
1e97c5a86b24
General cleanup -- const correctness, encapsulation, documentation, etc.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1085
diff
changeset
|
113 |
CandidateQueue::Find (const Ipv4Address addr) const |
1074 | 114 |
{ |
1075
a19e28d63e3b
Adjust candidate queue implementation: rename Fetch to Find, and make Find based on m_vertexId
Tom Henderson <tomh@tomh.org>
parents:
1074
diff
changeset
|
115 |
NS_DEBUG("CandidateQueue::Find ()"); |
1074 | 116 |
|
1099
1e97c5a86b24
General cleanup -- const correctness, encapsulation, documentation, etc.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1085
diff
changeset
|
117 |
CandidateList_t::const_iterator i = m_candidates.begin (); |
1074 | 118 |
|
119 |
for (; i != m_candidates.end (); i++) |
|
120 |
{ |
|
121 |
SPFVertex *v = *i; |
|
1075
a19e28d63e3b
Adjust candidate queue implementation: rename Fetch to Find, and make Find based on m_vertexId
Tom Henderson <tomh@tomh.org>
parents:
1074
diff
changeset
|
122 |
if (v->m_vertexId == addr) |
1074 | 123 |
{ |
124 |
return v; |
|
125 |
} |
|
126 |
} |
|
127 |
||
128 |
return 0; |
|
129 |
} |
|
130 |
||
131 |
void |
|
132 |
CandidateQueue::Reorder (void) |
|
133 |
{ |
|
134 |
NS_DEBUG("CandidateQueue::Reorder ()"); |
|
135 |
||
136 |
std::list<SPFVertex*> temp; |
|
137 |
||
138 |
while (!m_candidates.empty ()) { |
|
139 |
SPFVertex *v = m_candidates.front (); |
|
140 |
m_candidates.pop_front (); |
|
141 |
temp.push_back(v); |
|
142 |
} |
|
143 |
||
144 |
while (!temp.empty ()) { |
|
145 |
Push (temp.front ()); |
|
146 |
temp.pop_front (); |
|
147 |
} |
|
148 |
} |
|
149 |
||
150 |
} // namespace ns3 |