<commit_before>/*
 * Copyright (c) 2013 <NAME>
 *
 * See the file LICENSE.txt for copying permission.
 * 
 */

(function (global) {

  "use strict";

  function IndexOutOfBounds(maxIndex, requestedIndex, method) {
    this.maxIndex       = maxIndex;
    this.requestedIndex = requestedIndex;
    this.method         = method;
  }

  IndexOutOfBounds.prototype.toString = function () {
    return "Invalid index in method ['" + this.method + "']\n" +
           "Requested index    : " + this.requestedIndex +
           "\nValid _buffer index : [0.." + this.maxIndex + "]";
  };

  function ImproperBlockLength(ringBlockLength, givenBlockLength) {
    this.ringBlockLength  = ringBlockLength;
    this.givenBlockLength = givenBlockLength;
  }

  ImproperBlockLength.prototype.toString = function () {
    return "Block length mismatch.\n" +
           "Requeste block length : " + this.givenBlockLength + "\n" +
           "Valid block length    : " + this.ringBlockLength;
  };

  function Ring(length, blockLength) {
    this.length    = length;
    this._maxIndex = this.length - 1;
    this._start    = 0;
    this._buffer   = new Float32Array(this.length);

    /* blockLength should always be a factor of size.
     * An exception is thrown if it's not;
     */
    this._blockLength = 0;

    if (blockLength) {

      if (length % blockLength !== 0) {
        throw "Block length must be a factor of length.";
      }

      this._blockLength = blockLength;

    }
  }

  Ring.prototype.checkBounds = function (requested, callerName) {

    if (requested < 0 || requested > this._maxIndex) {
      throw new IndexOutOfBounds(this._maxIndex, requested, callerName);
    }
  };

  Ring.prototype.relativeIndex = function (index) {
    return (this._start + index) % this.length;
  };

  /* Should not be used when there is a set _blockLength */
  Ring.prototype.push = function (element) {

    this._buffer[this._start] = element;

    var newStart = this._start + 1;
    this._start = newStart > this._maxIndex ? 0 : newStart;
  };

  Ring.prototype.get = function (index) {

    this.checkBounds(index, 'get');

    return this._buffer[this.relativeIndex(index)];
  };

  Ring.prototype.set = function (index, value) {

    this.checkBounds(index, 'set');

    this._buffer[this.relativeIndex(index)] = value;

  };

  Ring.prototype.concat = function (arr) {

    var alen = arr.length;

    if (alen !== this._blockLength) {
      throw new ImproperBlockLength(this._blockLength, alen);
    }

    this._buffer.set(arr, this._start);
    this._start = (this._start + alen) % this.length;

  };

  Ring.prototype.map = function (callback) {

    var relativeIndex<commit_msg>Remove push method.<commit_after>/*
 * Copyright (c) 2013 <NAME>
 *
 * See the file LICENSE.txt for copying permission.
 * 
 */

(function (global) {

  "use strict";

  function IndexOutOfBounds(maxIndex, requestedIndex, method) {
    this.maxIndex       = maxIndex;
    this.requestedIndex = requestedIndex;
    this.method         = method;
  }

  IndexOutOfBounds.prototype.toString = function () {
    return "Invalid index in method ['" + this.method + "']\n" +
           "Requested index    : " + this.requestedIndex +
           "\nValid _buffer index : [0.." + this.maxIndex + "]";
  };

  function ImproperBlockLength(ringBlockLength, givenBlockLength) {
    this.ringBlockLength  = ringBlockLength;
    this.givenBlockLength = givenBlockLength;
  }

  ImproperBlockLength.prototype.toString = function () {
    return "Block length mismatch.\n" +
           "Requeste block length : " + this.givenBlockLength + "\n" +
           "Valid block length    : " + this.ringBlockLength;
  };

  function Ring(length, blockLength) {
    this.length    = length;
    this._maxIndex = this.length - 1;
    this._start    = 0;
    this._buffer   = new Float32Array(this.length);

    /* blockLength should always be a factor of size.
     * An exception is thrown if it's not;
     */
    this._blockLength = 0;

    if (blockLength) {

      if (length % blockLength !== 0) {
        throw "Block length must be a factor of length.";
      }

      this._blockLength = blockLength;

    }
  }

  Ring.prototype.checkBounds = function (requested, callerName) {

    if (requested < 0 || requested > this._maxIndex) {
      throw new IndexOutOfBounds(this._maxIndex, requested, callerName);
    }
  };

  Ring.prototype.relativeIndex = function (index) {
    return (this._start + index) % this.length;
  };

  Ring.prototype.get = function (index) {

    this.checkBounds(index, 'get');

    return this._buffer[this.relativeIndex(index)];
  };

  Ring.prototype.set = function (index, value) {

    this.checkBounds(index, 'set');

    this._buffer[this.relativeIndex(index)] = value;

  };

  Ring.prototype.concat = function (arr) {

    var alen = arr.length
      , nlen = this._start + alen;

    if (alen !== this._blockLength) {
      throw new ImproperBlockLength(this._blockLength, alen);
    }

    this._buffer.set(arr, this._start);

    if (this._start + alen >= this.length) {
        this._start = 0;
    } else {
        this._start = nlen;
    }
  };

  Ring.prototype.map = function (callback) {

    var relativeIndex
{'fraction_non_alphanumeric': 0.12406662837449742, 'fraction_numerical': 0.005169442848937392, 'mean_word_length': 2.704964539007092, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '4496747', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1556, 'n_words': 377}