29 #ifndef CMAPPEDMULTILEVELLIST_HPP_
30 #define CMAPPEDMULTILEVELLIST_HPP_
32 #include <sutil/CMappedList.hpp>
47 template <
typename Idx,
typename T>
60 virtual T*
create(
const Idx& arg_idx,
const T &arg_node2add,
61 const std::size_t arg_priority);
65 virtual T*
create(
const Idx& arg_idx,
const std::size_t arg_priority);
69 virtual T*
insert(
const Idx& arg_idx, T *arg_node2add,
70 const std::size_t arg_priority);
83 virtual bool erase(T* arg_t);
87 virtual bool erase(
const Idx& arg_idx);
95 std::size_t getNumPriorityLevels()
const
151 template <
typename Idx,
typename T>
160 template <
typename Idx,
typename T>
162 { mlvec_.clear(); map_nodeptr2pri_.clear(); pri_levels_=0; }
166 template <
typename Idx,
typename T>
168 const Idx& arg_idx,
const T & arg_node2add,
169 const std::size_t arg_priority)
176 for(std::size_t i=mlvec_.size(); i <= arg_priority; i++)
179 mlvec_.push_back(tmp);
182 mlvec_[arg_priority].push_back(tLnk);
183 map_nodeptr2pri_.insert(std::pair<T*,std::size_t>(tLnk,arg_priority));
188 template <
typename Idx,
typename T>
190 const Idx& arg_idx,
const std::size_t arg_priority)
197 for(std::size_t i=mlvec_.size(); i <= arg_priority; i++)
200 mlvec_.push_back(tmp);
203 mlvec_[arg_priority].push_back(tLnk);
204 map_nodeptr2pri_.insert(std::pair<T*,std::size_t>(tLnk,arg_priority));
212 template <
typename Idx,
typename T>
214 const Idx& arg_idx, T *arg_node2add,
215 const std::size_t arg_priority)
222 for(std::size_t i=mlvec_.size(); i <= arg_priority; i++)
225 mlvec_.push_back(tmp);
228 mlvec_[arg_priority].push_back(tLnk);
229 map_nodeptr2pri_.insert(std::pair<T*,std::size_t>(tLnk,arg_priority));
235 template <
typename Idx,
typename T>
242 if(0 == arg_br->
size())
247 mlvec_.
clear(); map_nodeptr2pri_.clear();
253 for(it = arg_br->CMappedList<Idx,T>::begin(), ite = arg_br->CMappedList<Idx,T>::end();
260 std::cerr<<
"\nCMultiLevelPileMap<Idx,T>::deepCopy() Error :Deep copy failed. Resetting multi-level mapped list.";
262 clear();
return false;
266 const T* tmpptr = &(*it);
271 std::cerr<<
"\nCMultiLevelPileMap<Idx,T>::deepCopy() Error :Did not find a node in the priority map.";
273 clear();
return false;
277 map_nodeptr2pri_.insert(std::pair<T*,std::size_t>(tmp,pri));
280 for(std::size_t i=mlvec_.size(); i <= pri; i++)
283 mlvec_.push_back(tmp);
286 mlvec_[pri].push_back(tmp);
292 template <
typename Idx,
typename T>
300 if(map_nodeptr2pri_.find(arg_t) ==
301 map_nodeptr2pri_.end())
304 std::size_t pri = map_nodeptr2pri_[arg_t];
307 typename std::vector<T*>::iterator it,ite;
308 for(it = mlvec_[pri].begin(),ite = mlvec_[pri].end();
312 { mlvec_[pri].erase(it);
break; }
315 if(pri == pri_levels_ -1)
317 if(mlvec_[pri].size()==0)
319 typename std::vector<std::vector<T*> >::reverse_iterator itr,itre;
320 for(itr = mlvec_.rbegin(),itre = mlvec_.rend();
323 if((*itr).size() == 0)
328 { mlvec_.erase((itr+1).base()); }
336 map_nodeptr2pri_.erase(arg_t);
343 pri_levels_ = mlvec_.size();
347 template <
typename Idx,
typename T>
359 if(map_nodeptr2pri_.find(t_ptr) ==
360 map_nodeptr2pri_.end())
363 std::size_t pri = map_nodeptr2pri_[t_ptr];
366 typename std::vector<T*>::iterator it,ite;
367 for(it = mlvec_[pri].begin(),ite = mlvec_[pri].end();
371 { mlvec_[pri].erase(it);
break; }
374 if(pri == pri_levels_ -1)
376 if(mlvec_[pri].size()==0)
378 typename std::vector<std::vector<T*> >::reverse_iterator itr,itre;
379 for(itr = mlvec_.rbegin(),itre = mlvec_.rend();
382 if((*itr).size() == 0)
387 { mlvec_.erase((itr+1).base()); }
395 map_nodeptr2pri_.erase(t_ptr);
402 pri_levels_ = mlvec_.size();
405 template <
typename Idx,
typename T>
410 map_nodeptr2pri_.clear();
415 template <
typename Idx,
typename T>
419 if(arg_pri > mlvec_.size())
423 std::vector<T*>* ret = &(mlvec_.at(arg_pri));
428 template <
typename Idx,
typename T>
433 if(map_nodeptr2pri_.find(arg_t) ==
434 map_nodeptr2pri_.end())
437 { ret =
static_cast<int>(map_nodeptr2pri_[arg_t]); }
442 template <
typename Idx,
typename T>
451 if(map_nodeptr2pri_.find(t_ptr) ==
452 map_nodeptr2pri_.end())
455 { ret =
static_cast<int>(map_nodeptr2pri_[t_ptr]); }
int getPriorityLevel(T *arg_t)
Definition: CMappedMultiLevelList.hpp:430
std::vector< std::vector< T * > > mlvec_
Definition: CMappedMultiLevelList.hpp:115
virtual bool clear()
Definition: CMappedList.hpp:1127
CMappedMultiLevelList()
Definition: CMappedMultiLevelList.hpp:152
Definition: CMappedList.hpp:85
virtual T * create(const Idx &arg_idx, const T &arg_node2add, const std::size_t arg_priority)
Definition: CMappedMultiLevelList.hpp:167
virtual CMappedMultiLevelList< Idx, T > & operator=(const CMappedMultiLevelList< Idx, T > &arg_rhs)
Definition: CMappedMultiLevelList.hpp:75
virtual bool clear()
Definition: CMappedMultiLevelList.hpp:406
virtual bool deepCopy(const CMappedMultiLevelList< Idx, T > *arg_br)
Definition: CMappedMultiLevelList.hpp:237
virtual ~CMappedMultiLevelList()
Definition: CMappedMultiLevelList.hpp:161
std::vector< T * > * getSinglePriorityLevel(std::size_t arg_pri)
Definition: CMappedMultiLevelList.hpp:417
virtual T * at(const std::size_t arg_idx)
Definition: CMappedList.hpp:832
virtual T * insert(const Idx &arg_idx, T *arg_node2add, const std::size_t arg_priority)
Definition: CMappedMultiLevelList.hpp:213
virtual bool erase(T *arg_t)
Definition: CMappedList.hpp:985
Definition: CMappedMultiLevelList.hpp:48
std::map< const T *, std::size_t > map_nodeptr2pri_
Definition: CMappedMultiLevelList.hpp:122
virtual bool erase(T *arg_t)
Definition: CMappedMultiLevelList.hpp:293
virtual T * create(const Idx &arg_idx, const bool insert_at_start=true)
Definition: CMappedList.hpp:714
Definition: CMappedList.hpp:381
virtual std::size_t size() const
Definition: CMappedList.hpp:240
std::size_t pri_levels_
Definition: CMappedMultiLevelList.hpp:125