diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-06-26 10:53:34 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-06-26 10:53:34 +0000 |
commit | 14e2d148bb82cf15ab4fac1eabbca85cfff49d7b (patch) | |
tree | 2fdb43746fdfc5d8fa92b4f775ee23d11e994e3c /vdslib | |
parent | 753bd5781cf57cb50e430aea8cffee995d45c314 (diff) |
Modernize to c++11 style loops.
Diffstat (limited to 'vdslib')
-rw-r--r-- | vdslib/src/vespa/vdslib/distribution/distribution.cpp | 14 | ||||
-rw-r--r-- | vdslib/src/vespa/vdslib/distribution/group.cpp | 36 | ||||
-rw-r--r-- | vdslib/src/vespa/vdslib/distribution/group.h | 7 |
3 files changed, 22 insertions, 35 deletions
diff --git a/vdslib/src/vespa/vdslib/distribution/distribution.cpp b/vdslib/src/vespa/vdslib/distribution/distribution.cpp index 52d523071e6..00794242450 100644 --- a/vdslib/src/vespa/vdslib/distribution/distribution.cpp +++ b/vdslib/src/vespa/vdslib/distribution/distribution.cpp @@ -669,20 +669,18 @@ Distribution::splitNodesIntoLeafGroups(IndexList nodeList) const { std::vector<IndexList> result; std::map<uint16_t, IndexList> nodes; - for (uint32_t i=0, n=nodeList.size(); i<n; ++i) { - const Group* group(_nodeGraph->getGroupForNode(nodeList[i])); + for (uint16_t node : nodeList) { + const Group* group(_nodeGraph->getGroupForNode(node)); if (group == nullptr) { LOGBP(warning, "Node %u is not assigned to a group. " - "Should not happen?", nodeList[i]); + "Should not happen?", node); } else { assert(group->isLeafGroup()); - nodes[group->getIndex()].push_back(nodeList[i]); + nodes[group->getIndex()].push_back(node); } } - for (std::map<uint16_t, IndexList>::const_iterator it(nodes.begin()); - it != nodes.end(); ++it) - { - result.push_back(it->second); + for (const auto & node : nodes) { + result.push_back(node.second); } return result; } diff --git a/vdslib/src/vespa/vdslib/distribution/group.cpp b/vdslib/src/vespa/vdslib/distribution/group.cpp index 91e27715911..308b9c77d94 100644 --- a/vdslib/src/vespa/vdslib/distribution/group.cpp +++ b/vdslib/src/vespa/vdslib/distribution/group.cpp @@ -39,11 +39,9 @@ Group::Group(uint16_t index, vespalib::stringref name, Group::~Group() { - for (std::map<uint16_t, Group*>::iterator it = _subGroups.begin(); - it != _subGroups.end(); ++it) - { - delete it->second; - it->second = 0; + for (auto & subGroup : _subGroups) { + delete subGroup.second; + subGroup.second = 0; } } @@ -75,8 +73,8 @@ Group::print(std::ostream& out, bool verbose, } if (_distributionSpec.size() == 0) { out << ", nodes( "; - for (uint32_t i = 0; i < _nodes.size(); i++) { - out << _nodes[i] << " "; + for (auto node : _nodes) { + out << node << " "; } out << ")"; } @@ -88,10 +86,9 @@ Group::print(std::ostream& out, bool verbose, out << ") {"; if (_subGroups.size()>0) { - for (std::map<uint16_t, Group*>::const_iterator it = _subGroups.begin(); - it != _subGroups.end(); ++it) { + for (const auto & subGroup : _subGroups) { out << "\n" << indent << " "; - it->second->print(out, verbose, indent + " "); + subGroup.second->print(out, verbose, indent + " "); } } @@ -110,8 +107,7 @@ Group::addSubGroup(Group::UP group) throw vespalib::IllegalArgumentException( "Cannot add null group.", VESPA_STRLOC); } - std::map<uint16_t, Group*>::const_iterator it( - _subGroups.find(group->getIndex())); + auto it =_subGroups.find(group->getIndex()); if (it != _subGroups.end()) { throw vespalib::IllegalArgumentException( "Another subgroup with same index is already added.", @@ -154,26 +150,22 @@ Group::getGroupForNode(uint16_t nodeIdx) const } } - for (std::map<uint16_t, Group*>::const_iterator iter = _subGroups.begin(); - iter != _subGroups.end(); - ++iter) { - const Group* g = iter->second->getGroupForNode(nodeIdx); - if (g != NULL) { + for (const auto & subGroup : _subGroups) { + const Group* g = subGroup.second->getGroupForNode(nodeIdx); + if (g != nullptr) { return g; } } - return NULL; + return nullptr; } void Group::calculateDistributionHashValues(uint32_t parentHash) { _distributionHash = parentHash ^ (1664525L * _index + 1013904223L); - for (std::map<uint16_t, Group*>::iterator it = _subGroups.begin(); - it != _subGroups.end(); ++it) - { - it->second->calculateDistributionHashValues(_distributionHash); + for (const auto & subGroup : _subGroups) { + subGroup.second->calculateDistributionHashValues(_distributionHash); } } diff --git a/vdslib/src/vespa/vdslib/distribution/group.h b/vdslib/src/vespa/vdslib/distribution/group.h index 238a56d0295..d6af005130d 100644 --- a/vdslib/src/vespa/vdslib/distribution/group.h +++ b/vdslib/src/vespa/vdslib/distribution/group.h @@ -19,8 +19,7 @@ namespace vespalib { class asciistream; } -namespace storage { -namespace lib { +namespace storage::lib { class IdealGroup; class SystemState; @@ -101,6 +100,4 @@ public: vespalib::string getDistributionConfigHash() const; }; -} // lib -} // storage - +} |