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 » Patch for Algo.h
Patch for Algo.h [message #53185] Sun, 15 March 2020 18:56
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Below is a tiny patch for Algo.h
Storing r.GetCount() on stack improves performance with ranges which do not store length explicitly.
template <class Range, class C>
int FindMatch(const Range& r, const C& match, int from = 0)
{
	const int count = r.GetCount();
	for(int i = from; i < count; i++)
		if(match(r[i])) return i;
	return -1;
}

template <class Range, class V>
int FindIndex(const Range& r, const V& value, int from = 0)
{
	const int count = r.GetCount();
	for(int i = from; i < count; i++)
		if(r[i] == value) return i;
	return -1;
}

template <class Range, class Predicate>
Vector<int> FindAll(const Range& r, Predicate match, int from = 0)
{
	Vector<int> ndx;
	const int count = r.GetCount();
	for(int i = from; i < count; i++)
		if(match(r[i]))
			ndx.Add(i);
	return ndx;
}

template <class Range, class Predicate>
Vector<int> FindAlli(const Range& r, Predicate match, int from = 0)
{
	Vector<int> ndx;
	const int count = r.GetCount();
	for(int i = from; i < count; i++)
		if(match(i))
			ndx.Add(i);
	return ndx;
}


Regards,
Novo
 
Read Message
Previous Topic: PolyCompare instantiation template<> for double missing
Next Topic: [Proposal] RGB <-> CMYK conversion functions.
Goto Forum:
  


Current Time: Thu Mar 28 13:32:36 CET 2024

Total time taken to generate the page: 0.01006 seconds