multi_index_map icon indicating copy to clipboard operation
multi_index_map copied to clipboard

feature request: `iter_by_` values mapped to a single index value

Open dknopik opened this issue 4 months ago • 1 comments

Currently, the iter_by_ methods for non-unique indices work by iterating over all index values and then iterating over the values associated to each index. So basically, the difference to a simple iter is that the values will be ordered differently: with `iter_by_´, they will be grouped by index.

However, this is not that useful to my use case. When I saw that there are iter_by_ functions (without checking the full signature), I assumed that they worked like this: accept a value for the corresponding index and iterate to all map values associated to it. Basically, first look up the indices of the map values for the desired index value (through a simple hash map retrieval), then return an iterator used to iterate over the corresponding map values.

This is more efficient than the current iter_by_ methods as we do not have to filter for the desired index first. Effectively, the described functionality above would be the same as get_by_*().into_iter(), except that it avoids allocating.

dknopik avatar Aug 05 '25 07:08 dknopik

This would also make things like checking if there is an entry per non-hashed key a lot more efficient as it currently always has to evaluate to a Vec

Swoorup avatar Aug 25 '25 10:08 Swoorup