Skip to content

Commit cbb5e72

Browse files
committed
classify: Use bool and replace TRUE, FALSE
Signed-off-by: Stefan Weil <[email protected]>
1 parent 46fa59a commit cbb5e72

File tree

3 files changed

+36
-40
lines changed

3 files changed

+36
-40
lines changed

src/classify/cluster.cpp

+30-34
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ SAMPLE* MakeSample(CLUSTERER * Clusterer, const float* Feature,
438438
Sample = (SAMPLE *) Emalloc (sizeof (SAMPLE) +
439439
(Clusterer->SampleSize -
440440
1) * sizeof (float));
441-
Sample->Clustered = FALSE;
442-
Sample->Prototype = FALSE;
441+
Sample->Clustered = false;
442+
Sample->Prototype = false;
443443
Sample->SampleCount = 1;
444444
Sample->Left = nullptr;
445445
Sample->Right = nullptr;
@@ -553,7 +553,7 @@ void FreePrototype(void *arg) { //PROTOTYPE *Prototype)
553553

554554
// unmark the corresponding cluster (if there is one
555555
if (Prototype->Cluster != nullptr)
556-
Prototype->Cluster->Prototype = FALSE;
556+
Prototype->Cluster->Prototype = false;
557557

558558
// deallocate the prototype statistics and then the prototype itself
559559
free(Prototype->Distrib);
@@ -586,7 +586,7 @@ CLUSTER *NextSample(LIST *SearchState) {
586586
return (nullptr);
587587
Cluster = (CLUSTER *) first_node (*SearchState);
588588
*SearchState = pop (*SearchState);
589-
while (TRUE) {
589+
for (;;) {
590590
if (Cluster->Left == nullptr)
591591
return (Cluster);
592592
*SearchState = push (*SearchState, Cluster->Right);
@@ -790,15 +790,15 @@ static CLUSTER* MakeNewCluster(CLUSTERER* Clusterer,
790790
// allocate the new cluster and initialize it
791791
Cluster = (CLUSTER *) Emalloc(
792792
sizeof(CLUSTER) + (Clusterer->SampleSize - 1) * sizeof(float));
793-
Cluster->Clustered = FALSE;
794-
Cluster->Prototype = FALSE;
793+
Cluster->Clustered = false;
794+
Cluster->Prototype = false;
795795
Cluster->Left = TempCluster->Cluster;
796796
Cluster->Right = TempCluster->Neighbor;
797797
Cluster->CharID = -1;
798798

799799
// 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;
802802
KDDelete(Clusterer->KDTree, Cluster->Left->Mean, Cluster->Left);
803803
KDDelete(Clusterer->KDTree, Cluster->Right->Mean, Cluster->Right);
804804

@@ -1024,7 +1024,7 @@ static PROTOTYPE* MakeDegenerateProto( //this was MinSample
10241024
Proto = NewMixedProto (N, Cluster, Statistics);
10251025
break;
10261026
}
1027-
Proto->Significant = FALSE;
1027+
Proto->Significant = false;
10281028
}
10291029
return (Proto);
10301030
} // MakeDegenerateProto
@@ -1518,17 +1518,17 @@ static PROTOTYPE *NewSimpleProto(int16_t N, CLUSTER *Cluster) {
15181518
Proto->Mean[i] = Cluster->Mean[i];
15191519
Proto->Distrib = nullptr;
15201520

1521-
Proto->Significant = TRUE;
1522-
Proto->Merged = FALSE;
1521+
Proto->Significant = true;
1522+
Proto->Merged = false;
15231523
Proto->Style = spherical;
15241524
Proto->NumSamples = Cluster->SampleCount;
15251525
Proto->Cluster = Cluster;
1526-
Proto->Cluster->Prototype = TRUE;
1526+
Proto->Cluster->Prototype = true;
15271527
return (Proto);
15281528
} // NewSimpleProto
15291529

15301530
/**
1531-
* This routine returns TRUE if the specified covariance
1531+
* This routine returns true if the specified covariance
15321532
* matrix indicates that all N dimensions are independent of
15331533
* one another. One dimension is judged to be independent of
15341534
* another when the magnitude of the corresponding correlation
@@ -1543,7 +1543,7 @@ static PROTOTYPE *NewSimpleProto(int16_t N, CLUSTER *Cluster) {
15431543
* @param N number of dimensions
15441544
* @param CoVariance ptr to a covariance matrix
15451545
* @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
15471547
*/
15481548
static bool
15491549
Independent(PARAM_DESC* ParamDesc,
@@ -1999,13 +1999,13 @@ static uint16_t UniformBucket(PARAM_DESC *ParamDesc,
19991999

20002000
/**
20012001
* 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
20042004
* distribution which was specified when the Buckets
2005-
* structure was originally created. Otherwise FALSE is
2005+
* structure was originally created. Otherwise false is
20062006
* returned.
20072007
* @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
20092009
*/
20102010
static bool DistributionOK(BUCKETS* Buckets) {
20112011
float FrequencyDifference;
@@ -2140,7 +2140,7 @@ static void InitBuckets(BUCKETS *Buckets) {
21402140
*
21412141
* @param arg1 chi-squared struct being tested for a match
21422142
* @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
21442144
*/
21452145
static int AlphaMatch(void *arg1, //CHISTRUCT *ChiStruct,
21462146
void *arg2) { //CHISTRUCT *SearchKey)
@@ -2271,8 +2271,8 @@ static double ChiArea(CHISTRUCT *ChiParams, double x) {
22712271
* This routine looks at all samples in the specified cluster.
22722272
* It computes a running estimate of the percentage of the
22732273
* 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
22762276
* fields must contain integers which identify the training
22772277
* characters which were used to generate the sample. One
22782278
* integer is used for each sample. The NumChar field in
@@ -2288,16 +2288,14 @@ static double ChiArea(CHISTRUCT *ChiParams, double x) {
22882288
* @param Cluster cluster containing samples to be tested
22892289
* @param MaxIllegal max percentage of samples allowed to have
22902290
* 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.
22922292
*/
22932293
static bool
22942294
MultipleCharSamples(CLUSTERER* Clusterer,
22952295
CLUSTER* Cluster, float MaxIllegal)
22962296
#define ILLEGAL_CHAR 2
22972297
{
2298-
static BOOL8 *CharFlags = nullptr;
2299-
static int32_t NumFlags = 0;
2300-
int i;
2298+
static std::vector<uint8_t> CharFlags;
23012299
LIST SearchState;
23022300
SAMPLE *Sample;
23032301
int32_t CharID;
@@ -2309,24 +2307,22 @@ MultipleCharSamples(CLUSTERER* Clusterer,
23092307
NumCharInCluster = Cluster->SampleCount;
23102308
NumIllegalInCluster = 0;
23112309

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);
23162312
}
23172313

2318-
for (i = 0; i < NumFlags; i++)
2319-
CharFlags[i] = FALSE;
2314+
for (auto& CharFlag : CharFlags)
2315+
CharFlag = false;
23202316

23212317
// find each sample in the cluster and check if we have seen it before
23222318
InitSampleSearch(SearchState, Cluster);
23232319
while ((Sample = NextSample (&SearchState)) != nullptr) {
23242320
CharID = Sample->CharID;
2325-
if (CharFlags[CharID] == FALSE) {
2326-
CharFlags[CharID] = TRUE;
2321+
if (CharFlags[CharID] == false) {
2322+
CharFlags[CharID] = true;
23272323
}
23282324
else {
2329-
if (CharFlags[CharID] == TRUE) {
2325+
if (CharFlags[CharID] == true) {
23302326
NumIllegalInCluster++;
23312327
CharFlags[CharID] = ILLEGAL_CHAR;
23322328
}

src/classify/cluster.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ struct BUCKETS;
3030
Types
3131
----------------------------------------------------------------------*/
3232
typedef struct sample {
33-
unsigned Clustered:1; // TRUE if included in a higher cluster
34-
unsigned Prototype:1; // TRUE if cluster represented by a proto
33+
bool Clustered:1; // true if included in a higher cluster
34+
bool Prototype:1; // true if cluster represented by a proto
3535
unsigned SampleCount:30; // number of samples in this cluster
3636
struct sample *Left; // ptr to left sub-cluster
3737
struct sample *Right; // ptr to right sub-cluster
@@ -65,8 +65,8 @@ typedef union {
6565
} FLOATUNION;
6666

6767
typedef struct {
68-
unsigned Significant:1; // TRUE if prototype is significant
69-
unsigned Merged:1; // Merged after clustering so do not output
68+
bool Significant:1; // true if prototype is significant
69+
bool Merged:1; // Merged after clustering so do not output
7070
// but kept for display purposes. If it has no
7171
// samples then it was actually merged.
7272
// Otherwise it matched an already significant

src/training/commontraining.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -577,13 +577,13 @@ void MergeInsignificantProtos(LIST ProtoList, const char* label,
577577
best_match->Mean,
578578
best_match->Mean, Prototype->Mean);
579579
Prototype->NumSamples = 0;
580-
Prototype->Merged = 1;
580+
Prototype->Merged = true;
581581
} else if (best_match != nullptr) {
582582
if (debug)
583583
tprintf("Red proto at %g,%g matched a green one at %g,%g\n",
584584
Prototype->Mean[0], Prototype->Mean[1],
585585
best_match->Mean[0], best_match->Mean[1]);
586-
Prototype->Merged = 1;
586+
Prototype->Merged = true;
587587
}
588588
}
589589
// Mark significant those that now have enough samples.

0 commit comments

Comments
 (0)