1 #ifndef NETLIST_UTILS_H 2 #define NETLIST_UTILS_H 4 #include "vtr_vector_map.h" 20 for (T val : values) {
30 template<
typename Container>
32 for (
auto val : values) {
42 vtr::vector_map<Id, Id>
compress_ids(
const vtr::vector_map<Id, Id>& ids) {
43 vtr::vector_map<Id, Id> id_map(ids.size());
48 id_map.insert(
id, Id(i));
66 template<
typename Id,
typename T>
68 VTR_ASSERT(values.size() == id_map.size());
71 vtr::vector_map<Id, T> result;
74 for (
size_t cur_idx = 0; cur_idx < values.size(); ++cur_idx) {
75 Id old_id = Id(cur_idx);
77 Id new_id = id_map[old_id];
80 result.insert(new_id, std::move(values[old_id]));
97 vtr::vector_map<Id, Id> result;
100 for (
size_t cur_idx = 0; cur_idx < id_map.size(); ++cur_idx) {
101 Id old_id = Id(cur_idx);
103 Id new_id = id_map[old_id];
105 result.insert(new_id, new_id);
116 template<
typename R,
typename Id>
118 size_t valid_count = 0;
120 for (Id old_id : range) {
121 if (id_map[old_id]) {
133 template<
typename Container,
typename ValId>
134 Container
update_all_refs(
const Container& values,
const vtr::vector_map<ValId, ValId>& id_map) {
137 for (ValId orig_val : values) {
139 ValId new_val = id_map[orig_val];
141 updated.emplace_back(new_val);
147 template<
typename Container,
typename ValId>
149 const vtr::vector_map<ValId, ValId>& id_map,
150 const std::set<size_t>& preserved_indices = {}) {
154 for (ValId orig_val : values) {
155 if (preserved_indices.count(idx)) {
158 updated.emplace_back(orig_val);
160 ValId new_val = id_map[orig_val];
163 updated.emplace_back(new_val);
166 }
else if (orig_val) {
169 ValId new_val = id_map[orig_val];
172 updated.emplace_back(new_val);
vtr::vector_map< Id, Id > compress_ids(const vtr::vector_map< Id, Id > &ids)
Builds a mapping from old to new ids by skipping values marked invalid.
Definition: netlist_utils.h:42
size_t count_valid_refs(R range, const vtr::vector_map< Id, Id > &id_map)
Count how many of the Id's referenced in 'range' have a valid new mapping in 'id_map'.
Definition: netlist_utils.h:117
bool all_valid(const Container &values)
Returns true if all elements in the vector 'values' evaluate true.
Definition: netlist_utils.h:31
bool are_contiguous(vtr::vector_map< T, T > &values)
Returns true if all elements are contiguously ascending values (i.e. equal to their index) ...
Definition: netlist_utils.h:18
Container update_valid_refs(const Container &values, const vtr::vector_map< ValId, ValId > &id_map, const std::set< size_t > &preserved_indices={})
Definition: netlist_utils.h:148
Container update_all_refs(const Container &values, const vtr::vector_map< ValId, ValId > &id_map)
Updates the Ids in 'values' based on id_map, even if the original or new mapping is not valid...
Definition: netlist_utils.h:134
vtr::vector_map< Id, Id > clean_and_reorder_ids(const vtr::vector_map< Id, Id > &id_map)
Returns the set of new valid Ids defined by 'id_map'.
Definition: netlist_utils.h:93
vtr::vector_map< Id, T > clean_and_reorder_values(const vtr::vector_map< Id, T > &values, const vtr::vector_map< Id, Id > &id_map)
Returns a vector based on 'values', which has had entries dropped & re-ordered according according to 'id...
Definition: netlist_utils.h:67