* Returns {Number of Cols, Some kind of Variance} of the data in localStorage * Variance: number of rows that are shorter than the longest row * * @return std::pair (Number of Columns, Number of rows that are shorter than longest row) */
| 963 | * @return std::pair (Number of Columns, Number of rows that are shorter than longest row) |
| 964 | */ |
| 965 | std::pair<table_index_t, table_index_t> CsvApplication::tableStatistics(CsvDataStorage localStorage) { |
| 966 | table_index_t maxCols = 0; |
| 967 | table_index_t shorterRows = 0; |
| 968 | |
| 969 | // table is empty |
| 970 | if( localStorage.rows() == 0 ) { |
| 971 | return {0, 0}; |
| 972 | } |
| 973 | // table has just one row |
| 974 | if( localStorage.rows() == 1) { |
| 975 | return { static_cast<table_index_t>(localStorage.rawRow(0).size()), 0 }; |
| 976 | } |
| 977 | // get maximum columns |
| 978 | for( table_index_t r = 1; r < localStorage.rows(); ++r ) { |
| 979 | if( (table_index_t) localStorage.rawRow(r).size() > maxCols ) { |
| 980 | maxCols = localStorage.rawRow(r).size(); |
| 981 | } |
| 982 | } |
| 983 | // count number of shorter rows |
| 984 | for( table_index_t r = 1; r < localStorage.rows(); ++r ) { |
| 985 | if( (table_index_t) localStorage.rawRow(r).size() < maxCols ) { |
| 986 | ++shorterRows; |
| 987 | } |
| 988 | } |
| 989 | return {maxCols, shorterRows}; |
| 990 | } |
| 991 | |
| 992 | |
| 993 | /* |