@rimbu/sorted
Version:
Immutable SortedMap and SortedSet implementations for TypeScript
74 lines • 3.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SortedSetContext = void 0;
exports.createSortedSetContext = createSortedSetContext;
var tslib_1 = require("tslib");
var set_custom_1 = require("@rimbu/collection-types/set-custom");
var common_1 = require("@rimbu/common");
var set_custom_2 = require("@rimbu/sorted/set-custom");
var SortedSetContext = /** @class */ (function (_super) {
tslib_1.__extends(SortedSetContext, _super);
function SortedSetContext(blockSizeBits, comp) {
var _this = _super.call(this) || this;
_this.blockSizeBits = blockSizeBits;
_this.comp = comp;
_this.typeTag = 'SortedSet';
_this.builder = function () {
return new set_custom_2.SortedSetBuilder(_this);
};
_this.maxEntries = 1 << _this.blockSizeBits;
_this.minEntries = _this.maxEntries >>> 1;
_this._empty = Object.freeze(new set_custom_2.SortedSetEmpty(_this));
return _this;
}
SortedSetContext.prototype.isNonEmptyInstance = function (source) {
return source instanceof set_custom_2.SortedSetNode;
};
SortedSetContext.prototype.isValidValue = function (value) {
return this.comp.isComparable(value);
};
SortedSetContext.prototype.createBuilder = function (source) {
return new set_custom_2.SortedSetBuilder(this, source);
};
SortedSetContext.prototype.findIndex = function (value, 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(value, midEntry);
if (comp < 0)
end = mid - 1;
else if (comp > 0)
start = mid + 1;
else
return mid;
}
return -(start + 1);
};
SortedSetContext.prototype.leaf = function (entries) {
return new set_custom_2.SortedSetLeaf(this, entries);
};
SortedSetContext.prototype.inner = function (entries, children, size) {
return new set_custom_2.SortedSetInner(this, entries, children, size);
};
SortedSetContext.prototype.isSortedSetEmpty = function (obj) {
return obj instanceof set_custom_2.SortedSetEmpty;
};
SortedSetContext.prototype.isSortedSetLeaf = function (obj) {
return obj instanceof set_custom_2.SortedSetLeaf;
};
SortedSetContext.prototype.isSortedSetInner = function (obj) {
return obj instanceof set_custom_2.SortedSetInner;
};
SortedSetContext.prototype.isSortedSetNode = function (obj) {
return obj instanceof set_custom_2.SortedSetNode;
};
return SortedSetContext;
}(set_custom_1.RSetBase.ContextBase));
exports.SortedSetContext = SortedSetContext;
function createSortedSetContext(options) {
var _a, _b;
return Object.freeze(new SortedSetContext((_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