UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for static analysis and code manipulation.

43 lines (42 loc) 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var ArrayUtils_1 = require("../ArrayUtils"); var comparers_1 = require("../comparers"); var SortedKeyValueArray = /** @class */ (function () { function SortedKeyValueArray(getKey, comparer) { this.getKey = getKey; this.comparer = comparer; this.array = []; } SortedKeyValueArray.prototype.set = function (value) { ArrayUtils_1.ArrayUtils.binaryInsertWithOverwrite(this.array, value, new comparers_1.PropertyComparer(this.getKey, this.comparer)); }; SortedKeyValueArray.prototype.removeByValue = function (value) { this.removeByKey(this.getKey(value)); }; SortedKeyValueArray.prototype.removeByKey = function (key) { var storedComparer = new comparers_1.ComparerToStoredComparer(this.comparer, key); var index = ArrayUtils_1.ArrayUtils.binarySearch(this.array, new comparers_1.PropertyStoredComparer(this.getKey, storedComparer)); if (index >= 0) this.array.splice(index, 1); }; SortedKeyValueArray.prototype.getArrayCopy = function () { return tslib_1.__spread(this.array); }; SortedKeyValueArray.prototype.hasItems = function () { return this.array.length > 0; }; SortedKeyValueArray.prototype.entries = function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [5 /*yield**/, tslib_1.__values(this.array)]; case 1: _a.sent(); return [2 /*return*/]; } }); }; return SortedKeyValueArray; }()); exports.SortedKeyValueArray = SortedKeyValueArray;