Skip to content

Commit

Permalink
classify: Use bool and replace TRUE, FALSE
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Mar 31, 2019
1 parent 46fa59a commit cbb5e72
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 40 deletions.
64 changes: 30 additions & 34 deletions src/classify/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ SAMPLE* MakeSample(CLUSTERER * Clusterer, const float* Feature,
Sample = (SAMPLE *) Emalloc (sizeof (SAMPLE) +
(Clusterer->SampleSize -
1) * sizeof (float));
Sample->Clustered = FALSE;
Sample->Prototype = FALSE;
Sample->Clustered = false;
Sample->Prototype = false;
Sample->SampleCount = 1;
Sample->Left = nullptr;
Sample->Right = nullptr;
Expand Down Expand Up @@ -553,7 +553,7 @@ void FreePrototype(void *arg) { //PROTOTYPE *Prototype)

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

// deallocate the prototype statistics and then the prototype itself
free(Prototype->Distrib);
Expand Down Expand Up @@ -586,7 +586,7 @@ CLUSTER *NextSample(LIST *SearchState) {
return (nullptr);
Cluster = (CLUSTER *) first_node (*SearchState);
*SearchState = pop (*SearchState);
while (TRUE) {
for (;;) {
if (Cluster->Left == nullptr)
return (Cluster);
*SearchState = push (*SearchState, Cluster->Right);
Expand Down Expand Up @@ -790,15 +790,15 @@ static CLUSTER* MakeNewCluster(CLUSTERER* Clusterer,
// allocate the new cluster and initialize it
Cluster = (CLUSTER *) Emalloc(
sizeof(CLUSTER) + (Clusterer->SampleSize - 1) * sizeof(float));
Cluster->Clustered = FALSE;
Cluster->Prototype = FALSE;
Cluster->Clustered = false;
Cluster->Prototype = false;
Cluster->Left = TempCluster->Cluster;
Cluster->Right = TempCluster->Neighbor;
Cluster->CharID = -1;

// mark the old clusters as "clustered" and delete them from the kd-tree
Cluster->Left->Clustered = TRUE;
Cluster->Right->Clustered = TRUE;
Cluster->Left->Clustered = true;
Cluster->Right->Clustered = true;
KDDelete(Clusterer->KDTree, Cluster->Left->Mean, Cluster->Left);
KDDelete(Clusterer->KDTree, Cluster->Right->Mean, Cluster->Right);

Expand Down Expand Up @@ -1024,7 +1024,7 @@ static PROTOTYPE* MakeDegenerateProto( //this was MinSample
Proto = NewMixedProto (N, Cluster, Statistics);
break;
}
Proto->Significant = FALSE;
Proto->Significant = false;
}
return (Proto);
} // MakeDegenerateProto
Expand Down Expand Up @@ -1518,17 +1518,17 @@ static PROTOTYPE *NewSimpleProto(int16_t N, CLUSTER *Cluster) {
Proto->Mean[i] = Cluster->Mean[i];
Proto->Distrib = nullptr;

Proto->Significant = TRUE;
Proto->Merged = FALSE;
Proto->Significant = true;
Proto->Merged = false;
Proto->Style = spherical;
Proto->NumSamples = Cluster->SampleCount;
Proto->Cluster = Cluster;
Proto->Cluster->Prototype = TRUE;
Proto->Cluster->Prototype = true;
return (Proto);
} // NewSimpleProto

/**
* This routine returns TRUE if the specified covariance
* This routine returns true if the specified covariance
* matrix indicates that all N dimensions are independent of
* one another. One dimension is judged to be independent of
* another when the magnitude of the corresponding correlation
Expand All @@ -1543,7 +1543,7 @@ static PROTOTYPE *NewSimpleProto(int16_t N, CLUSTER *Cluster) {
* @param N number of dimensions
* @param CoVariance ptr to a covariance matrix
* @param Independence max off-diagonal correlation coefficient
* @return TRUE if dimensions are independent, FALSE otherwise
* @return true if dimensions are independent, false otherwise
*/
static bool
Independent(PARAM_DESC* ParamDesc,
Expand Down Expand Up @@ -1999,13 +1999,13 @@ static uint16_t UniformBucket(PARAM_DESC *ParamDesc,

/**
* This routine performs a chi-square goodness of fit test
* on the histogram data in the Buckets data structure. TRUE
* is returned if the histogram matches the probability
* on the histogram data in the Buckets data structure.
* true is returned if the histogram matches the probability
* distribution which was specified when the Buckets
* structure was originally created. Otherwise FALSE is
* structure was originally created. Otherwise false is
* returned.
* @param Buckets histogram data to perform chi-square test on
* @return TRUE if samples match distribution, FALSE otherwise
* @return true if samples match distribution, false otherwise
*/
static bool DistributionOK(BUCKETS* Buckets) {
float FrequencyDifference;
Expand Down Expand Up @@ -2140,7 +2140,7 @@ static void InitBuckets(BUCKETS *Buckets) {
*
* @param arg1 chi-squared struct being tested for a match
* @param arg2 chi-squared struct that is the search key
* @return TRUE if ChiStruct's Alpha matches SearchKey's Alpha
* @return true if ChiStruct's Alpha matches SearchKey's Alpha
*/
static int AlphaMatch(void *arg1, //CHISTRUCT *ChiStruct,
void *arg2) { //CHISTRUCT *SearchKey)
Expand Down Expand Up @@ -2271,8 +2271,8 @@ static double ChiArea(CHISTRUCT *ChiParams, double x) {
* This routine looks at all samples in the specified cluster.
* It computes a running estimate of the percentage of the
* characters which have more than 1 sample in the cluster.
* When this percentage exceeds MaxIllegal, TRUE is returned.
* Otherwise FALSE is returned. The CharID
* When this percentage exceeds MaxIllegal, true is returned.
* Otherwise false is returned. The CharID
* fields must contain integers which identify the training
* characters which were used to generate the sample. One
* integer is used for each sample. The NumChar field in
Expand All @@ -2288,16 +2288,14 @@ static double ChiArea(CHISTRUCT *ChiParams, double x) {
* @param Cluster cluster containing samples to be tested
* @param MaxIllegal max percentage of samples allowed to have
* more than 1 feature in the cluster
* @return TRUE if the cluster should be split, FALSE otherwise.
* @return true if the cluster should be split, false otherwise.
*/
static bool
MultipleCharSamples(CLUSTERER* Clusterer,
CLUSTER* Cluster, float MaxIllegal)
#define ILLEGAL_CHAR 2
{
static BOOL8 *CharFlags = nullptr;
static int32_t NumFlags = 0;
int i;
static std::vector<uint8_t> CharFlags;
LIST SearchState;
SAMPLE *Sample;
int32_t CharID;
Expand All @@ -2309,24 +2307,22 @@ MultipleCharSamples(CLUSTERER* Clusterer,
NumCharInCluster = Cluster->SampleCount;
NumIllegalInCluster = 0;

if (Clusterer->NumChar > NumFlags) {
free(CharFlags);
NumFlags = Clusterer->NumChar;
CharFlags = (BOOL8 *) Emalloc (NumFlags * sizeof (BOOL8));
if (Clusterer->NumChar > CharFlags.size()) {
CharFlags.resize(Clusterer->NumChar);
}

for (i = 0; i < NumFlags; i++)
CharFlags[i] = FALSE;
for (auto& CharFlag : CharFlags)
CharFlag = false;

// find each sample in the cluster and check if we have seen it before
InitSampleSearch(SearchState, Cluster);
while ((Sample = NextSample (&SearchState)) != nullptr) {
CharID = Sample->CharID;
if (CharFlags[CharID] == FALSE) {
CharFlags[CharID] = TRUE;
if (CharFlags[CharID] == false) {
CharFlags[CharID] = true;
}
else {
if (CharFlags[CharID] == TRUE) {
if (CharFlags[CharID] == true) {
NumIllegalInCluster++;
CharFlags[CharID] = ILLEGAL_CHAR;
}
Expand Down
8 changes: 4 additions & 4 deletions src/classify/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ struct BUCKETS;
Types
----------------------------------------------------------------------*/
typedef struct sample {
unsigned Clustered:1; // TRUE if included in a higher cluster
unsigned Prototype:1; // TRUE if cluster represented by a proto
bool Clustered:1; // true if included in a higher cluster
bool Prototype:1; // true if cluster represented by a proto
unsigned SampleCount:30; // number of samples in this cluster
struct sample *Left; // ptr to left sub-cluster
struct sample *Right; // ptr to right sub-cluster
Expand Down Expand Up @@ -65,8 +65,8 @@ typedef union {
} FLOATUNION;

typedef struct {
unsigned Significant:1; // TRUE if prototype is significant
unsigned Merged:1; // Merged after clustering so do not output
bool Significant:1; // true if prototype is significant
bool Merged:1; // Merged after clustering so do not output
// but kept for display purposes. If it has no
// samples then it was actually merged.
// Otherwise it matched an already significant
Expand Down
4 changes: 2 additions & 2 deletions src/training/commontraining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,13 +577,13 @@ void MergeInsignificantProtos(LIST ProtoList, const char* label,
best_match->Mean,
best_match->Mean, Prototype->Mean);
Prototype->NumSamples = 0;
Prototype->Merged = 1;
Prototype->Merged = true;
} else if (best_match != nullptr) {
if (debug)
tprintf("Red proto at %g,%g matched a green one at %g,%g\n",
Prototype->Mean[0], Prototype->Mean[1],
best_match->Mean[0], best_match->Mean[1]);
Prototype->Merged = 1;
Prototype->Merged = true;
}
}
// Mark significant those that now have enough samples.
Expand Down

0 comments on commit cbb5e72

Please sign in to comment.