Update sort.cpp

This commit is contained in:
Paul Beckingham 2019-02-07 08:12:59 -05:00
parent 803f4a5017
commit 32d14bc085

View file

@ -49,7 +49,6 @@ void sort_tasks (
const std::string& keys) const std::string& keys)
{ {
Timer timer; Timer timer;
global_data = &data; global_data = &data;
// Split the key defs. // Split the key defs.
@ -76,16 +75,18 @@ void sort_projects (
for (auto& parent : parents) for (auto& parent : parents)
{ {
parent_pos = std::find_if (sorted.begin (), sorted.end (), parent_pos = std::find_if (sorted.begin (), sorted.end (),
[&parent](const std::pair <std::string, int>& item) { return item.first == parent; } [&parent](const std::pair <std::string, int>& item) { return item.first == parent; });
);
// if parent does not exist yet: insert into sorted view // if parent does not exist yet: insert into sorted view
if (parent_pos == sorted.end ()) { if (parent_pos == sorted.end ())
sorted.push_back (std::make_pair (parent, 1)); sorted.push_back (std::make_pair (parent, 1));
}
} }
// insert new element below latest parent // insert new element below latest parent
sorted.insert ((parent_pos == sorted.end ()) ? parent_pos : ++parent_pos, project); sorted.insert ((parent_pos == sorted.end ()) ? parent_pos : ++parent_pos, project);
} else { }
else
{
// if has no parents: simply push to end of list // if has no parents: simply push to end of list
sorted.push_back (project); sorted.push_back (project);
} }