@@ -42,35 +42,35 @@ struct SBKeyParts {
4242// Parse the key to extract filename, row, and column
4343static SBKeyParts parse_sb_key (const std::string& key) {
4444 SBKeyParts parts;
45-
45+
4646 // Find the last two underscores
4747 size_t last_underscore = key.rfind (' _' );
4848 size_t second_last_underscore = key.rfind (' _' , last_underscore - 1 );
49-
49+
5050 parts.filename = key.substr (0 , second_last_underscore);
5151 parts.row = std::stoi (key.substr (second_last_underscore + 1 , last_underscore - second_last_underscore - 1 ));
5252 parts.col = std::stoi (key.substr (last_underscore + 1 ));
53-
53+
5454 return parts;
5555}
5656
5757// Read CSV file and keep first NUM_EMPTY_ROWS rows completely and first NUM_EMPTY_COLS columns of all other rows
5858static std::vector<std::vector<std::string>> read_and_trim_csv (const std::string& filepath) {
5959 std::vector<std::vector<std::string>> data;
6060 std::ifstream file (filepath);
61-
61+
6262 if (!file.is_open ()) {
6363 return data;
6464 }
65-
65+
6666 std::string line;
6767 int row_count = 0 ;
6868 while (std::getline (file, line)) {
6969 std::vector<std::string> row;
7070 std::stringstream ss (line);
7171 std::string cell;
7272 int col_count = 0 ;
73-
73+
7474 if (row_count < crrgenerator::NUM_EMPTY_ROWS) {
7575 // Keep entire row for first NUM_EMPTY_ROWS rows
7676 while (std::getline (ss, cell, ' ,' )) {
@@ -83,19 +83,19 @@ static std::vector<std::vector<std::string>> read_and_trim_csv(const std::string
8383 col_count++;
8484 }
8585 }
86-
86+
8787 data.push_back (row);
8888 row_count++;
8989 }
90-
90+
9191 file.close ();
9292 return data;
9393}
9494
9595// Write 2D vector to CSV file
9696static void write_csv (const std::string& filepath, const std::vector<std::vector<std::string>>& data) {
9797 std::ofstream file (filepath);
98-
98+
9999 for (size_t i = 0 ; i < data.size (); ++i) {
100100 for (size_t j = 0 ; j < data[i].size (); ++j) {
101101 file << data[i][j];
@@ -105,7 +105,7 @@ static void write_csv(const std::string& filepath, const std::vector<std::vector
105105 }
106106 file << " \n " ;
107107 }
108-
108+
109109 file.close ();
110110}
111111
@@ -252,22 +252,22 @@ void write_sb_count_stats(const Netlist<>& net_list,
252252 // Write the sb_count to a file
253253 // First, read all CSV files from directory and trim them
254254 std::unordered_map<std::string, std::vector<std::vector<std::string>>> csv_data;
255-
255+
256256 for (const auto & entry : fs::directory_iterator (sb_map_dir)) {
257257 if (entry.is_regular_file () && entry.path ().extension () == " .csv" ) {
258258 std::string filename = entry.path ().filename ().string ();
259259 csv_data[filename] = read_and_trim_csv (entry.path ().string ());
260260 }
261261 }
262-
262+
263263 // Group sb_count entries by filename
264264 std::unordered_map<std::string, std::vector<std::pair<int , std::pair<int , int >>>> file_groups;
265-
265+
266266 for (const auto & [sb_id, count] : sb_count) {
267267 SBKeyParts parts = parse_sb_key (sb_id);
268268 file_groups[parts.filename ].push_back ({parts.row , {parts.col , count}});
269269 }
270-
270+
271271 // Process each file
272272 for (auto & [filename, data] : csv_data) {
273273 // Check if this file has updates from sb_count
@@ -278,35 +278,35 @@ void write_sb_count_stats(const Netlist<>& net_list,
278278 VTR_LOG (" Written trimmed CSV: %s\n " , filename.c_str ());
279279 continue ;
280280 }
281-
281+
282282 const auto & entries = file_groups[filename];
283-
283+
284284 // Find maximum row and column needed
285285 int max_row = 0 , max_col = 0 ;
286286 for (const auto & entry : entries) {
287287 max_row = std::max (max_row, entry.first );
288288 max_col = std::max (max_col, entry.second .first );
289289 }
290-
290+
291291 // Expand data structure if needed
292292 while (data.size () <= static_cast <size_t >(max_row)) {
293293 data.push_back (std::vector<std::string>());
294294 }
295-
295+
296296 for (auto & row : data) {
297297 while (row.size () <= static_cast <size_t >(max_col)) {
298298 row.push_back (" " );
299299 }
300300 }
301-
301+
302302 // Update values from sb_count
303303 for (const auto & entry : entries) {
304304 int row = entry.first ;
305305 int col = entry.second .first ;
306306 int count = entry.second .second ;
307307 data[row][col] = std::to_string (count);
308308 }
309-
309+
310310 // Write updated file
311311 std::string output_path = sb_count_dir + " /" + filename;
312312 write_csv (output_path, data);
0 commit comments