<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Feb 13, 2015 at 12:10 PM, Shankar Easwaran <span dir="ltr"><<a href="mailto:shankare@codeaurora.org" target="_blank">shankare@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Honestly, std::set is the wrong data type here no matter what.<br>
</blockquote></span>
Why ? Order is less important for me but is nice to have too, I want the data structure to contain only unique values.<br>
<br>
>From cppreference, <a href="http://www.cplusplus.com/reference/set/set/" target="_blank">http://www.cplusplus.com/<u></u>reference/set/set/</a><br>
<br>
Sets are containers that store unique elements following a specific order.<br></blockquote><div><br></div><div>I know what sets are, and I know what std::set is. ;]</div><div><br></div><div>It may correctly model the API you want, but that doesn't mean it is the correct data structure to use.</div><div><br></div><div>Fundamentally std::set is abysmally slow on modern computers. The fundamental structure of it *requires* it to be implemented in terms of a balanced tree of nodes, each heap allocated and connected via pointers. The result is that traversals of the tree are extremely cache hostile and slow. This is in turn magnified by the performance problems of constantly rebalancing, as the rebalancing operations require significant traversals of the structure.</div><div><br></div><div>In essentially every case where std::set is used, there is a better data structure to express the same core concept but with significantly faster operations, and in many cases using significantly less memory. I've already listed the alternatives that seem strictly superior.</div><div><br></div><div><br></div><div>Also, you should never make data structure decisions based on what would be "nice to have". Either you traverse the structure and require the ordering to be there, or it isn't required and shouldn't be relevant.</div></div></div></div>