Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Lists with Vectors #970

Merged
merged 11 commits into from
Mar 10, 2022
Merged

Replace Lists with Vectors #970

merged 11 commits into from
Mar 10, 2022

Conversation

IVlaD17
Copy link
Contributor

@IVlaD17 IVlaD17 commented Feb 10, 2022

Closes #619

Pretty much what's being said in the title. Replacing std::lists with std::vectors where possible.

Changed the following areas:

  • data1dstore.h
  • data2dstore.h
  • data3dstore.h
  • combopopulator.h
  • tablewidgetupdater.h
  • treewidgetupdater.h

@IVlaD17 IVlaD17 force-pushed the 619-replace-lists-with-vectors branch from 12b6612 to 95abce8 Compare February 10, 2022 15:49
@IVlaD17 IVlaD17 requested review from rprospero and trisyoungs March 7, 2022 15:44
Copy link
Member

@trisyoungs trisyoungs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Some comments over a few of the loops which should be investigated.

Comment on lines 31 to 32
return std::find_if(data_.begin()->get(), data_.end()->get(), [&name](auto &data) { return data.first.tag() == name; }) !=
data_.end()->get();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right and wouldn't traverse the vector:

Suggested change
return std::find_if(data_.begin()->get(), data_.end()->get(), [&name](auto &data) { return data.first.tag() == name; }) !=
data_.end()->get();
return std::find_if(data_.begin(), data_.end(), [&name](auto &data) { return data->first.tag() == name; }) !=
data_.end();

Comment on lines 38 to 39
auto it = std::find_if(data_.begin()->get(), data_.end()->get(), [&name](auto &data) { return data.first.tag() == name; });
if (it == data_.end()->get())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here:

Suggested change
auto it = std::find_if(data_.begin()->get(), data_.end()->get(), [&name](auto &data) { return data.first.tag() == name; });
if (it == data_.end()->get())
auto it = std::find_if(data_.begin(), data_.end(), [&name](auto &data) { return data->first.tag() == name; });
if (it == data_.end())

Comment on lines 31 to 32
return std::find_if(data_.begin()->get(), data_.end()->get(), [&name](auto &data) { return data.first.tag() == name; }) !=
data_.end()->get();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return std::find_if(data_.begin()->get(), data_.end()->get(), [&name](auto &data) { return data.first.tag() == name; }) !=
data_.end()->get();
auto it = std::find_if(data_.begin(), data_.end(), [&name](auto &data) { return data->first.tag() == name; });
if (it == data_.end())

Comment on lines 38 to 39
auto it = std::find_if(data_.begin()->get(), data_.end()->get(), [&name](auto &data) { return data.first.tag() == name; });
if (it == data_.end()->get())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto it = std::find_if(data_.begin()->get(), data_.end()->get(), [&name](auto &data) { return data.first.tag() == name; });
if (it == data_.end()->get())
auto it = std::find_if(data_.begin(), data_.end(), [&name](auto &data) { return data->first.tag() == name; });
if (it == data_.end())

Comment on lines 31 to 32
return std::find_if(data_.begin()->get(), data_.end()->get(), [&name](auto &data) { return data.first.tag() == name; }) !=
data_.end()->get();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return std::find_if(data_.begin()->get(), data_.end()->get(), [&name](auto &data) { return data.first.tag() == name; }) !=
data_.end()->get();
auto it = std::find_if(data_.begin(), data_.end(), [&name](auto &data) { return data->first.tag() == name; });
if (it == data_.end())

@@ -40,8 +40,9 @@ bool Data3DStoreKeyword::deserialise(LineParser &parser, int startArg, const Cor
// Serialise data to specified LineParser
bool Data3DStoreKeyword::serialise(LineParser &parser, std::string_view keywordName, std::string_view prefix) const
{
for (const auto &[data, format] : data_.data())
for (const auto sharedDataPointer : data_.data())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (const auto sharedDataPointer : data_.data())
for (const auto &sharedDataPointer : data_.data())

@@ -22,8 +22,9 @@ bool DataTestModule::process(Dissolve &dissolve, ProcessPool &procPool)
Messenger::print("\n");

// Loop over reference one-dimensional data supplied
for (auto &[referenceData, format] : test1DData_.data())
for (auto sharedDataPointer : test1DData_.data())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto sharedDataPointer : test1DData_.data())
for (auto &sharedDataPointer : test1DData_.data())

@@ -63,8 +64,9 @@ bool DataTestModule::process(Dissolve &dissolve, ProcessPool &procPool)
}

// Loop over reference two-dimensional data supplied
for (auto &[referenceData, format] : test2DData_.data())
for (auto sharedDataPointer : test2DData_.data())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto sharedDataPointer : test2DData_.data())
for (auto &sharedDataPointer : test2DData_.data())

@@ -645,8 +645,9 @@ bool RDFModule::testReferencePartials(const Data1DStore &testData, double testTh
LineParser parser;

// Loop over supplied test data and see if we can locate it amongst our PartialSets
for (auto &[data, format] : testData.data())
for (auto sharedDataPointer : testData.data())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto sharedDataPointer : testData.data())
for (auto &sharedDataPointer : testData.data())

@@ -675,8 +676,9 @@ bool RDFModule::testReferencePartials(const Data1DStore &testData, double testTh
LineParser parser;

// Loop over supplied test data and see if we can locate it amongst our PartialSets
for (auto &[data, format] : testData.data())
for (auto sharedDataPointer : testData.data())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto sharedDataPointer : testData.data())
for (auto &sharedDataPointer : testData.data())

@rprospero
Copy link
Contributor

I agree with Tristan's comments, but otherwise approve.

@IVlaD17 IVlaD17 merged commit e0de92d into develop Mar 10, 2022
@IVlaD17 IVlaD17 deleted the 619-replace-lists-with-vectors branch March 10, 2022 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid std::list if possible
3 participants