<commit_before>// Fenwick Tree implementation
// -----------------------------------------
// Authors: <NAME>  (<EMAIL>)
//          <NAME> (<EMAIL>)

#pragma once

template<typename T>
class FenwickTree {
public:
  FenwickTree(int size): size(size) {
    tree = new T[size];
  }

  ~FenwickTree() {
    delete[] tree;
  }

  // Increases value of i-th element by delta
  void add(int i, T delta) {
    for (; i < size; i |= i + 1)
      tree[i] += delta;
  }

  // Returns sum of elements with indexes left to right, inclusive
  T sum(int left, int right) {
    return sum(right) - sum(left - 1);
  }

private:
  T* tree;
  int size;

  // Calculates sum from index 0 to given input
  T sum(int index) {
    T sum = 0;

    while (index >= 0) {
      sum += tree[index];
      index &= index + 1;
      index--;
    }
<commit_msg>Fenwick: Fixed major bug :P<commit_after>// Fenwick Tree implementation
// -----------------------------------------
// Authors: <NAME>  (<EMAIL>)
//          <NAME> (<EMAIL>)

#pragma once

#include <algorithm>

template<typename T>
class FenwickTree {
public:
  FenwickTree(int size): size(size) {
    tree = new T[size];
    std::fill_n(tree, size, 0);
  }

  ~FenwickTree() {
    delete[] tree;
  }

  // Increases value of i-th element by delta
  void add(int i, T delta) {
    for (; i < size; i |= i + 1)
      tree[i] += delta;
  }

  // Returns sum of elements with indexes left to right, inclusive
  T sum(int left, int right) {
    return sum(right) - sum(left - 1);
  }

private:
  T* tree;
  int size;

  // Calculates sum from index 0 to given input
  T sum(int index) {
    T sum = 0;

    while (index >= 0) {
      sum += tree[index];
      index &= index + 1;
      index--;
    }

{'fraction_non_alphanumeric': 0.18497109826589594, 'fraction_numerical': 0.007514450867052023, 'mean_word_length': 1.9896373056994818, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '4416895', 'n_tokens_mistral': 610, 'n_tokens_neox': 579, 'n_words': 193}