<commit_before>var componentWise = require('./componentwise');

var arAdd = componentWise.numOp(function(a, b) {return a + b;});
var arSub = componentWise.numOp(function(a, b) {return a - b;});
var arLt = componentWise.numRelation(function(a, b) {return a < b;});
var arGt = componentWise.numRelation(function(a, b) {return a > b;});

function Complexity(options) {
    if (!this instanceof Complexity) {
        return new Complexity(options);
    }
    options = options || {};

    // TODO: ick
    if (!options.initial)
        throw new Error('missing initial option');
    if (!Array.isArray(options.initial))
        throw new Error('invalid initial option');
    if (!options.step)
        throw new Error('missing step option');
    if (!Array.isArray(options.step))
        throw new Error('invalid step option');
    if (options.lo &&
        !Array.isArray(options.lo)) {
        throw new Error('invalid lo option');
    }
    if (!options.hi)
        throw new Error('missing hi option');
    if (!Array.isArray(options.hi))
        throw new Error('invalid hi option');

    this.initial = options.initial;
    this.step = options.step;
    this.hi = options.hi;
    this.lo = options.lo ||
              this.hi.map(function() {return 1;});
    this.value = this.initial;
}

Complexity.prototype.inc = function() {
    var c = arAdd(this.value, this.step);
    if (!arGt(c, this.hi)) this.value = c;
    return this.value;
};

Complexity.prototype.dec = function() {
    var c = arSub(this.value, this.step);
    if (!arLt(c, this.lo)) this.value = c;
    return this.value;
};

module.exports = Complexity;<commit_msg>complexity: refactor inc/dec into a level property<commit_after>var componentWise = require('./componentwise');

var arAdd = componentWise.numOp(function(a, b) {return a + b;});
var arSub = componentWise.numOp(function(a, b) {return a - b;});
var arFloorDiv = componentWise.numOp(function(a, b) {return Math.floor(a / b);});
var arLt = componentWise.numRelation(function(a, b) {return a < b;});
var arGt = componentWise.numRelation(function(a, b) {return a > b;});
var arScale = componentWise.scalarNumOp(function(s, a) {return s*a;});

function Complexity(options) {
    if (!this instanceof Complexity) {
        return new Complexity(options);
    }
    options = options || {};

    // TODO: ick
    if (!options.initial)
        throw new Error('missing initial option');
    if (!Array.isArray(options.initial))
        throw new Error('invalid initial option');
    if (!options.step)
        throw new Error('missing step option');
    if (!Array.isArray(options.step))
        throw new Error('invalid step option');
    if (options.lo &&
        !Array.isArray(options.lo)) {
        throw new Error('invalid lo option');
    }
    if (!options.hi)
        throw new Error('missing hi option');
    if (!Array.isArray(options.hi))
        throw new Error('invalid hi option');

    this.initial = options.initial;
    this.step = options.step;
    this.hi = options.hi;
    this.lo = options.lo ||
              this.hi.map(function() {return 1;});
    this.value = this.initial;
    Object.defineProperty(this, 'level', {
        enumerable: true,
        get: this.getLevel,
        set: this.setLevel
    });
}

Complexity.prototype.getLevel = function() {
    var diff = arSub(this.value, this.lo);
    var qs = arFloorDiv(diff, this.step);
    return 1 + Math.min.apply(Math, qs);
};

Complexity.prototype.setLevel = function(level) {
    var value = arAdd(this.lo, arScale(level, this.step));
    if (arGt(value, this.hi)) value = this.hi;
    else if (arLt(value, this.lo)) value = this.lo;
    this.value = value;
    return value;
};

module.exports = Complexity;
{'fraction_non_alphanumeric': 0.14958299704062417, 'fraction_numerical': 0.0008071025020177562, 'mean_word_length': 3.1128318584070795, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '63934', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1179, 'n_words': 306}