"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.memoizedGetDescendantCount = exports.memoizedGetFlatDataFromTree = exports.memoizedInsertNode = void 0;
var tree_1 = require("./tree");
var memoize = function (f) {
    var savedArgsArray = [];
    var savedKeysArray = [];
    var savedResult = null;
    return function (args) {
        var keysArray = Object.keys(args).sort();
        var argsArray = keysArray.map(function (key) { return args[key]; });
        // If the arguments for the last insert operation are different than this time,
        // recalculate the result
        if (argsArray.length !== savedArgsArray.length ||
            argsArray.some(function (arg, index) { return arg !== savedArgsArray[index]; }) ||
            keysArray.some(function (key, index) { return key !== savedKeysArray[index]; })) {
            savedArgsArray = argsArray;
            savedKeysArray = keysArray;
            savedResult = f(args);
        }
        return savedResult;
    };
};
exports.memoizedInsertNode = memoize(tree_1.insertNode);
exports.memoizedGetFlatDataFromTree = memoize(tree_1.getFlatDataFromTree);
exports.memoizedGetDescendantCount = memoize(tree_1.getDescendantCount);
