<commit_before>#ifndef VPP_IMAGENd_HH__
# define VPP_IMAGENd_HH__

# include <memory>
# include <vpp/boxNd.hh>
# include <vpp/imageNd_iterator.hh>

namespace vpp
{

  template <typename P>
  void delete_imageNd_data(P* ptr)
  {
    std::cout << "delete" << std::endl;
    std::cout << ptr->external_refcount_ << std::endl;
    if (ptr->external_refcount_ && *(ptr->external_refcount_) > 1)
    {
      (*(ptr->external_refcount_))--;
    }
     else
      delete ptr;
  }

  template <typename V, unsigned N, typename EXTERNAL_REFCOUNT_TYPE = int>
  class imageNd_data
  {
  public:
    V* data_;
    V* data_end_;
    V* begin_;
    boxNd<N> domain_;
    int border_;
    int pitch_;
    bool own_data_;
    EXTERNAL_REFCOUNT_TYPE* external_refcount_;
  };

  template <typename V, unsigned N>
  class imageNd
  {
  public:

    typedef V value_type;
    typedef vint<N> coord_type;
    typedef boxNd<N> domain_type;
    typedef imageNd_iterator<V, N> iterator;
    typedef imageNd_row_iterator<V, N> row_iterator;
    enum { dimension = N };

    // Constructors.
    imageNd();

    imageNd(int* dims, int border = 0);

    imageNd(const boxNd<N>& domain, int border = 0);

    imageNd(int* dims, int border, V* data, int pitch, bool own_data = false);

    // Copy constructor. Share the data.
    imageNd(const imageNd<V, N>& other);

    // Move constructor.
    imageNd(const imageNd<V, N>&& other);

    // Destructor.
    ~imageNd();

    // Assigment.
    imageNd<V, N>& operator=(const imageNd<V, N>& other);
    imageNd<V, N>& operator=(const imageNd<V, N>&& other);

    // Access to values.
    V& operator()(const vint<N>& p);
    const V& operator()(const vint<N>& p) const;

    V* address_of(const vint<N>& p);
    const V* address_of(const vint<N>& p) const;

    int offset_of(const vint<N>& p) const;

    int coords_to_index(const vint<N>& p) const;

    int coords_to_offset(const vint<N>& p) const;

    bool has(coord_type& p) const { return ptr_->domain_.has(p); }
    bool has(const V* p) const { return p >= ptr_->data_ and p < ptr_->data_end_; }
    // Access to raw buffer.
    V* data() { return ptr_->data_; }
    const V* data() const { return ptr_->data_; }

    iterator begin() { return iterator(*ptr_->domain_.begin(), *this); }
    iterator end() { return iterator(*ptr_->domain_.end(), *this); }

    int pitch() const { return ptr_->pitch_; }
    int border() const { return ptr_->border_; }

    // Domain<commit_msg>Shortcut method for accessing image2d values : imageNd::operator(int, int)<commit_after>#ifndef VPP_IMAGENd_HH__
# define VPP_IMAGENd_HH__

# include <memory>
# include <vpp/boxNd.hh>
# include <vpp/imageNd_iterator.hh>

namespace vpp
{

  template <typename P>
  void delete_imageNd_data(P* ptr)
  {
    std::cout << "delete" << std::endl;
    std::cout << ptr->external_refcount_ << std::endl;
    if (ptr->external_refcount_ && *(ptr->external_refcount_) > 1)
    {
      (*(ptr->external_refcount_))--;
    }
     else
      delete ptr;
  }

  template <typename V, unsigned N, typename EXTERNAL_REFCOUNT_TYPE = int>
  class imageNd_data
  {
  public:
    V* data_;
    V* data_end_;
    V* begin_;
    boxNd<N> domain_;
    int border_;
    int pitch_;
    bool own_data_;
    EXTERNAL_REFCOUNT_TYPE* external_refcount_;
  };

  template <typename V, unsigned N>
  class imageNd
  {
  public:

    typedef V value_type;
    typedef vint<N> coord_type;
    typedef boxNd<N> domain_type;
    typedef imageNd_iterator<V, N> iterator;
    typedef imageNd_row_iterator<V, N> row_iterator;
    enum { dimension = N };

    // Constructors.
    imageNd();

    imageNd(int* dims, int border = 0);

    imageNd(const boxNd<N>& domain, int border = 0);

    imageNd(int* dims, int border, V* data, int pitch, bool own_data = false);

    // Copy constructor. Share the data.
    imageNd(const imageNd<V, N>& other);

    // Move constructor.
    imageNd(const imageNd<V, N>&& other);

    // Destructor.
    ~imageNd();

    // Assigment.
    imageNd<V, N>& operator=(const imageNd<V, N>& other);
    imageNd<V, N>& operator=(const imageNd<V, N>&& other);

    // Access to values.
    V& operator()(const vint<N>& p);
    const V& operator()(const vint<N>& p) const;

    V& operator()(int r, int c) { return operator()(vint2(r, c)); }
    const V& operator() (int r, int c) const { return operator()(vint2(r, c)); }

    V* address_of(const vint<N>& p);
    const V* address_of(const vint<N>& p) const;

    int offset_of(const vint<N>& p) const;

    int coords_to_index(const vint<N>& p) const;

    int coords_to_offset(const vint<N>& p) const;

    bool has(coord_type& p) const { return ptr_->domain_.has(p); }
    bool has(const V* p) const { return p >= ptr_->data_ and p < ptr_->data_end_; }
    // Access to raw buffer.
    V* data() { return ptr_->data_; }
    const V* data() const { return ptr_->data_; }

    iterator begin() { return iterator(*ptr_->domain_.begin(), *this); }
    iterator end() { return iterator(*ptr_->domain_.end(), *this); }

    int pitch() const { return ptr_->pitch_; }
    int border() const { return ptr_->border_; }

    // Domain
{'fraction_non_alphanumeric': 0.14355373512775502, 'fraction_numerical': 0.0017554125219426564, 'mean_word_length': 3.152226720647773, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 83, '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': '1595401', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1769, 'n_words': 487}