{"size": 3741, "ext": "js", "max_stars_repo_path": "ArraySet-commonjs.js", "max_stars_repo_name": "Jamesernator/es6-array-set", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ArraySet-commonjs.js", "max_issues_repo_name": "Jamesernator/es6-array-set", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ArraySet-commonjs.js", "max_forks_repo_name": "Jamesernator/es6-array-set", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.1073825503, "max_line_length": 72, "alphanum_fraction": 0.4691259022}
#!/usr/bin/env babel-node
"use strict";

Object.defineProperty(exports, "__esModule", {
    value: true
});

function id(x) {
    return x;
}

class ArraySet {
    constructor(iterable = null, serialize = id) {
        /*  Creates an ArrayMap object with optional serialize that will
            be called on every single key entered
        */
        this.size = 0;
        this._subSets = new Map();
        this._has = false;
        this._serialize = serialize;
        if (iterable != null) {
            for (const value of iterable) {
                this.add(value);
            }
        }
    }

    add(array) {
        /* Adds an array to the ArraySet */
        this._add(this._serialize(array));
        return this;
    }
    /* eslint-disable complexity */
    _add(array) {
        /* This actually adds the array to the ArraySet, returns true
            if the */
        if (array.length === 0) {
            if (this._has) {
                return false;
            } else {
                this.size += 1;
                this._has = true;
                return true;
            }
        } else {
            const [first, ...rest] = array;
            if (!this._subSets.has(first)) {
                this._subSets.set(first, new ArraySet());
            }
            const subSet = this._subSets.get(first);
            const changed = subSet._add(rest);
            if (changed) {
                this.size += 1;
            }
            return changed;
        }
    }
    /* eslint-enable complexity */

    clear() {
        /* Removes all elements from the ArraySet */
        this.size = 0;
        this._subSets = new Map();
        this._has = false;
    }

    delete(array) {
        /* This removes an item from the ArraySet */
        return this._delete(this._serialize(array));
    }

    /* eslint-disable complexity */
    _delete(array) {
        const [first, ...rest] = array;
        if (array.length === 0) {
            if (this._has) {
                this.size -= 1;
                this._has = false;
                return true;
            } else {
                return false;
            }
        } else if (!this._subSets.has(first)) {
            return false;
        } else {
            const subSet = this._subSets.get(first);
            const deleted = subSet._delete(rest);
            if (deleted) {
                this.size -= 1;
                if (subSet.size === 0) {
                    this._subSets.delete(first);
                }
            }
            return deleted;
        }
    }
    /* eslint-enable complexity */

    *entries() {
        for (const value of this.values()) {
            yield [value, value];
        }
    }

    forEach(callback, thisArg = null) {
        /* Invokes the callback with each element of the set */
        for (const value of this.values()) {
            Reflect.apply(callback, thisArg, [value, value, this]);
        }
    }

    has(array) {
        return this._has(this._serialize(array));
    }

    _has(array) {
        const [first, ...rest] = array;
        if (array.length === 0) {
            return this._has;
        } else if (!this._subSets.has(first)) {
            return false;
        } else {
            return this._subSets.get(first).has(rest);
        }
    }

    *keys() {
        yield* this.values();
    }

    *values() {
        if (this._has) {
            yield [];
        }
        for (const [value, subSet] of this._subSets) {
            for (const arr of subSet.values()) {
                yield [value, ...arr];
            }
        }
    }

    *[Symbol.iterator]() {
        yield* this.values();
    }
}
exports.default = ArraySet;
module.exports = exports["default"];

