<commit_before>/**
 * Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window.
 * For example,
 * MovingAverage m = new MovingAverage(3);
 * m.next(1) = 1
 * m.next(10) = (1 + 10) / 2
 * m.next(3) = (1 + 10 + 3) / 3
 * m.next(5) = (10 + 3 + 5) / 3
 * Input :  ["MovingAverage","next","next","next","next"]
 *          [[3],[1],[10],[3],[5]]
 *
 * Output : [null,1.00000,5.50000,4.66667,6.00000]
 * Complexity: O(1) time, space O(n) where is the given size of the array.
 */
public class MovingAverage {
    /** Initialize your data structure here. */
    int[] arr;
    int index;
    double res;
    int start;
    public MovingAverage(int size) {
        arr = new int[size];
        index = 0;
        res = 0;
        start = 0;
    }
    public double next(int val) {
        //  keep a constant size to divide once we reach length - 1
        if (start < arr.length) {
            start++;
        }
        res -= arr[index];
        res += val;
        arr[index] = val;
        index = (index + 1) % arr.length;
        return res / start;
    }
}
/**
 * Your MovingAverage object will be instantiated and called as such:
 * MovingAverage obj = new MovingAverage(size);
 * double param_1 = obj.next(val);
 */
<commit_msg>Use 2 spaces not 4<commit_after>/**
 * Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window.
 * For example,
 * MovingAverage m = new MovingAverage(3);
 * m.next(1) = 1
 * m.next(10) = (1 + 10) / 2
 * m.next(3) = (1 + 10 + 3) / 3
 * m.next(5) = (10 + 3 + 5) / 3
 * Input :  ["MovingAverage","next","next","next","next"]
 *          [[3],[1],[10],[3],[5]]
 *
 * Output : [null,1.00000,5.50000,4.66667,6.00000]
 * Complexity: O(1) time, space O(n) where is the given size of the array.
 */
public class MovingAverage {
  /** Initialize your data structure here. */
  int[] arr;
  int index;
  double res;
  int start;

  public MovingAverage(int size) {
    arr = new int[size];
    index = 0;
    res = 0;
    start = 0;
  }

  public double next(int val) {
    // keep a constant size to divide once we reach length - 1
    if (start < arr.length) {
      start++;
    }
    res -= arr[index];
    res += val;
    arr[index] = val;
    index = (index + 1) % arr.length;
    return res / start;
  }
}
/**
 * Your MovingAverage object will be instantiated and called as such:
 * MovingAverage obj = new MovingAverage(size);
 * double param_1 = obj.next(val);
 */

{'fraction_non_alphanumeric': 0.15231259968102073, 'fraction_numerical': 0.04704944178628389, 'mean_word_length': 2.4464285714285716, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7554249', 'n_tokens_mistral': 944, 'n_tokens_neox': 827, 'n_words': 280}