mirror of
https://github.com/opencv/opencv.git
synced 2025-07-25 22:57:53 +08:00
Adds efficient sort algorithm to KNearest
This commit is contained in:
parent
7bc980edaf
commit
65d816c3b5
@ -240,20 +240,7 @@ public:
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
float* rp = rbuf + testidx*k;
|
float* rp = rbuf + testidx*k;
|
||||||
for( j = k-1; j > 0; j-- )
|
std::sort(rp, rp+k);
|
||||||
{
|
|
||||||
bool swap_fl = false;
|
|
||||||
for( i = 0; i < j; i++ )
|
|
||||||
{
|
|
||||||
if( rp[i] > rp[i+1] )
|
|
||||||
{
|
|
||||||
std::swap(rp[i], rp[i+1]);
|
|
||||||
swap_fl = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( !swap_fl )
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = rp[0];
|
result = rp[0];
|
||||||
int prev_start = 0;
|
int prev_start = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user