<commit_before>/*
 * variable_store.cpp
 *
 *  Created on: Apr 22, 2016
 */

#include "mcc/tac/variable_store.h"

#include <cassert>

#include "mcc/tac/variable.h"

namespace mcc {
  namespace tac {

    VariableStore::const_reference VariableStore::operator[](
        VariableStore::size_type pos) const {

      auto it = this->variableTable.at(pos);

      return *it;
    }

    VariableStore::size_type VariableStore::size() const {
      return this->variableTable.size();
    }

    void VariableStore::addVariable(
        VariableStore::VariableNode const& variable) {
      auto it = this->insertVariable(variable);

      std::vector<VariableStore::VariableNodeSet::iterator> varVector;
      varVector.push_back(it);

      this->renameMap.insert(std::make_pair(variable, varVector));
    }

    bool VariableStore::removeVariable(
        VariableStore::VariableNode const& variable) {
      auto var = renameMap.find(variable);

      if (var != renameMap.end()) {
        for (auto const& v : var->second) {
          for (auto it = this->variableTable.begin();
              it != this->variableTable.end(); ++it) {
            if (*it == v) {
              this->variableTable.erase(it);
            }
          }
        }

        this->renameMap.erase(var->first);

        return true;
      }

      return false;
    }

    VariableStore::VariableNode
    const& VariableStore::renameVariable(<commit_msg>remove variable from store when whariable is removed<commit_after>/*
 * variable_store.cpp
 *
 *  Created on: Apr 22, 2016
 */

#include "mcc/tac/variable_store.h"

#include <cassert>

#include "mcc/tac/variable.h"

namespace mcc {
  namespace tac {

    VariableStore::const_reference VariableStore::operator[](
        VariableStore::size_type pos) const {

      auto it = this->variableTable.at(pos);

      return *it;
    }

    VariableStore::size_type VariableStore::size() const {
      return this->variableTable.size();
    }

    void VariableStore::addVariable(
        VariableStore::VariableNode const& variable) {
      auto it = this->insertVariable(variable);

      std::vector<VariableStore::VariableNodeSet::iterator> varVector;
      varVector.push_back(it);

      this->renameMap.insert(std::make_pair(variable, varVector));
    }

    bool VariableStore::removeVariable(
        VariableStore::VariableNode const& variable) {
      auto var = renameMap.find(variable);

      if (var != renameMap.end()) {
        for (auto const& v : var->second) {
          for (auto it = this->variableTable.begin();
              it != this->variableTable.end(); ++it) {
            if (*it == v) {
              this->variableTable.erase(it);
              this->store.erase(v);
            }
          }
        }

        this->renameMap.erase(var->first);

        return true;
      }

      return false;
    }

    VariableStore::VariableNode
    const& VariableStore::renameVariable(
{'fraction_non_alphanumeric': 0.1281963859529492, 'fraction_numerical': 0.004091374019774974, 'mean_word_length': 2.591187270501836, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1338656', 'n_tokens_mistral': 898, 'n_tokens_neox': 840, 'n_words': 167}