<commit_before>#include <sstream>
#include "slice.hpp"

namespace Vole {

  using std::stringstream;

  template <typename T>
  Slice<T>::Slice(size_t l, size_t c)
  : mem(new T[c]),
    beg(mem),
    len(l),
    cap(c)
  { }

  template <typename T>
  Slice<T>::Slice(T* m, T* b, size_t l, size_t c)
  : mem(m),
    beg(b),
    len(l),
    cap(c)
  { }

  template <typename T>
  template <typename Allocator>
  Slice<T>::Slice(size_t l, size_t c, Allocator& a)
  : mem(a.template alloc<T>(c)),
    beg(mem),
    len(l),
    cap(c)
  { }

  template <typename T>
  template <typename Allocator>
  Slice<T>::Slice(size_t l, size_t c, Allocator* a)
  : mem(a->template alloc<T>(c)),
    beg(mem),
    len(l),
    cap(c)
  { }

  template <typename T>
  T& Slice<T>::operator[](size_t i) {
    if (!(i < len)) {
      // TODO: use an error class with more metadata
      throw "slice index out of bounds";
    }
    return beg[i];
  }

  template <typename T>
  Slice<T> Slice<T>::slice(size_t start, size_t end) {
    if (end > len || start > end) {
      // TODO: use an error class with more metadata
      throw "invalid range for slice";
    }
    return { mem, beg + start, end - beg, cap - beg };
  }

  template <typename T>
  T& Slice<T>::first() {
    return (*this)[0];
  }

  template <typename T>
  T& Slice<T>::last() {
    return (*this)[len-1];
  }

  template <typename T>
  Slice<T> Slice<T>::take(size_t n) {
    return slice(0, n);
  }

  template <typename T>
  Slice<T> Slice<T>::drop(size_t n) {
    return slice(n, len);
  }

  template <typename T>
  Slice<T>::operator string() {
    stringstream ss;
    ss << '(';
    for (size_t i = 0; i < len; ++i) {
      ss << (i ? " " : "") << beg[i];
    }
    ss << ')';
    return ss.str();
  }
}<commit_msg>fix up the range calculations; they were totally wrong<commit_after>#include <sstream>
#include "slice.hpp"

namespace Vole {

  using std::stringstream;

  template <typename T>
  Slice<T>::Slice(size_t l, size_t c)
  : mem(new T[c]),
    beg(mem),
    len(l),
    cap(c)
  { }

  template <typename T>
  Slice<T>::Slice(T* m, T* b, size_t l, size_t c)
  : mem(m),
    beg(b),
    len(l),
    cap(c)
  { }

  template <typename T>
  template <typename Allocator>
  Slice<T>::Slice(size_t l, size_t c, Allocator& a)
  : mem(a.template alloc<T>(c)),
    beg(mem),
    len(l),
    cap(c)
  { }

  template <typename T>
  template <typename Allocator>
  Slice<T>::Slice(size_t l, size_t c, Allocator* a)
  : mem(a->template alloc<T>(c)),
    beg(mem),
    len(l),
    cap(c)
  { }

  template <typename T>
  T& Slice<T>::operator[](size_t i) {
    if (!(i < len)) {
      // TODO: use an error class with more metadata
      throw "slice index out of bounds";
    }
    return beg[i];
  }

  template <typename T>
  Slice<T> Slice<T>::slice(size_t lower, size_t upper) {
    if (upper > len || lower > upper) {
      // TODO: use an error class with more metadata
      throw "invalid range for slice";
    }
    return { mem, beg + lower, upper - lower, cap - lower };
  }

  template <typename T>
  T& Slice<T>::first() {
    return (*this)[0];
  }

  template <typename T>
  T& Slice<T>::last() {
    return (*this)[len-1];
  }

  template <typename T>
  Slice<T> Slice<T>::take(size_t n) {
    return slice(0, n);
  }

  template <typename T>
  Slice<T> Slice<T>::drop(size_t n) {
    return slice(n, len);
  }

  template <typename T>
  Slice<T>::operator string() {
    stringstream ss;
    ss << '(';
    for (size_t i = 0; i < len; ++i) {
      ss << (i ? " " : "") << beg[i];
    }
    ss << ')';
    return ss.str();
  }
}
{'fraction_non_alphanumeric': 0.17614424410540916, 'fraction_numerical': 0.002219140083217753, 'mean_word_length': 2.690890481064483, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 69, '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': '1289061', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1386, 'n_words': 370}