<commit_before>package com.frostwire.jlibtorrent;

/**
 * This is a limited capability data point series backed by
 * a circular buffer logic. Used to hold equally timed sample
 * of statistics.
 *
 * @author aldenml
 * @author gubatron
 */
public class IntSeries {

    private final int[] buffer;
    private int head;
    private int end;

    IntSeries(int[] buffer) {
        if (buffer == null) {
            throw new IllegalArgumentException("buffer to hold data can't be null");
        }
        this.buffer = buffer;

        head = -1;
        end = -1;
    }

    IntSeries(int capacity) {
        this(new int[capacity]);
    }

    void add(int value) {
        if (head == -1) {
            head = end = 0;
            buffer[end] = value;
            return;
        }
        end = (end + 1) % buffer.length;
        buffer[end] = value;
        if (end <= head) {
            head = (head + 1) % buffer.length;
        }
    }

    int get(int i) {
        if (i < 0 || i > size() - 1) {
            throw new ArrayIndexOutOfBoundsException();
        }
        return buffer[(head + i) % size()];
    }

    int size() {
        if (head == -1) {
            return 0;
        } else if (head <= end) {
            return 1 + (end - head);
        } else {
            return buffer.length;
        }
    }

    /**
     * Returns up to count elements from the head
     */
    public int[] tail(int count) {
        int bufferSize = size();
        if (bufferSize == 0) {
            return new int[0];
        }
        int tailLength = Math.min(count, bufferSize);
        int[] result = new int[tailLength];
        int pointer = 1 + (end - tailLength);
        if (pointer < 0) {
            pointer = (buffer.length + pointer) % bufferSize;
        }
        int i = 0;
        while (i < result.length) {
            result[i] = buffer[pointer];
            pointer = (pointer + 1) % bufferSize;
            i++;
        }
        return result;
    }

    @Override
    public String toString() {
        StringBuffer arrayStr = new StringBuffer();
        arrayStr.append("[ ");
        for (int i = 0; i < buffer.length; i++) {
            arrayStr.append(buffer[i]);
            if (i != buffer.length - 1) {
                arrayStr.append(", ");
            }
        }
        arrayStr.append(" ]");
        return "{ head: " + head + ", end: " + end + ", size: " + size() + ", buffer: " + arrayStr.toString() + " }";
    }
}
<commit_msg>removed range checking from IntSeries#get for performance reasons<commit_after>package com.frostwire.jlibtorrent;

/**
 * This is a limited capability data point series backed by
 * a circular buffer logic. Used to hold equally timed sample
 * of statistics.
 *
 * @author aldenml
 * @author gubatron
 */
public final class IntSeries {

    private final int[] buffer;
    private int head;
    private int end;

    IntSeries(int[] buffer) {
        if (buffer == null) {
            throw new IllegalArgumentException("buffer to hold data can't be null");
        }
        if (buffer.length == 0) {
            throw new IllegalArgumentException("buffer to hold data can't be of size 0");
        }
        this.buffer = buffer;

        head = -1;
        end = -1;
    }

    IntSeries(int capacity) {
        this(new int[capacity]);
    }

    void add(int value) {
        if (head == -1) {
            head = end = 0;
            buffer[end] = value;
            return;
        }

        end = (end + 1) % buffer.length;
        buffer[end] = value;
        if (end <= head) {
            head = (head + 1) % buffer.length;
        }
    }

    /**
     * This method will always returns a value, but keep in mind that
     * due to the nature of the circular buffer internal logic, if you pass
     * past the size, you will get the sames values again. Use {@link #size()}
     * for a proper boundary check.
     *
     * @param index the value's index
     * @return the value in the series
     */
    public int get(int index) {
        return buffer[(head + index) % size()];
    }

    public int size() {
        if (head == -1) {
            return 0;
        } else if (head <= end) {
            return 1 + (end - head);
        } else {
            return buffer.length;
        }
    }

    /**
     * Returns up to count elements from the head
     */
    public int[] tail(int count) {
        int bufferSize = size();
        if (bufferSize == 0) {
            return new int[0];
        }
        int tailLength = Math.min(count, bufferSize);
        int[] result = new int[tailLength];
        int pointer = 1 + (end - tailLength);
        if (pointer < 0) {
            pointer = (buffer.length + pointer) % bufferSize;
        }
        int i = 0;
        while (i < result.length) {
            result[i] = buffer[pointer];
            pointer = (pointer + 1) % bufferSize;
            i++;
        }
        return result;
    }

    @Override
    public String toString() {
        StringBuffer arrayStr = new StringBuffer();
        arrayStr.append("[ ");
        for (int i = 0; i < buffer.length; i++) {
            arrayStr.append(buffer[i]);
            if (i != buffer.length - 1) {
                arrayStr.append(", ");
            }
        }
        arrayStr.append(" ]");
        return "{ head: " + head + ", end: " + end + ", size: " + size() + ", buffer: " + arrayStr.toString() + " }";
    }
}

{'fraction_non_alphanumeric': 0.12594644506001848, 'fraction_numerical': 0.007017543859649123, 'mean_word_length': 1.5951126018207955, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 4, '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': '5709004', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1542, 'n_words': 493}