Skip to content

Commit eb15a8b

Browse files
authored
[ML] Replace 0 with nullptr in model lib (#40)
1 parent 796bd9d commit eb15a8b

36 files changed

+100
-100
lines changed

include/core/CContainerPrinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class CORE_EXPORT CContainerPrinter : private CNonInstantiatable {
244244
//! Print a non associative element pointer to const for debug.
245245
template<typename T>
246246
static std::string printElement(const T* value) {
247-
if (value == 0) {
247+
if (value == nullptr) {
248248
return "\"null\"";
249249
}
250250
std::ostringstream result;

include/model/CHierarchicalResults.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class MODEL_EXPORT CHierarchicalResults {
273273

274274
//! Add a dummy result for a simple count detector.
275275
void addSimpleCountResult(SAnnotatedProbability& annotatedProbability,
276-
const CAnomalyDetectorModel* model = 0,
276+
const CAnomalyDetectorModel* model = nullptr,
277277
core_t::TTime bucketStartTime = 0);
278278

279279
//! Add a simple search result.
@@ -321,7 +321,7 @@ class MODEL_EXPORT CHierarchicalResults {
321321
const std::string& personFieldValue,
322322
const std::string& valueFieldName,
323323
SAnnotatedProbability& annotatedProbability,
324-
const CAnomalyDetectorModel* model = 0,
324+
const CAnomalyDetectorModel* model = nullptr,
325325
core_t::TTime bucketStartTime = 0);
326326

327327
//! Add the influencer called \p name.

include/model/CHierarchicalResultsLevelSet.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class CHierarchicalResultsLevelSet : public CHierarchicalResultsVisitor {
9090
const T* personElement(const std::string& partitionFieldName, const std::string& personFieldName) const {
9191
TWord word = ms_Dictionary.word(partitionFieldName, personFieldName);
9292
TWordTypePrVecCItr i = element(m_PersonSet, word);
93-
return (i != m_PersonSet.end() && i->first == word) ? &i->second : 0;
93+
return (i != m_PersonSet.end() && i->first == word) ? &i->second : nullptr;
9494
}
9595

9696
//! Get a leaf element.
@@ -102,7 +102,7 @@ class CHierarchicalResultsLevelSet : public CHierarchicalResultsVisitor {
102102
const std::string& valueFieldName) const {
103103
TWord word = ms_Dictionary.word(partitionFieldName, personFieldName, functionName, valueFieldName);
104104
TWordTypePrVecCItr i = element(m_LeafSet, word);
105-
return (i != m_LeafSet.end() && i->first == word) ? &i->second : 0;
105+
return (i != m_LeafSet.end() && i->first == word) ? &i->second : nullptr;
106106
}
107107

108108
//! Get the influencer bucket set.
@@ -241,7 +241,7 @@ class CHierarchicalResultsLevelSet : public CHierarchicalResultsVisitor {
241241
static const T* element(const TWordTypePrVec& set, const std::string& name) {
242242
TWord word = ms_Dictionary.word(name);
243243
TWordTypePrVecCItr i = element(set, word);
244-
return (i != set.end() && i->first == word) ? &i->second : 0;
244+
return (i != set.end() && i->first == word) ? &i->second : nullptr;
245245
}
246246

247247
//! Get the element corresponding to \p word if it exists

include/model/CIndividualModelDetail.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ CIndividualModel::featureData(model_t::EFeature feature,
5353
const std::vector<std::pair<model_t::EFeature, std::vector<std::pair<std::size_t, T>>>>& featureData) const {
5454
if (!this->bucketStatsAvailable(time)) {
5555
LOG_ERROR("No statistics at " << time << ", current bucket = " << this->printCurrentBucket());
56-
return 0;
56+
return nullptr;
5757
}
5858

5959
auto i = std::lower_bound(featureData.begin(), featureData.end(), feature, maths::COrderings::SFirstLess());
6060
if (i == featureData.end() || i->first != feature) {
6161
LOG_ERROR("No data for feature " << model_t::print(feature));
62-
return 0;
62+
return nullptr;
6363
}
6464

6565
auto j = std::lower_bound(i->second.begin(), i->second.end(), pid, maths::COrderings::SFirstLess());
66-
return (j != i->second.end() && j->first == pid) ? &j->second : 0;
66+
return (j != i->second.end() && j->first == pid) ? &j->second : nullptr;
6767
}
6868

6969
template<typename T, typename FILTER>

lib/model/CAnnotatedProbabilityBuilder.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ CAnnotatedProbabilityBuilder::CAnnotatedProbabilityBuilder(SAnnotatedProbability
2727
: m_Result(annotatedProbability),
2828
m_NumberAttributeProbabilities(1),
2929
m_NumberOfPeople(0),
30-
m_AttributeProbabilityPrior(0),
31-
m_PersonAttributeProbabilityPrior(0),
30+
m_AttributeProbabilityPrior(nullptr),
31+
m_PersonAttributeProbabilityPrior(nullptr),
3232
m_MinAttributeProbabilities(1),
3333
m_DistinctTotalAttributes(0),
3434
m_DistinctRareAttributes(0),
@@ -47,8 +47,8 @@ CAnnotatedProbabilityBuilder::CAnnotatedProbabilityBuilder(SAnnotatedProbability
4747
: m_Result(annotatedProbability),
4848
m_NumberAttributeProbabilities(numberAttributeProbabilities),
4949
m_NumberOfPeople(numberOfPeople),
50-
m_AttributeProbabilityPrior(0),
51-
m_PersonAttributeProbabilityPrior(0),
50+
m_AttributeProbabilityPrior(nullptr),
51+
m_PersonAttributeProbabilityPrior(nullptr),
5252
m_MinAttributeProbabilities(numberAttributeProbabilities),
5353
m_DistinctTotalAttributes(0),
5454
m_DistinctRareAttributes(0),

lib/model/CAnomalyDetector.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ CAnomalyDetector::CAnomalyDetector(int detectorIndex,
113113
m_ModelFactory(modelFactory),
114114
m_Model(makeModel(modelFactory, m_DataGatherer)),
115115
m_IsForPersistence(false) {
116-
if (m_DataGatherer == 0) {
116+
if (m_DataGatherer == nullptr) {
117117
LOG_ABORT("Failed to construct data gatherer for detector: " << this->description());
118118
}
119-
if (m_Model == 0) {
119+
if (m_Model == nullptr) {
120120
LOG_ABORT("Failed to construct model for detector: " << this->description());
121121
}
122122
limits.resourceMonitor().registerComponent(*this);

lib/model/CAnomalyDetectorModel.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,11 @@ double CAnomalyDetectorModel::learnRate(model_t::EFeature feature) const {
406406
const CInfluenceCalculator* CAnomalyDetectorModel::influenceCalculator(model_t::EFeature feature, std::size_t iid) const {
407407
if (iid >= m_InfluenceCalculators.size()) {
408408
LOG_ERROR("Influencer identifier " << iid << " out of range");
409-
return 0;
409+
return nullptr;
410410
}
411411
const TFeatureInfluenceCalculatorCPtrPrVec& calculators{m_InfluenceCalculators[iid]};
412412
auto result = std::lower_bound(calculators.begin(), calculators.end(), feature, maths::COrderings::SFirstLess());
413-
return result != calculators.end() && result->first == feature ? result->second.get() : 0;
413+
return result != calculators.end() && result->first == feature ? result->second.get() : nullptr;
414414
}
415415

416416
const CAnomalyDetectorModel::TDoubleVec& CAnomalyDetectorModel::personBucketCounts() const {

lib/model/CCountingModel.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ std::string CCountingModel::printCurrentBucket() const {
388388
}
389389

390390
CMemoryUsageEstimator* CCountingModel::memoryUsageEstimator() const {
391-
return 0;
391+
return nullptr;
392392
}
393393
}
394394
}

lib/model/CCountingModelFactory.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ CAnomalyDetectorModel* CCountingModelFactory::makeModel(const SModelInitializati
4848
TDataGathererPtr dataGatherer = initData.s_DataGatherer;
4949
if (!dataGatherer) {
5050
LOG_ERROR("NULL data gatherer");
51-
return 0;
51+
return nullptr;
5252
}
5353
return new CCountingModel(this->modelParams(), dataGatherer);
5454
}
@@ -58,7 +58,7 @@ CAnomalyDetectorModel* CCountingModelFactory::makeModel(const SModelInitializati
5858
TDataGathererPtr dataGatherer = initData.s_DataGatherer;
5959
if (!dataGatherer) {
6060
LOG_ERROR("NULL data gatherer");
61-
return 0;
61+
return nullptr;
6262
}
6363
return new CCountingModel(this->modelParams(), dataGatherer, traverser);
6464
}

lib/model/CDataGatherer.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ bool CDataGatherer::determineMetricCategory(TMetricCategoryVec& fieldMetricCateg
742742
}
743743

744744
bool CDataGatherer::extractCountFromField(const std::string& fieldName, const std::string* fieldValue, std::size_t& count) const {
745-
if (fieldValue == 0) {
745+
if (fieldValue == nullptr) {
746746
// Treat not present as explicit null
747747
count = EXPLICIT_NULL_SUMMARY_COUNT;
748748
return true;
@@ -882,15 +882,15 @@ bool CDataGatherer::restoreBucketGatherer(const std::string& summaryCountFieldNa
882882
CEventRateBucketGatherer* gatherer = new CEventRateBucketGatherer(
883883
*this, summaryCountFieldName, personFieldName, attributeFieldName, valueFieldName, influenceFieldNames, traverser);
884884

885-
if (gatherer == 0) {
885+
if (gatherer == nullptr) {
886886
LOG_ERROR("Failed to create gatherer");
887887
return false;
888888
}
889889
m_Gatherers.push_back(gatherer);
890890
} else if (name == CBucketGatherer::METRIC_BUCKET_GATHERER_TAG) {
891891
CMetricBucketGatherer* gatherer = new CMetricBucketGatherer(
892892
*this, summaryCountFieldName, personFieldName, attributeFieldName, valueFieldName, influenceFieldNames, traverser);
893-
if (gatherer == 0) {
893+
if (gatherer == nullptr) {
894894
LOG_ERROR("Failed to create gatherer");
895895
return false;
896896
}

0 commit comments

Comments
 (0)