<commit_before>#ifndef LINEAREDGEDB_H
#define LINEAREDGEDB_H

#include "../edgedb.h"
#include "../edgeannotationstorage.h"

#include "../dfs.h"
#include "../exactannokeysearch.h"

#include <fstream>
#include <set>
#include <limits>

#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/map.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/vector.hpp>

#include <boost/format.hpp>

#include <stx/btree_map>


namespace annis
{


template<typename pos_t>
class LinearEdgeDB : public ReadableGraphStorage
{
public:
  class LinearIterator : public EdgeIterator
  {
  public:

    LinearIterator(const LinearEdgeDB& edb, nodeid_t startNode, unsigned int minDistance, unsigned int maxDistance)
      : edb(edb), minDistance(minDistance), maxDistance(maxDistance), startNode(startNode),
        chain(nullptr)
    {
      reset();
    }

    virtual std::pair<bool, nodeid_t> next()
    {
      bool found = false;
      nodeid_t node = 0;
      if(chain != nullptr && currentPos <= endPos && currentPos < chain->size())
      {
        found = true;
        node = chain->at(currentPos);
        chain->at(currentPos);
        currentPos++;
      }
      return std::pair<bool, nodeid_t>(found, node);
    }

    virtual void reset()
    {
      typedef typename stx::btree_map<nodeid_t, RelativePosition<pos_t> >::const_iterator PosIt;
      typedef std::map<nodeid_t, std::vector<nodeid_t> >::const_iterator NodeChainIt;

      PosIt posSourceIt = edb.node2pos.find(startNode);
      if(posSourceIt != edb.node2pos.end())
      {
        const RelativePosition<pos_t>& relPos = posSourceIt->second;
        currentPos = relPos.pos;
        NodeChainIt itNodeChain = edb.nodeChains.find(relPos.root);
        if(itNodeChain != edb.nodeChains.end())
        {
          chain = &(itNodeChain->second);
        }

        // define where to stop
        if(maxDistance == uintmax)
        {
          endPos = std::numeric_limits<pos_t>::max();
        }
        else
        {
          endPos = currentPos + maxDistance;
        }
        // add the minium distance
        currentPos = currentPos + minDistance;

      }
    }

    virtual ~LinearIterator()
    {

    }

  private:

    const LinearEdgeDB& edb;
    unsigned int minDistance;
    unsigned int maxDistance;
    nodeid_t startNode;

    const std::vector<nodeid_t>* chain;
    pos_t currentPos;
    pos_t endPos;

  };


public:
  LinearEdgeDB(StringStorage& strings, const Component& component)
    : component(component)
  {

  }

  virtual void clear()
  {
    edgeAnno.clear();
    node2pos.clear();
    nodeChains.clear();
  }

  virtual void copy(const DB& db, const ReadableGraphStorage& orig)
  {
    // find all root nodes
    std::set<nodeid_t> roots;
<commit_msg>don't use the pos_t for the internal variables currentPos and endPos<commit_after>#ifndef LINEAREDGEDB_H
#define LINEAREDGEDB_H

#include "../edgedb.h"
#include "../edgeannotationstorage.h"

#include "../dfs.h"
#include "../exactannokeysearch.h"

#include <fstream>
#include <set>
#include <limits>

#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/map.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/vector.hpp>

#include <boost/format.hpp>

#include <stx/btree_map>


namespace annis
{


template<typename pos_t>
class LinearEdgeDB : public ReadableGraphStorage
{
public:
  class LinearIterator : public EdgeIterator
  {
  public:

    LinearIterator(const LinearEdgeDB& edb, nodeid_t startNode, unsigned int minDistance, unsigned int maxDistance)
      : edb(edb), minDistance(minDistance), maxDistance(maxDistance), startNode(startNode),
        chain(nullptr)
    {
      reset();
    }

    virtual std::pair<bool, nodeid_t> next()
    {
      bool found = false;
      nodeid_t node = 0;
      if(chain != nullptr && currentPos <= endPos && currentPos < chain->size())
      {
        found = true;
        node = chain->at(currentPos);
        chain->at(currentPos);
        currentPos++;
      }
      return std::pair<bool, nodeid_t>(found, node);
    }

    virtual void reset()
    {
      typedef typename stx::btree_map<nodeid_t, RelativePosition<pos_t> >::const_iterator PosIt;
      typedef std::map<nodeid_t, std::vector<nodeid_t> >::const_iterator NodeChainIt;

      PosIt posSourceIt = edb.node2pos.find(startNode);
      if(posSourceIt != edb.node2pos.end())
      {
        const RelativePosition<pos_t>& relPos = posSourceIt->second;
        currentPos = relPos.pos;
        NodeChainIt itNodeChain = edb.nodeChains.find(relPos.root);
        if(itNodeChain != edb.nodeChains.end())
        {
          chain = &(itNodeChain->second);
        }

        // define where to stop
        if(maxDistance == uintmax)
        {
          endPos = std::numeric_limits<pos_t>::max();
        }
        else
        {
          endPos = currentPos + maxDistance;
        }
        // add the minium distance
        currentPos = currentPos + minDistance;

      }
    }

    virtual ~LinearIterator()
    {

    }

  private:

    const LinearEdgeDB& edb;
    unsigned int minDistance;
    unsigned int maxDistance;
    nodeid_t startNode;

    const std::vector<nodeid_t>* chain;
    unsigned int currentPos;
    unsigned int endPos;

  };


public:
  LinearEdgeDB(StringStorage& strings, const Component& component)
    : component(component)
  {

  }

  virtual void clear()
  {
    edgeAnno.clear();
    node2pos.clear();
    nodeChains.clear();
  }

  virtual void copy(const DB& db, const ReadableGraphStorage& orig)
  {
    // find all root nodes
    std::set<nodeid_t> roots;

{'fraction_non_alphanumeric': 0.11747250829115029, 'fraction_numerical': 0.0013964042590329901, 'mean_word_length': 2.89530931339225, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 55, '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': '641146', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1807, 'n_words': 388}