[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 58b0c04 3/9: Sort columns alphabetically in T
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 58b0c04 3/9: Sort columns alphabetically in TSV output |
Date: |
Thu, 27 Sep 2018 12:53:50 -0400 (EDT) |
branch: master
commit 58b0c04f9c50d6bdc1157793040641262192e5a0
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Sort columns alphabetically in TSV output
Incidentally, omit spaces between arguments in template instantiations
so that they're more easily recognizable as single syntactic units.
---
ledger_evaluator.cpp | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/ledger_evaluator.cpp b/ledger_evaluator.cpp
index b609c00..a112a08 100644
--- a/ledger_evaluator.cpp
+++ b/ledger_evaluator.cpp
@@ -48,6 +48,7 @@
#include <algorithm> // fill(), transform()
#include <functional> // minus
+#include <map>
#include <unordered_map>
#include <utility> // move(), pair
@@ -871,8 +872,8 @@ ledger_evaluator Ledger::make_evaluator() const
// Maps to hold the results of formatting numeric data.
- std::unordered_map<std::string, std::string> stringscalars;
- std::unordered_map<std::string, std::vector<std::string>> stringvectors;
+ std::unordered_map<std::string,std::string> stringscalars;
+ std::unordered_map<std::string,std::vector<std::string>> stringvectors;
stringvectors["FundNames"] = ledger_invariant_->FundNames;
@@ -1007,7 +1008,16 @@ ledger_evaluator Ledger::make_evaluator() const
);
fs::ofstream ofs(filepath, ios_out_trunc_binary());
- for(auto const& j : stringvectors)
+ // Copy 'stringvectors' to a (sorted) std::map in order to
+ // show columns alphabetically. Other, more complicated
+ // techniques are faster, but direct copying favors simplicity
+ // over speed--appropriately, as this facility is rarely used.
+ std::map<std::string,std::vector<std::string>> ordered_stringvectors
+ (stringvectors.begin()
+ ,stringvectors.end()
+ );
+
+ for(auto const& j : ordered_stringvectors)
{
ofs << j.first << '\t';
}
@@ -1015,7 +1025,7 @@ ledger_evaluator Ledger::make_evaluator() const
for(int i = 0; i < GetMaxLength(); ++i)
{
- for(auto const& j : stringvectors)
+ for(auto const& j : ordered_stringvectors)
{
std::vector<std::string> const& v = j.second;
if(i < lmi::ssize(v))
- [lmi-commits] [lmi] master updated (ea25cc6 -> 058e112), Greg Chicares, 2018/09/27
- [lmi-commits] [lmi] master 7d7cd0d 4/9: Adjust whitespace for vertical alignment, Greg Chicares, 2018/09/27
- [lmi-commits] [lmi] master 3d75aa3 2/9: Rearrange headers, Greg Chicares, 2018/09/27
- [lmi-commits] [lmi] master 429acb9 1/9: Add missing 'pyx="values_tsv"' support, Greg Chicares, 2018/09/27
- [lmi-commits] [lmi] master 58b0c04 3/9: Sort columns alphabetically in TSV output,
Greg Chicares <=
- [lmi-commits] [lmi] master 0593224 5/9: Reorder statements more logically, Greg Chicares, 2018/09/27
- [lmi-commits] [lmi] master bb0eb2c 7/9: Favor problem-domain terminology, Greg Chicares, 2018/09/27
- [lmi-commits] [lmi] master 16da526 6/9: Change the format of 'GenAcctAllocation', Greg Chicares, 2018/09/27
- [lmi-commits] [lmi] master 058e112 9/9: Assert a formerly implicit assumption, Greg Chicares, 2018/09/27
- [lmi-commits] [lmi] master 957fb26 8/9: Favor problem-domain terminology, Greg Chicares, 2018/09/27