Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort by attribute and reorder by vector<int> for objList? #232

Open
ylchan87 opened this issue Jan 24, 2017 · 1 comment
Open

Sort by attribute and reorder by vector<int> for objList? #232

ylchan87 opened this issue Jan 24, 2017 · 1 comment
Labels

Comments

@ylchan87
Copy link
Contributor

The sort for objList in

husky/core/objlist.hpp

Lines 77 to 95 in 7ec82aa

void sort() {
auto& data = objlist_data_.data_;
if (data.size() == 0)
return;
std::vector<int> order(this->get_size());
for (int i = 0; i < order.size(); ++i) {
order[i] = i;
}
// sort the permutation
std::sort(order.begin(), order.end(),
[&](const size_t a, const size_t b) { return data[a].id() < data[b].id(); });
// apply the permutation on all the attribute lists
for (auto& it : this->attrlist_map) {
it.second->reorder(order);
}
std::sort(data.begin(), data.end(), [](const ObjT& a, const ObjT& b) { return a.id() < b.id(); });
hashed_objs_.clear();
sorted_size_ = data.size();
}

now sorts with the obj.id()
Is it feasible to allow a lambda arg so a user can say sort by obj attribute?

Also, std::sort is called twice in the current implementation.

If reorder is implemented for objList and
reorder does not destroy the input permutation list (right now I think it was changed to all -1 after the call)

then we can reuse the permutation list to arrange the objList and avoid calling std::sort twice.
Would such change be feasible?

@kygx-legend kygx-legend changed the title sort by attribute and reorder by vector<int> for objList? Sort by attribute and reorder by vector<int> for objList? Jan 26, 2017
@ddmbr
Copy link
Member

ddmbr commented Feb 23, 2017

If you sort by another attribute, how do you implement ObjList::find()? I think you may want to have an extra index above the existing object list instead, but I'm not sure how to maintain this index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants