Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » [solved] Why doesn't Vector have Find?
[solved] Why doesn't Vector have Find? [message #45565] Fri, 04 December 2015 14:59 Go to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
I know that it is not particularly fast, but it is convenient. I am tired of changing Vectors to Index for the sole reason of having uniform Find interface Smile.

[Updated on: Tue, 03 January 2017 11:44]

Report message to a moderator

Re: Why doesn't Vector have Find? [message #45569 is a reply to message #45565] Fri, 04 December 2015 19:43 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

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.
Re: Why doesn't Vector have Find? [message #45570 is a reply to message #45569] Sat, 05 December 2015 11:28 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
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 Smile

Mirek

[Updated on: Sat, 05 December 2015 11:46]

Report message to a moderator

Re: Why doesn't Vector have Find? [message #45989 is a reply to message #45570] Wed, 10 February 2016 16:02 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
So, has any decision been reached? Smile

I have a ton of finds in Vectors implemented using for loops and I'm about to replace them with my "find" global method.
Re: Why doesn't Vector have Find? [message #45990 is a reply to message #45989] Wed, 10 February 2016 18:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
cbpporter wrote on Wed, 10 February 2016 16:02
So, has any decision been reached? Smile

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...
Re: Why doesn't Vector have Find? [message #45999 is a reply to message #45990] Fri, 12 February 2016 16:31 Go to previous message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
FindIndex will do for now.

Hmmm, Core updates. Exciting!
Previous Topic: Time in milliseconds
Next Topic: IntStr function returns an empty string
Goto Forum:
  


Current Time: Fri Mar 29 15:38:55 CET 2024

Total time taken to generate the page: 0.01130 seconds