UNPKG

@rimbu/sorted

Version:

Immutable SortedMap and SortedSet implementations for TypeScript

71 lines 3.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SortedMapContext = void 0; exports.createSortedMapContext = createSortedMapContext; var tslib_1 = require("tslib"); var map_custom_1 = require("@rimbu/collection-types/map-custom"); var common_1 = require("@rimbu/common"); var map_custom_2 = require("@rimbu/sorted/map-custom"); var SortedMapContext = /** @class */ (function (_super) { tslib_1.__extends(SortedMapContext, _super); function SortedMapContext(blockSizeBits, comp) { var _this = _super.call(this) || this; _this.blockSizeBits = blockSizeBits; _this.comp = comp; _this.typeTag = 'SortedMap'; _this.builder = function () { return new map_custom_2.SortedMapBuilder(_this); }; _this.maxEntries = 1 << blockSizeBits; _this.minEntries = _this.maxEntries >>> 1; _this._empty = Object.freeze(new map_custom_2.SortedMapEmpty(_this)); return _this; } SortedMapContext.prototype.isNonEmptyInstance = function (source) { return source instanceof map_custom_2.SortedMapNode; }; SortedMapContext.prototype.createBuilder = function (source) { return new map_custom_2.SortedMapBuilder(this, source); }; SortedMapContext.prototype.isValidKey = function (key) { return this.comp.isComparable(key); }; SortedMapContext.prototype.findIndex = function (key, entries) { var start = 0; var end = entries.length - 1; while (start <= end) { var mid = (start + end) >>> 1; var midEntry = entries[mid]; var comp = this.comp.compare(key, midEntry[0]); if (comp < 0) end = mid - 1; else if (comp > 0) start = mid + 1; else return mid; } return -(start + 1); }; SortedMapContext.prototype.leaf = function (entries) { return new map_custom_2.SortedMapLeaf(this, entries); }; SortedMapContext.prototype.inner = function (entries, children, size) { return new map_custom_2.SortedMapInner(this, entries, children, size); }; SortedMapContext.prototype.isSortedMapEmpty = function (obj) { return obj instanceof map_custom_2.SortedMapEmpty; }; SortedMapContext.prototype.isSortedMapLeaf = function (obj) { return obj instanceof map_custom_2.SortedMapLeaf; }; SortedMapContext.prototype.isSortedMapInner = function (obj) { return obj instanceof map_custom_2.SortedMapInner; }; return SortedMapContext; }(map_custom_1.RMapBase.ContextBase)); exports.SortedMapContext = SortedMapContext; function createSortedMapContext(options) { var _a, _b; return Object.freeze(new SortedMapContext((_a = options === null || options === void 0 ? void 0 : options.blockSizeBits) !== null && _a !== void 0 ? _a : 5, (_b = options === null || options === void 0 ? void 0 : options.comp) !== null && _b !== void 0 ? _b : common_1.Comp.defaultComp())); } //# sourceMappingURL=context.cjs.map