OverSim
GiaNeighborCandidateList.cc
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
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 
24 #include <iterator>
25 #include <assert.h>
26 
27 #include <omnetpp.h>
28 
30 
31 
33 {
34  return candidates.size();
35 }
36 
38 {
39  assert(!(node.isUnspecified()));
40  candidates.insert( node );
41 }
42 
43 void GiaNeighborCandidateList::remove(uint32_t position)
44 {
45  std::set<NodeHandle>::iterator it = candidates.begin();
46  for (uint32_t i=0; i<position; i++) {
47  it++;
48  }
49  candidates.erase( it );
50 }
51 
53 {
54  candidates.erase(node);
55 }
56 
58 {
59  if(node.getKey().isUnspecified())
60  return false;
61 
62  std::set<NodeHandle>::iterator it = candidates.find(node);
63 
64  if(it != candidates.end() && it->getKey() == node.getKey())
65  return true;
66  else
67  return false;
68 }
69 
70 //bad code
71 const NodeHandle& GiaNeighborCandidateList::get( uint32_t position )
72 {
73  if ( position >= candidates.size() )
75  else {
76  std::set<NodeHandle>::iterator it = candidates.begin();
77  for (uint32_t i=0; i<position; i++) {
78  it++;
79  }
80  return *it;
81  }
82 }
83 
85 {
86  return get(intuniform(0, getSize()));
87 }
88 
89 // int GiaNeighborCandidateList::getPosition( NodeHandle node )
90 // {
91 // if ( !contains(node) )
92 // return -1;
93 // else
94 // {
95 // uint i = 0;
96 // std::set<NodeHandle>::iterator theIterator;
97 // for( theIterator = candidates.begin(); theIterator != candidates.end(); theIterator++ )
98 // {
99 // if ( theIterator->key == node.getKey() )
100 // return i++;
101 // }
102 // }
103 // return -1;
104 // }
105 
107 {
108  candidates.clear();
109 }