I have a list of items that are created each frame and need to be sorted.
Each Item's first member variable to sort by is an unordered_set
.
I've moved this to an ordered set everywhere in the system so I can sort it in the list of items. But I'm suffering a performance hit in another are of the code foe this.
Bearing in mind that each item will be destroyed and be recreated on a per-frame basis, is there anything I can do to hold these in unordered_set
s and sort them?
class item
{
public:
unordered_set< int > _sortUS;
int _sortI;
//Other members to sort
bool operator<( const item& that ) const
{
if( _sortI != that._sortI )
{
return _sortI < that._sortI;
}
else if( _sortUS != that._sortUS )
{
return ??? // this is what I need. I don't know how to compare these without converting them to sets
}
}
};
unsorted_set
s? – Gilmerunordered_set
. I just wanted to make it clear that I own the item's comparison operator, so I can make changes to how the operator comparesunordered_set
s. – Breezeoperator <
) on the items. I am still unclear what the question is - do you have a "less than" criterion for theunorderd_set
s which you have trouble expressin in code (if so, please add it to the question), or is it something else? – Gilmerlexicographical_compare(sort(uo1), sort(uo2))
? Also, if you are re-creating and destroying items very often you really want to make sure to reuse the memory of thesets
. So instead of destroying them, assign to them. – Zelayaset
s so I can just use anoperator<
to compare. But I'm taking a performance hit on insertion. Is there some magic that I can do to sortunordered_set
s? – Breeze