@@ -438,8 +438,8 @@ SAMPLE* MakeSample(CLUSTERER * Clusterer, const float* Feature,
438
438
Sample = (SAMPLE *) Emalloc (sizeof (SAMPLE) +
439
439
(Clusterer->SampleSize -
440
440
1 ) * sizeof (float ));
441
- Sample->Clustered = FALSE ;
442
- Sample->Prototype = FALSE ;
441
+ Sample->Clustered = false ;
442
+ Sample->Prototype = false ;
443
443
Sample->SampleCount = 1 ;
444
444
Sample->Left = nullptr ;
445
445
Sample->Right = nullptr ;
@@ -553,7 +553,7 @@ void FreePrototype(void *arg) { //PROTOTYPE *Prototype)
553
553
554
554
// unmark the corresponding cluster (if there is one
555
555
if (Prototype->Cluster != nullptr )
556
- Prototype->Cluster ->Prototype = FALSE ;
556
+ Prototype->Cluster ->Prototype = false ;
557
557
558
558
// deallocate the prototype statistics and then the prototype itself
559
559
free (Prototype->Distrib );
@@ -586,7 +586,7 @@ CLUSTER *NextSample(LIST *SearchState) {
586
586
return (nullptr );
587
587
Cluster = (CLUSTER *) first_node (*SearchState);
588
588
*SearchState = pop (*SearchState);
589
- while ( TRUE ) {
589
+ for (;; ) {
590
590
if (Cluster->Left == nullptr )
591
591
return (Cluster);
592
592
*SearchState = push (*SearchState, Cluster->Right );
@@ -790,15 +790,15 @@ static CLUSTER* MakeNewCluster(CLUSTERER* Clusterer,
790
790
// allocate the new cluster and initialize it
791
791
Cluster = (CLUSTER *) Emalloc (
792
792
sizeof (CLUSTER) + (Clusterer->SampleSize - 1 ) * sizeof (float ));
793
- Cluster->Clustered = FALSE ;
794
- Cluster->Prototype = FALSE ;
793
+ Cluster->Clustered = false ;
794
+ Cluster->Prototype = false ;
795
795
Cluster->Left = TempCluster->Cluster ;
796
796
Cluster->Right = TempCluster->Neighbor ;
797
797
Cluster->CharID = -1 ;
798
798
799
799
// mark the old clusters as "clustered" and delete them from the kd-tree
800
- Cluster->Left ->Clustered = TRUE ;
801
- Cluster->Right ->Clustered = TRUE ;
800
+ Cluster->Left ->Clustered = true ;
801
+ Cluster->Right ->Clustered = true ;
802
802
KDDelete (Clusterer->KDTree , Cluster->Left ->Mean , Cluster->Left );
803
803
KDDelete (Clusterer->KDTree , Cluster->Right ->Mean , Cluster->Right );
804
804
@@ -1024,7 +1024,7 @@ static PROTOTYPE* MakeDegenerateProto( //this was MinSample
1024
1024
Proto = NewMixedProto (N, Cluster, Statistics);
1025
1025
break ;
1026
1026
}
1027
- Proto->Significant = FALSE ;
1027
+ Proto->Significant = false ;
1028
1028
}
1029
1029
return (Proto);
1030
1030
} // MakeDegenerateProto
@@ -1518,17 +1518,17 @@ static PROTOTYPE *NewSimpleProto(int16_t N, CLUSTER *Cluster) {
1518
1518
Proto->Mean [i] = Cluster->Mean [i];
1519
1519
Proto->Distrib = nullptr ;
1520
1520
1521
- Proto->Significant = TRUE ;
1522
- Proto->Merged = FALSE ;
1521
+ Proto->Significant = true ;
1522
+ Proto->Merged = false ;
1523
1523
Proto->Style = spherical;
1524
1524
Proto->NumSamples = Cluster->SampleCount ;
1525
1525
Proto->Cluster = Cluster;
1526
- Proto->Cluster ->Prototype = TRUE ;
1526
+ Proto->Cluster ->Prototype = true ;
1527
1527
return (Proto);
1528
1528
} // NewSimpleProto
1529
1529
1530
1530
/* *
1531
- * This routine returns TRUE if the specified covariance
1531
+ * This routine returns true if the specified covariance
1532
1532
* matrix indicates that all N dimensions are independent of
1533
1533
* one another. One dimension is judged to be independent of
1534
1534
* another when the magnitude of the corresponding correlation
@@ -1543,7 +1543,7 @@ static PROTOTYPE *NewSimpleProto(int16_t N, CLUSTER *Cluster) {
1543
1543
* @param N number of dimensions
1544
1544
* @param CoVariance ptr to a covariance matrix
1545
1545
* @param Independence max off-diagonal correlation coefficient
1546
- * @return TRUE if dimensions are independent, FALSE otherwise
1546
+ * @return true if dimensions are independent, false otherwise
1547
1547
*/
1548
1548
static bool
1549
1549
Independent (PARAM_DESC* ParamDesc,
@@ -1999,13 +1999,13 @@ static uint16_t UniformBucket(PARAM_DESC *ParamDesc,
1999
1999
2000
2000
/* *
2001
2001
* This routine performs a chi-square goodness of fit test
2002
- * on the histogram data in the Buckets data structure. TRUE
2003
- * is returned if the histogram matches the probability
2002
+ * on the histogram data in the Buckets data structure.
2003
+ * true is returned if the histogram matches the probability
2004
2004
* distribution which was specified when the Buckets
2005
- * structure was originally created. Otherwise FALSE is
2005
+ * structure was originally created. Otherwise false is
2006
2006
* returned.
2007
2007
* @param Buckets histogram data to perform chi-square test on
2008
- * @return TRUE if samples match distribution, FALSE otherwise
2008
+ * @return true if samples match distribution, false otherwise
2009
2009
*/
2010
2010
static bool DistributionOK (BUCKETS* Buckets) {
2011
2011
float FrequencyDifference;
@@ -2140,7 +2140,7 @@ static void InitBuckets(BUCKETS *Buckets) {
2140
2140
*
2141
2141
* @param arg1 chi-squared struct being tested for a match
2142
2142
* @param arg2 chi-squared struct that is the search key
2143
- * @return TRUE if ChiStruct's Alpha matches SearchKey's Alpha
2143
+ * @return true if ChiStruct's Alpha matches SearchKey's Alpha
2144
2144
*/
2145
2145
static int AlphaMatch (void *arg1, // CHISTRUCT *ChiStruct,
2146
2146
void *arg2) { // CHISTRUCT *SearchKey)
@@ -2271,8 +2271,8 @@ static double ChiArea(CHISTRUCT *ChiParams, double x) {
2271
2271
* This routine looks at all samples in the specified cluster.
2272
2272
* It computes a running estimate of the percentage of the
2273
2273
* characters which have more than 1 sample in the cluster.
2274
- * When this percentage exceeds MaxIllegal, TRUE is returned.
2275
- * Otherwise FALSE is returned. The CharID
2274
+ * When this percentage exceeds MaxIllegal, true is returned.
2275
+ * Otherwise false is returned. The CharID
2276
2276
* fields must contain integers which identify the training
2277
2277
* characters which were used to generate the sample. One
2278
2278
* integer is used for each sample. The NumChar field in
@@ -2288,16 +2288,14 @@ static double ChiArea(CHISTRUCT *ChiParams, double x) {
2288
2288
* @param Cluster cluster containing samples to be tested
2289
2289
* @param MaxIllegal max percentage of samples allowed to have
2290
2290
* more than 1 feature in the cluster
2291
- * @return TRUE if the cluster should be split, FALSE otherwise.
2291
+ * @return true if the cluster should be split, false otherwise.
2292
2292
*/
2293
2293
static bool
2294
2294
MultipleCharSamples (CLUSTERER* Clusterer,
2295
2295
CLUSTER* Cluster, float MaxIllegal)
2296
2296
#define ILLEGAL_CHAR 2
2297
2297
{
2298
- static BOOL8 *CharFlags = nullptr ;
2299
- static int32_t NumFlags = 0 ;
2300
- int i;
2298
+ static std::vector<uint8_t > CharFlags;
2301
2299
LIST SearchState;
2302
2300
SAMPLE *Sample;
2303
2301
int32_t CharID;
@@ -2309,24 +2307,22 @@ MultipleCharSamples(CLUSTERER* Clusterer,
2309
2307
NumCharInCluster = Cluster->SampleCount ;
2310
2308
NumIllegalInCluster = 0 ;
2311
2309
2312
- if (Clusterer->NumChar > NumFlags) {
2313
- free (CharFlags);
2314
- NumFlags = Clusterer->NumChar ;
2315
- CharFlags = (BOOL8 *) Emalloc (NumFlags * sizeof (BOOL8));
2310
+ if (Clusterer->NumChar > CharFlags.size ()) {
2311
+ CharFlags.resize (Clusterer->NumChar );
2316
2312
}
2317
2313
2318
- for (i = 0 ; i < NumFlags; i++ )
2319
- CharFlags[i] = FALSE ;
2314
+ for (auto & CharFlag : CharFlags )
2315
+ CharFlag = false ;
2320
2316
2321
2317
// find each sample in the cluster and check if we have seen it before
2322
2318
InitSampleSearch (SearchState, Cluster);
2323
2319
while ((Sample = NextSample (&SearchState)) != nullptr ) {
2324
2320
CharID = Sample->CharID ;
2325
- if (CharFlags[CharID] == FALSE ) {
2326
- CharFlags[CharID] = TRUE ;
2321
+ if (CharFlags[CharID] == false ) {
2322
+ CharFlags[CharID] = true ;
2327
2323
}
2328
2324
else {
2329
- if (CharFlags[CharID] == TRUE ) {
2325
+ if (CharFlags[CharID] == true ) {
2330
2326
NumIllegalInCluster++;
2331
2327
CharFlags[CharID] = ILLEGAL_CHAR;
2332
2328
}
0 commit comments