<commit_before>#include "ledger.h"
#include "valexpr.h"
#include "datetime.h"
#include "acconf.h"

#include <fstream>

namespace ledger {

const std::string version = PACKAGE_VERSION;

bool transaction_t::valid() const
{
  if (! entry)
    return false;

  bool found = false;
  for (transactions_list::const_iterator i = entry->transactions.begin();
       i != entry->transactions.end();
       i++)
    if (*i == this) {
      found = true;
      break;
    }
  if (! found)
    return false;

  if (! account)
    return false;

  found = false;
  for (transactions_list::const_iterator i = account->transactions.begin();
       i != account->transactions.end();
       i++)
    if (*i == this) {
      found = true;
      break;
    }
  if (! found)
    return false;

  if (! amount.valid())
    return false;

  if (cost && ! cost->valid())
    return false;

  if (flags & ~0x000f)
    return false;

  return true;
}

void entry_t::add_transaction(transaction_t * xact)
{
  xact->entry = this;
  transactions.push_back(xact);
  xact->account->add_transaction(xact);
}

bool entry_t::remove_transaction(transaction_t * xact)
{
  bool found = false;
  transactions_list::iterator i;
  for (i = transactions.begin(); i != transactions.end(); i++)
    if (*i == xact) {
      found = true;
      break;
    }
  if (! found)
    return false;

  transactions.erase(i);

  for (i = xact->account->transactions.begin();
       i != xact->account->transactions.end();
       i++)
    if (*i == xact) {
      xact->account->transactions.erase(i);
      return true;
    }

  return false;
}

bool entry_t::valid() const
{
  if (! date || date == -1)
    return false;

  if (state != UNCLEARED && state != CLEARED && state != PENDING)
    return false;

  for (transactions_list::const_iterator i = transactions.begin();
       i != transactions.end();
       i++)
    if ((*i)->entry != this || ! (*i)->valid())
      return false;

  return true;
}

account_t::~account_t()
{
  DEBUG_PRINT("ledger.memory.ctors", "dtor account_t");
  //assert(! data);

  for (accounts_map::iterator i = accounts.begin();
       i != accounts.end();
       i++)
    delete (*i).second;
}

account_t * account_t::find_account(const std::string& name,<commit_msg>modified entry_t::add_transaction and remove_transaction, since now using lists<commit_after>#include "ledger.h"
#include "valexpr.h"
#include "datetime.h"
#include "acconf.h"

#include <fstream>

namespace ledger {

const std::string version = PACKAGE_VERSION;

bool transaction_t::valid() const
{
  if (! entry)
    return false;

  bool found = false;
  for (transactions_list::const_iterator i = entry->transactions.begin();
       i != entry->transactions.end();
       i++)
    if (*i == this) {
      found = true;
      break;
    }
  if (! found)
    return false;

  if (! account)
    return false;

  found = false;
  for (transactions_list::const_iterator i = account->transactions.begin();
       i != account->transactions.end();
       i++)
    if (*i == this) {
      found = true;
      break;
    }
  if (! found)
    return false;

  if (! amount.valid())
    return false;

  if (cost && ! cost->valid())
    return false;

  if (flags & ~0x000f)
    return false;

  return true;
}

void entry_t::add_transaction(transaction_t * xact)
{
  xact->entry = this;
  transactions.push_back(xact);
  xact->account->add_transaction(xact);
}

bool entry_t::remove_transaction(transaction_t * xact)
{
  transactions.remove(xact);
  xact->account->transactions.remove(xact);
  return true;
}

bool entry_t::valid() const
{
  if (! date || date == -1)
    return false;

  if (state != UNCLEARED && state != CLEARED && state != PENDING)
    return false;

  for (transactions_list::const_iterator i = transactions.begin();
       i != transactions.end();
       i++)
    if ((*i)->entry != this || ! (*i)->valid())
      return false;

  return true;
}

account_t::~account_t()
{
  DEBUG_PRINT("ledger.memory.ctors", "dtor account_t");
  //assert(! data);

  for (accounts_map::iterator i = accounts.begin();
       i != accounts.end();
       i++)
    delete (*i).second;
}

account_t * account_t::find_account(const std::string& name,
{'fraction_non_alphanumeric': 0.15887404580152673, 'fraction_numerical': 0.002385496183206107, 'mean_word_length': 3.070873786407767, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '6216562', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1399, 'n_words': 334}