c++ - What's the correct data structure for 2-prop sorted list? -


i writing simple handless ui framework, in need dispatch message own.

every widget has list of child, has 2 properties: paint order(the order recieve paint message) , other-event order(the order receive message other paint).

void widget::sortchildwidgets( sortmode mode ) {     if (mode == ksortbypaint) {         //return true if should precede otherwise return false;         m_children.sort([&](widget* pw1, widget* pw2) ->bool {             if (pw1->getpaintorder() < pw2->getpaintorder()) {                 return true;             } else {                 return false;             }         });     }      if (mode == ksortbyevent) {         //return true if should precede otherwise return false;         m_children.sort([&](widget* pw1, widget* pw2) ->bool {             if (pw1->geteventorder() < pw2->geteventorder()) {                 return true;             } else {                 return false;             }         });     } } 

because widget change order @ runtime, need resort everytime dispatch message, definitly bad.

my problem: there better data structure rather std::list free me sort every time dispatch message, or need maintain std::list , make sorted everytime insert child widget?

the recommended data-structure keeping items ordered std::set. can provide custom predicate ordering, , keep same items in multiple sets different ordering.

if need more performance, boost.multi-index. library designed keep multiple views of same data-set different orderings.

note neither of these data-structure assume value of key not change once has been added.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -