<commit_before>/*
 *            Copyright 2009-2018 The VOTCA Development Team
 *                       (http://www.votca.org)
 *
 *      Licensed under the Apache License, Version 2.0 (the "License")
 *
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *              http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <algorithm>
#include <cassert>
#include <string>
#include <votca/tools/graph.h>

using namespace std;

namespace votca {
namespace tools {

class GraphNode;

bool Graph::operator!=(const Graph& g) const { return id_.compare(g.id_); }

bool Graph::operator==(const Graph& g) const { return !(*(this) != g); }

Graph::Graph(const Graph& g) {
  this->edge_container_ = g.edge_container_;
  for (auto pr : g.nodes_) {
    this->nodes_[pr.first] = pr.second;
  }
  this->id_ = g.id_;
}

Graph& Graph::operator=(const Graph& g) {
  this->edge_container_ = g.edge_container_;
  for (auto pr : g.nodes_) {
    this->nodes_[pr.first] = pr.second;
  }
  this->id_ = g.id_;
  return *this;
}

Graph& Graph::operator=(Graph&& g) {
  this->edge_container_ = move(g.edge_container_);
  this->nodes_ = move(g.nodes_);
  this->id_ = move(g.id_);
  return *this;
}

vector<pair<int, GraphNode>> Graph::getIsolatedNodes(void) {
  vector<pair<int, GraphNode>> iso_nodes;
  for (auto node : nodes_) {
    if (edge_container_.vertexExist(node.first)) {
      if (edge_container_.getDegree(node.first) == 0) {
        pair<int, GraphNode> pr(node.first, node.second);
        iso_nodes.push_back(pr);
      }
    } else {
      pair<int, GraphNode> pr(node.first, node.second);
      iso_nodes.push_back(pr);
    }
  }
  return iso_nodes;
}

vector<int> Graph::getVerticesMissingNodes(void) {
  vector<int> missing;
  auto vertices = edge_container_.getVertices();
  for (auto vertex : vertices) {
    if (nodes_.count(vertex) == 0) {
      missing.push_back(vertex);
    }
  }
  return missing;
}

vector<pair<int,GraphNode>> Graph::getNeighNodes(int vert){
  auto neigh_vertices = edge_container_.getNeighVertices(vert);
  vector<pair<int,GraphNode>> neigh_vertices_pr;
  for(auto neigh_vert : neigh_vertices){
    auto node_pr = pair<int,GraphNode>(neigh_vert,nodes_[neigh_vert]);
    neigh_vertices_pr.push_back(node_pr);
  }
  return neigh_vertices_pr;
}

void Graph::setNode(int vert, GraphNode gn){
  if(nodes_.count(vert)){
    nodes_[vert] = gn;
  } else {
    string errMsg = "Vertex does not exist within graph cannot, reset node";
    throw runtime_error(errMsg);
  }
  calcId_();
}

void Graph::setNode(std::pair<int, GraphNode> p_gn) {
  setNode(p_gn.first, p_gn.second);
}

GraphNode Graph::getNode(int vert) { 
  assert(nodes_.count(vert));
  return nodes_[vert]; 
}

vector<pair<int, GraphNode>> Graph::getNodes(void) {
  vector<pair<int, GraphNode>> vec_nodes;
  for (auto pr_node : nodes_) {
    vec_nodes.push_back(pr_node);
  }
  return vec_nodes;
}

vector<int> Graph::getJunctions() const{
  vector<int> junctions;
  int max_degree = edge_container_.getMaxDegree();
  for(auto degree=3; degree<=max_degree;++degree){
    auto vertices = edge_container_.getVerticesDegree(degree);
    junctions.insert(junctions.end(),vertices.begin(),vertices.end());
  }
  return junctions;
}

void Graph::calcId_() {
  auto nodes = getNodes();
  sort(nodes.begin(), nodes.end(), cmpVertNodePair);
  string struct_Id_temp = "";
  for (auto nd_pr : nodes) {
    struct_Id_temp.append(nd_pr.second.getStringId());
  }
  id_ = struct_Id_temp;
  return;
}

ostream& operator<<(ostream& os, const Graph g) {
  os << "Graph" << endl;
  for (auto p_gn : g.nodes_) {
    os << "Node " << p_gn.first << endl;
    os << p_gn.second << endl;
  }
  return os;
}

bool cmpVertNodePair(pair<int, GraphNode> gn1_pr, pair<int, GraphNode> gn2_pr) {
  string str1_Id = gn1_pr.second.getStringId();
  return str1_Id.compare(gn2_pr.second.getStringId()) < 0;
}
}
}
<commit_msg>1. Made variable names more explicit in graph.cc 2. Removed auto, unless clear what type is, in graph.cc 3. Applied clang style formatting to graph.cc<commit_after>/*
 *            Copyright 2009-2018 The VOTCA Development Team
 *                       (http://www.votca.org)
 *
 *      Licensed under the Apache License, Version 2.0 (the "License")
 *
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *              http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <algorithm>
#include <cassert>
#include <string>
#include <votca/tools/graph.h>

using namespace std;

namespace votca {
namespace tools {

class GraphNode;

bool Graph::operator!=(const Graph& graph) const {
  return id_.compare(graph.id_);
}

bool Graph::operator==(const Graph& graph) const { return !(*(this) != graph); }

Graph::Graph(const Graph& graph) {
  this->edge_container_ = graph.edge_container_;
  for (const pair<int, GraphNode>& id_and_node : graph.nodes_) {
    this->nodes_[id_and_node.first] = id_and_node.second;
  }
  this->id_ = graph.id_;
}

Graph& Graph::operator=(const Graph& graph) {
  this->edge_container_ = graph.edge_container_;
  for (const pair<int, GraphNode>& id_and_node : graph.nodes_) {
    this->nodes_[id_and_node.first] = id_and_node.second;
  }
  this->id_ = graph.id_;
  return *this;
}

Graph& Graph::operator=(Graph&& graph) {
  this->edge_container_ = move(graph.edge_container_);
  this->nodes_ = move(graph.nodes_);
  this->id_ = move(graph.id_);
  return *this;
}

vector<pair<int, GraphNode>> Graph::getIsolatedNodes(void) {
  vector<pair<int, GraphNode>> isolated_nodes;
  for (const pair<int, GraphNode>& id_and_node : nodes_) {
    if (edge_container_.vertexExist(id_and_node.first)) {
      if (edge_container_.getDegree(id_and_node.first) == 0) {
        pair<int, GraphNode> id_and_node_copy(id_and_node.first,
                                              id_and_node.second);
        isolated_nodes.push_back(id_and_node_copy);
      }
    } else {
      pair<int, GraphNode> id_and_node_copy(node.first, node.second);
      isolated_nodes.push_back(id_and_node_copy);
    }
  }
  return isolated_nodes;
}

vector<int> Graph::getVerticesMissingNodes(void) {
  vector<int> missing;
  vector<int> vertices = edge_container_.getVertices();
  for (int& vertex : vertices) {
    if (nodes_.count(vertex) == 0) {
      missing.push_back(vertex);
    }
  }
  return missing;
}

vector<pair<int, GraphNode>> Graph::getNeighNodes(int vertex) {
  vector<int> neigh_vertices = edge_container_.getNeighVertices(vertex);
  vector<pair<int, GraphNode>> neigh_ids_and_nodes;
  for (int& neigh_vert : neigh_vertices) {
    auto id_and_node = pair<int, GraphNode>(neigh_vert, nodes_[neigh_vert]);
    neigh_ids_and_nodes.push_back(id_and_node);
  }
  return neigh_ids_and_nodes;
}

void Graph::setNode(int vertex, GraphNode graph_node) {
  if (nodes_.count(vertex)) {
    nodes_[vertex] = graph_node;
  } else {
    string errMsg = "Vertex does not exist within graph cannot, reset node";
    throw runtime_error(errMsg);
  }
  calcId_();
}

void Graph::setNode(std::pair<int, GraphNode> id_and_node) {
  setNode(id_and_node.first, id_and_node.second);
}

GraphNode Graph::getNode(int vertex) {
  assert(nodes_.count(vertex));
  return nodes_[vertex];
}

vector<pair<int, GraphNode>> Graph::getNodes(void) {
  vector<pair<int, GraphNode>> vec_nodes;
  for (const pair<int, GraphNode>& id_and_node : nodes_) {
    vec_nodes.push_back(id_and_node);
  }
  return vec_nodes;
}

vector<int> Graph::getJunctions() const {
  vector<int> junctions;
  int max_degree = edge_container_.getMaxDegree();
  for (int degree = 3; degree <= max_degree; ++degree) {
    vector<int> vertices = edge_container_.getVerticesDegree(degree);
    junctions.insert(junctions.end(), vertices.begin(), vertices.end());
  }
  return junctions;
}

void Graph::calcId_() {
  auto nodes = getNodes();
  sort(nodes.begin(), nodes.end(), cmpVertNodePair);
  string struct_Id_temp = "";
  for (const pair<int, GraphNode>& id_and_node : nodes) {
    struct_Id_temp.append(id_and_node.second.getStringId());
  }
  id_ = struct_Id_temp;
  return;
}

ostream& operator<<(ostream& os, const Graph graph) {
  os << "Graph" << endl;
  for (const pair<int, GraphNode>& id_and_node : g.nodes_) {
    os << "Node " << id_and_node.first << endl;
    os << id_and_node.second << endl;
  }
  return os;
}

bool cmpVertNodePair(pair<int, GraphNode>& id_and_node1,
                     pair<int, GraphNode>& id_and_node2) {
  string str1_Id = id_and_node1.second.getStringId();
  return str1_Id.compare(id_and_node2.second.getStringId()) < 0;
}
}  // namespace tools
}  // namespace votca

{'fraction_non_alphanumeric': 0.13298957997636696, 'fraction_numerical': 0.005048877430443657, 'mean_word_length': 3.994635193133047, 'pattern_counts': {'":': 0, '<': 100, '<?xml version=': 0, '>': 82, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3910556', 'n_tokens_mistral': 3193, 'n_tokens_neox': 3144, 'n_words': 730}