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

Home » U++ Library support » U++ Core » Patch for Algo.h
Patch for Algo.h Sun, 15 March 2020 18:56
 Novo Messages: 1009Registered: December 2006 Experienced 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]))
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))
return ndx;
}

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

Current Time: Fri Jun 05 16:43:06 CEST 2020

Total time taken to generate the page: 0.01692 seconds