]> git.scottworley.com Git - tablify/commitdiff
Sort columns _descending_ by frequency
authorScott Worley <scottworley@scottworley.com>
Tue, 20 Aug 2024 17:38:24 +0000 (10:38 -0700)
committerScott Worley <scottworley@scottworley.com>
Tue, 20 Aug 2024 18:00:27 +0000 (11:00 -0700)
Changelog
src/lib.rs

index 4be743b0432cf6cdb236c1fe6fe2fb60be08e262..8af88114969b883714478401ea4cbf42167afb70 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1,5 +1,6 @@
 ## [Unreleased]
 - A little more space up top
+- Sort columns _descending_ by frequency
 
 ## [0.2.0] - 2024-08-19
 Initial release
index 30026929c3993ea004d726e2c0ceffcbc44957ce..fbafcb1726863ebac3aba8407b174820a1038c56 100644 (file)
@@ -137,7 +137,7 @@ fn column_counts(rows: &[RowInput]) -> Vec<(usize, String)> {
         .into_iter()
         .map(|(col, n)| (n, col))
         .collect();
-    counts.sort();
+    counts.sort_unstable_by(|(an, acol), (bn, bcol)| bn.cmp(an).then(acol.cmp(bcol)));
     counts
 }
 fn column_order(rows: &[RowInput]) -> Vec<String> {
@@ -353,7 +353,7 @@ mod tests {
                     .collect::<Result<Vec<_>, _>>()
                     .unwrap()
             ),
-            vec![(1, String::from("bar")), (2, String::from("baz"))]
+            vec![(2, String::from("baz")), (1, String::from("bar"))]
         );
         assert_eq!(
             column_counts(
@@ -361,7 +361,7 @@ mod tests {
                     .collect::<Result<Vec<_>, _>>()
                     .unwrap()
             ),
-            vec![(1, String::from("bar")), (2, String::from("baz"))]
+            vec![(2, String::from("baz")), (1, String::from("bar"))]
         );
         assert_eq!(
             column_counts(
@@ -369,7 +369,7 @@ mod tests {
                     .collect::<Result<Vec<_>, _>>()
                     .unwrap()
             ),
-            vec![(1, String::from("bar")), (2, String::from("baz"))]
+            vec![(2, String::from("baz")), (1, String::from("bar"))]
         );
     }