[multi-index?] Advice about publicizing capacity for sets/vectors

I was thinking of using a multi-indexed container as part of an implementation of another container. The final container will have an interface like a set, but internally the elements sometimes have to be accessible via random-access iteration[1]. Implementing with a straight set would limit me to bidirectional iteration, which will slow down internal operations that need random access. The internal multi-index container would have set and vector aspects, i.e. ordered-unique and random-access index specifiers. Even though the external interface will be like a set, should I have publicize the vector-like operations "capacity" and "reserve"? Will reserving capacity help in the ordered-unique part of any insertions? Alternatively, is there a better way to implement a set w/ random-access iteration besides this multi-index idea? [1] I think that the external iterators should stay bidirectional. That way I can transfer the ordered-unique view's iterators and give a consistent traversal order. If I use the random-access view's iterators, I could traverse better but there'll be no obvious rule to the arrangement of elements from the user's perspective. -- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com

Hello Daryle, Daryle Walker ha escrito:
I was thinking of using a multi-indexed container as part of an implementation of another container. The final container will have an interface like a set, but internally the elements sometimes have to be accessible via random-access iteration[1]. Implementing with a straight set would limit me to bidirectional iteration, which will slow down internal operations that need random access.
The internal multi-index container would have set and vector aspects, i.e. ordered-unique and random-access index specifiers. Even though the external interface will be like a set, should I have publicize the vector-like operations "capacity" and "reserve"? Will reserving capacity help in the ordered-unique part of any insertions?
Yes, reserving will gain you some performance even if insertions are made through the ordered_unique index --take into account that inserting through any index will also affect all other indices behind the scenes.
Alternatively, is there a better way to implement a set w/ random-access iteration besides this multi-index idea?
I hope there isn't :) Seriously, Boost.MultiIndex is designed to be as compact and efficient as possible, so it's probably an optimum choice for your problem with respect to memory usage and performance. As for the resulting user interface, it may not suit your particular needs, in which case you'll have to do some wrapping work over the core multi_index_container. Best, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (2)
-
Daryle Walker
-
Joaquín Mª López Muñoz