diff options
-rw-r--r-- | src/compare.cc | 33 | ||||
-rw-r--r-- | src/compare.h | 2 |
2 files changed, 33 insertions, 2 deletions
diff --git a/src/compare.cc b/src/compare.cc index 3b85f149..f34d5aa8 100644 --- a/src/compare.cc +++ b/src/compare.cc @@ -33,6 +33,35 @@ namespace ledger { +bool value_is_less_than(const value_t& left, const value_t& right) +{ + if (left.is_sequence()) { + assert(right.is_sequence()); + + const value_t::sequence_t& left_seq(left.as_sequence()); + value_t::sequence_t::const_iterator left_iter = left_seq.begin(); + + const value_t::sequence_t& right_seq(right.as_sequence()); + value_t::sequence_t::const_iterator right_iter = right_seq.begin(); + + while (left_iter != left_seq.end() && + right_iter != right_seq.end()) { + if (*left_iter < *right_iter) + return true; + else if (*left_iter > *right_iter) + return false; + left_iter++; right_iter++; + } + + assert(left_iter == left_seq.end()); + assert(right_iter == right_seq.end()); + + return true; + } else { + return left < right; + } +} + template <> bool compare_items<xact_t>::operator()(xact_t * left, xact_t * right) { @@ -58,7 +87,7 @@ bool compare_items<xact_t>::operator()(xact_t * left, xact_t * right) DEBUG("ledger.walk.compare_items_xact", "rxdata.sort_value = " << rxdata.sort_value); - return lxdata.sort_value < rxdata.sort_value; + return value_is_less_than(lxdata.sort_value, rxdata.sort_value); } template <> @@ -79,7 +108,7 @@ bool compare_items<account_t>::operator()(account_t * left, account_t * right) rxdata.add_flags(ACCOUNT_EXT_SORT_CALC); } - return lxdata.sort_value < rxdata.sort_value; + return value_is_less_than(lxdata.sort_value, rxdata.sort_value); } } // namespace ledger diff --git a/src/compare.h b/src/compare.h index 09abbd2a..70b44ed3 100644 --- a/src/compare.h +++ b/src/compare.h @@ -77,6 +77,8 @@ public: bool operator()(T * left, T * right); }; +bool value_is_less_than(const value_t& left, const value_t& right); + template <typename T> bool compare_items<T>::operator()(T * left, T * right) { |