U++ Forum - RDF feed
https://www.ultimatepp.org/forums/
[solved] Why doesn't Vector have Find?
https://www.ultimatepp.org/forums/index.php?t=rview&goto=45565&th=9486#msg_45565
.]]>cbpporter2015-12-04T13:59:42-00:00Re: Why doesn't Vector have Find?
https://www.ultimatepp.org/forums/index.php?t=rview&goto=45569&th=9486#msg_45569
But I doubt if slow sequential search is a good idea at all. If you want Vector and you want to have quick search, make it sorted. Add items by using FindUpperBound()-like calls, then you may search with FindBinary() which costs O(log(n)), not O(n) as for sequential search.]]>Mindtraveller2015-12-04T18:43:49-00:00Re: Why doesn't Vector have Find?
https://www.ultimatepp.org/forums/index.php?t=rview&goto=45570&th=9486#msg_45570
Mindtraveller wrote on Fri, 04 December 2015 19:43
There is a common Find() template to achieve what you want. It is applied to a number of containers, not only Vector.
But I doubt if slow sequential search is a good idea at all. If you want Vector and you want to have quick search, make it sorted. Add items by using FindUpperBound()-like calls, then you may search with FindBinary() which costs O(log(n)), not O(n) as for sequential search.
Actually, I think this might not be that bad idea, in fact I was thinking about it too.
Thing is that sometimes you know that you only have a limited number of elements to find, but you want to conserve memory. Index consumes quite a lot of auxiliary memory for hashing. In that case, I often use simple Vector with FindIndex. Anyway, sometimes later it is needed to convert (or copy/paste) code to Index. Having Find as method would save some typing.
BTW, if you are about to insert items by FindUpperBound, you might consider using Sorted* kind of container
Mirek]]>mirek2015-12-05T10:28:16-00:00Re: Why doesn't Vector have Find?
https://www.ultimatepp.org/forums/index.php?t=rview&goto=45989&th=9486#msg_45989
I have a ton of finds in Vectors implemented using for loops and I'm about to replace them with my "find" global method.]]>cbpporter2016-02-10T15:02:44-00:00Re: Why doesn't Vector have Find?
https://www.ultimatepp.org/forums/index.php?t=rview&goto=45990&th=9486#msg_45990
cbpporter wrote on Wed, 10 February 2016 16:02
So, has any decision been reached?
I have a ton of finds in Vectors implemented using for loops and I'm about to replace them with my "find" global method.
Well, FindIndex existed in U++ for ages... (does exactly that).
I am now in middle of major Core complete overhaul, changing everything to C++11/14 standards. Maybe I will add Find to Vector/Array in the process...]]>mirek2016-02-10T17:07:11-00:00Re: Why doesn't Vector have Find?
https://www.ultimatepp.org/forums/index.php?t=rview&goto=45999&th=9486#msg_45999
Hmmm, Core updates. Exciting!]]>cbpporter2016-02-12T15:31:31-00:00