<commit_before>/**
 * @file
 */
#include "libbirch/Memo.hpp"

#include "libbirch/SwapClone.hpp"
#include "libbirch/SwapContext.hpp"

bi::Memo::Memo() :
    isForked(false) {
  //
}

bi::Memo::Memo(Memo* parent, const bool isForwarding) :
    cloneParent(isForwarding ? nullptr : parent),
    forwardParent(isForwarding ? parent : nullptr),
    isForked(false) {
  //
}

bi::Memo::~Memo() {
  //
}

bool bi::Memo::hasAncestor(Memo* memo) const {
  SharedPtr<Memo> parent = getParent();
  return parent && (parent == memo || parent->hasAncestor(memo));
}

bi::Memo* bi::Memo::fork() {
  #if USE_LAZY_DEEP_CLONE
  isForked = true;
  #endif
  return create(this, false);
}

void bi::Memo::clean() {
  auto parent = getParent();
  if (parent) {
    parent->clean();
  }
  clones.clean();
}

bi::Memo* bi::Memo::forwardGet() {
  #if USE_LAZY_DEEP_CLONE
  ///@todo make this thread safe
  if (forwardChild) {
    return forwardChild->forwardGet();
  } else if (isForked) {
    forwardChild = create(this, true);
    clean();
    return forwardChild.get();
  } else {
    return this;
  }
  #else
  return this;
  #endif
}

bi::Memo* bi::Memo::forwardPull() {
  #if USE_LAZY_DEEP_CLONE
  return forwardChild ? forwardChild->forwardPull() : this;<commit_msg>Made new sweep clean shallow rather than recursing all the way back to root memo. Won't generalise well, but sufficient for current use cases.<commit_after>/**
 * @file
 */
#include "libbirch/Memo.hpp"

#include "libbirch/SwapClone.hpp"
#include "libbirch/SwapContext.hpp"

bi::Memo::Memo() :
    isForked(false) {
  //
}

bi::Memo::Memo(Memo* parent, const bool isForwarding) :
    cloneParent(isForwarding ? nullptr : parent),
    forwardParent(isForwarding ? parent : nullptr),
    isForked(false) {
  //
}

bi::Memo::~Memo() {
  //
}

bool bi::Memo::hasAncestor(Memo* memo) const {
  SharedPtr<Memo> parent = getParent();
  return parent && (parent == memo || parent->hasAncestor(memo));
}

bi::Memo* bi::Memo::fork() {
  #if USE_LAZY_DEEP_CLONE
  isForked = true;
  #endif
  return create(this, false);
}

void bi::Memo::clean() {
  /* for current use cases, just clean the current memo, not parents */
  //auto parent = getParent();
  //if (parent) {
  //  parent->clean();
  //}
  clones.clean();
}

bi::Memo* bi::Memo::forwardGet() {
  #if USE_LAZY_DEEP_CLONE
  ///@todo make this thread safe
  if (forwardChild) {
    return forwardChild->forwardGet();
  } else if (isForked) {
    forwardChild = create(this, true);
    clean();
    return forwardChild.get();
  } else {
    return this;
  }
  #else
  return this;
  #endif
}

bi::Memo* bi::Memo::forwardPull() {
  #if USE_LAZY_DEEP_CLONE
  return forwardChild ? forwardChild->forwardPull() : this;
{'fraction_non_alphanumeric': 0.1625415589213151, 'fraction_numerical': 0.0, 'mean_word_length': 3.8270944741532977, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '6297674', 'n_tokens_mistral': 1035, 'n_tokens_neox': 1027, 'n_words': 215}