PandA-2024.02
rehashed_heap.hpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
47 #ifndef REHASHED_HEAP_HPP
48 #define REHASHED_HEAP_HPP
49 
50 #include <algorithm>
51 #include <queue>
52 #include <vector>
53 
54 #include "custom_map.hpp"
55 #include "graph.hpp"
56 #include "priority.hpp"
57 #include "refcount.hpp"
58 
63 
64 
68 template <class _Type>
69 struct rehashed_heap : public std::priority_queue<vertex, std::vector<vertex>, priority_compare_functor<_Type>>
70 {
76  : std::priority_queue<vertex, std::vector<vertex>, priority_compare_functor<_Type>>(_comp)
77  {
78  }
82  void rehash()
83  {
84  std::make_heap(std::priority_queue<vertex, std::vector<vertex>, priority_compare_functor<_Type>>::c.begin(),
85  std::priority_queue<vertex, std::vector<vertex>, priority_compare_functor<_Type>>::c.end(),
86  std::priority_queue<vertex, std::vector<vertex>, priority_compare_functor<_Type>>::comp);
87  }
88 
89  std::vector<vertex>::const_iterator begin()
90  {
91  return rehashed_heap::c.begin();
92  }
93  std::vector<vertex>::const_iterator end()
94  {
95  return rehashed_heap::c.end();
96  }
97 };
98 
102 template <class _Type>
103 struct tree_rehashed_heap : public CustomUnorderedMap<vertex, std::vector<rehashed_heap<_Type>>>
104 {
113  typename std::vector<rehashed_heap<_Type>>::iterator
115  const priority_data<_Type>& priority_functor, vertex& controlling_vertex, unsigned int& b_tag, bool& found)
116  {
117  found = false;
118  typename std::vector<rehashed_heap<_Type>>::iterator res;
119  typename tree_rehashed_heap::const_iterator it_end = this->end();
120  for(typename tree_rehashed_heap::iterator it = this->begin(); it != it_end; ++it)
121  {
122  typename std::vector<rehashed_heap<_Type>>::const_iterator vit_end = it->second.end();
123  unsigned int i = 0;
124  bool cv_not_in_bl = curren_black_list.find(it->first) == curren_black_list.end();
125  for(typename std::vector<rehashed_heap<_Type>>::iterator vit = it->second.begin(); vit != vit_end; ++vit, ++i)
126  {
127  if(!vit->empty() && (cv_not_in_bl || curren_black_list.find(it->first)->second.find(i) ==
128  curren_black_list.find(it->first)->second.end()))
129  {
130  if(!found)
131  {
132  found = true;
133  res = vit;
134  controlling_vertex = it->first;
135  b_tag = i;
136  }
137  else if(priority_functor(vit->top()) > priority_functor(res->top()))
138  {
139  res = vit;
140  controlling_vertex = it->first;
141  b_tag = i;
142  }
143  }
144  }
145  }
146  return res;
147  }
148 
152  void rehash()
153  {
154  typename tree_rehashed_heap::iterator it_end = this->end();
155  for(typename tree_rehashed_heap::iterator it = this->begin(); it != it_end; ++it)
156  {
157  typename std::vector<rehashed_heap<_Type>>::iterator vit_end = it->second.end();
158  for(typename std::vector<rehashed_heap<_Type>>::iterator vit = it->second.begin(); vit != vit_end; ++vit)
159  {
160  vit->rehash();
161  }
162  }
163  }
164 };
165 
166 #endif
rehashed_heap(const priority_compare_functor< _Type > &_comp)
Constructor.
Base class used to define the priority associated with each vertex of a list base scheduling problem...
Definition: priority.hpp:69
Class specification of the graph structures.
Definition of hash function for EdgeDescriptor.
Definition: graph.hpp:1321
void rehash()
Rehash the heap associated with the priority queue.
redefinition of map to manage ordered/unordered structures
std::vector< vertex >::const_iterator end()
This package is used to drive the list based algorithm with different type of priority schemes...
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
Definition: custom_map.hpp:148
Class used to represent a tree of priority queues.
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
Class used to represent a priority queue of vertex with rehash.
Functor used to compare two vertices with respect to a priority object.
Definition: priority.hpp:170
Template definition of refcount.
void rehash()
Rehash all the heaps in the map.
std::vector< rehashed_heap< _Type > >::iterator top(const CustomUnorderedMap< vertex, CustomOrderedSet< unsigned int >> &curren_black_list, const priority_data< _Type > &priority_functor, vertex &controlling_vertex, unsigned int &b_tag, bool &found)
Return the vertex with the highest priority.
std::vector< vertex >::const_iterator begin()

Generated on Mon Feb 12 2024 13:02:54 for PandA-2024.02 by doxygen 1.8.13