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?
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 previous message
mirek is currently offline  mirek
Messages: 13984
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

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Time in milliseconds
Next Topic: IntStr function returns an empty string
Goto Forum:
  


Current Time: Tue Jun 04 02:47:48 CEST 2024

Total time taken to generate the page: 0.01751 seconds