summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-04-05 15:12:04 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-04-05 15:16:23 +0200
commit995b3186fa2126d1b299052a90a75cf32d5bfa26 (patch)
treeae518cbbc62791e3385ece602973ba1ac578ed2e /i18npool
parentd266373bbb48f1c4c481fac74727c7b17440f7bd (diff)
Use std algorithms here
Change-Id: Ib7bb92cca1f52067f9030b6c6fdc088409ca10ef Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113601 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/source/search/levdis.cxx62
-rw-r--r--i18npool/source/search/levdis.hxx4
2 files changed, 9 insertions, 57 deletions
diff --git a/i18npool/source/search/levdis.cxx b/i18npool/source/search/levdis.cxx
index 5842abd1eef5..dd9f8fbf587a 100644
--- a/i18npool/source/search/levdis.cxx
+++ b/i18npool/source/search/levdis.cxx
@@ -56,6 +56,7 @@
*/
#include <algorithm>
+#include <numeric>
#include "levdis.hxx"
@@ -119,7 +120,7 @@ int WLevDistance::WLD( const sal_Unicode* cString, sal_Int32 nStringLen )
nP = 0; // a '?' could be any character.
else
// Minimum of replacement and deletion+insertion weighting
- nP = Min3( nRepP0, nRepP0, nDelR0 + nInsQ0 );
+ nP = std::min({ nRepP0, nRepP0, nDelR0 + nInsQ0 });
npDistance[0] = nInsQ0; // start with simple insert
npDistance[1] = nInsQ0;
npDistance[2] = nInsQ0;
@@ -150,7 +151,7 @@ int WLevDistance::WLD( const sal_Unicode* cString, sal_Int32 nStringLen )
}
}
}
- nSPMin = Min3( npDistance[0], npDistance[1], npDistance[2] );
+ nSPMin = std::min({ npDistance[0], npDistance[1], npDistance[2] });
}
// calculate distance matrix
@@ -203,7 +204,7 @@ int WLevDistance::WLD( const sal_Unicode* cString, sal_Int32 nStringLen )
// WLD( X(i), Y(j) ) = min( WLD( X(i-1), Y(j-1) ) + p(i,j) ,
// WLD( X(i) , Y(j-1) ) + q ,
// WLD( X(i-1), Y(j) ) + r )
- npDistance[i] = Min3( d1 + nPij, d2 + nQ, npDistance[i-1] + nR );
+ npDistance[i] = std::min({ d1 + nPij, d2 + nQ, npDistance[i-1] + nR });
if ( npDistance[i] < nSPMin )
nSPMin = npDistance[i];
if ( bSplitCount )
@@ -263,63 +264,27 @@ void WLevDistance::CalcLPQR( int nX, int nY, int nZ, bool bRelaxed )
if ( nX < 0 ) nX = 0; // only positive values
if ( nY < 0 ) nY = 0;
if ( nZ < 0 ) nZ = 0;
- if (0 == Min3( nX, nY, nZ )) // at least one 0
+ if (0 == std::min({ nX, nY, nZ })) // at least one 0
{
int nMid, nMax;
- nMax = Max3( nX, nY, nZ ); // either 0 for three 0s or Max
+ nMax = std::max({ nX, nY, nZ }); // either 0 for three 0s or Max
if ( 0 == (nMid = Mid3( nX, nY, nZ )) ) // even two 0
nLimit = nMax; // either 0 or the only one >0
else // one is 0
- nLimit = LCM( nMid, nMax );
+ nLimit = std::lcm( nMid, nMax );
}
else // all three of them are not 0
- nLimit = LCM( LCM( nX, nY ), nZ );
+ nLimit = std::lcm(std::lcm(nX, nY), nZ);
nRepP0 = ( nX ? nLimit / nX : nLimit + 1 );
nInsQ0 = ( nY ? nLimit / nY : nLimit + 1 );
nDelR0 = ( nZ ? nLimit / nZ : nLimit + 1 );
bSplitCount = bRelaxed;
}
-// greatest common divisor according to Euklid (chaindivision)
-// special case: 0 plus anything produces 1
-int WLevDistance::GCD( int a, int b )
-{
- if ( !a || !b )
- return 1;
- if ( a < 0 ) a = -a;
- if ( b < 0 ) b = -b;
- do
- {
- if ( a > b )
- a -= int(a / b) * b;
- else
- b -= int(b / a) * a;
- } while ( a && b );
- return( a ? a : b);
-}
-
-// least common multiple : a * b / GCD(a,b)
-int WLevDistance::LCM( int a, int b )
-{
- if ( a > b ) // decrease overflow chance
- return( (a / GCD(a,b)) * b );
- else
- return( (b / GCD(a,b)) * a );
-}
-
-// Minimum of three values
-inline int WLevDistance::Min3( int x, int y, int z )
-{
- if ( x < y )
- return std::min(x, z);
- else
- return std::min(y, z);
-}
-
// The value in the middle
int WLevDistance::Mid3( int x, int y, int z )
{
- int min = Min3(x,y,z);
+ int min = std::min({ x, y, z });
if ( x == min )
return std::min(y, z);
else if ( y == min )
@@ -328,15 +293,6 @@ int WLevDistance::Mid3( int x, int y, int z )
return std::min(x, y);
}
-// Maximum of three values
-int WLevDistance::Max3( int x, int y, int z )
-{
- if ( x > y )
- return std::max(x, z);
- else
- return std::max(y, z);
-}
-
// initialize data from CTOR
void WLevDistance::InitData( const sal_Unicode* cPattern )
{
diff --git a/i18npool/source/search/levdis.hxx b/i18npool/source/search/levdis.hxx
index c789b7da8fb5..1dc570d39c21 100644
--- a/i18npool/source/search/levdis.hxx
+++ b/i18npool/source/search/levdis.hxx
@@ -147,11 +147,7 @@ class WLevDistance
bool bSplitCount; ///< if TRUE, Rep/Ins/Del are counted separately
void InitData( const sal_Unicode* cPattern );
- static inline int Min3( int x, int y, int z ); ///< minimum value of 3 values
static int Mid3( int x, int y, int z ); ///< middle value of 3 values
- static int Max3( int x, int y, int z ); ///< maximum value of 3 values
- static int GCD( int a, int b ); ///< Greatest Common Divisor
- static int LCM( int a, int b ); ///< Least Common Multiple
public: