@rimbu/hashed
Version:
Immutable HashMap and HashSet implementations for TypeScript
71 lines • 3.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HashSetContext = void 0;
exports.createHashSetContext = createHashSetContext;
var tslib_1 = require("tslib");
var set_custom_1 = require("@rimbu/collection-types/set-custom");
var common_1 = require("@rimbu/common");
var list_1 = require("@rimbu/list");
var index_cjs_1 = require("../../common/index.cjs");
var set_custom_2 = require("@rimbu/hashed/set-custom");
var HashSetContext = /** @class */ (function (_super) {
tslib_1.__extends(HashSetContext, _super);
function HashSetContext(hasher, eq, blockSizeBits, listContext) {
var _this = _super.call(this) || this;
_this.hasher = hasher;
_this.eq = eq;
_this.blockSizeBits = blockSizeBits;
_this.listContext = listContext;
_this.typeTag = 'HashSet';
_this.builder = function () {
return new set_custom_2.HashSetBlockBuilder(_this);
};
_this.blockCapacity = 1 << blockSizeBits;
_this.blockMask = _this.blockCapacity - 1;
_this.maxDepth = Math.ceil(32 / blockSizeBits);
_this._empty = Object.freeze(new set_custom_2.HashSetEmpty(_this));
_this._emptyBlock = Object.freeze(new set_custom_2.HashSetBlock(_this, null, null, 0, 0));
return _this;
}
HashSetContext.prototype.isNonEmptyInstance = function (source) {
return source instanceof set_custom_2.HashSetNonEmptyBase;
};
HashSetContext.prototype.hash = function (value) {
return this.hasher.hash(value);
};
HashSetContext.prototype.getKeyIndex = function (level, hash) {
var shift = this.blockSizeBits * level;
return (hash >>> shift) & this.blockMask;
};
HashSetContext.prototype.emptyBlock = function () {
return this._emptyBlock;
};
HashSetContext.prototype.isValidValue = function (value) {
return this.hasher.isValid(value);
};
HashSetContext.prototype.createBuilder = function (source) {
return new set_custom_2.HashSetBlockBuilder(this, source);
};
HashSetContext.prototype.block = function (entries, entrySets, size, level) {
return new set_custom_2.HashSetBlock(this, entries, entrySets, size, level);
};
HashSetContext.prototype.collision = function (entries) {
return new set_custom_2.HashSetCollision(this, entries);
};
HashSetContext.prototype.isHashSetBlock = function (obj) {
return obj instanceof set_custom_2.HashSetBlock;
};
HashSetContext.prototype.isHashSetCollision = function (obj) {
return obj instanceof set_custom_2.HashSetCollision;
};
HashSetContext.prototype.isHashSetBlockBuilder = function (obj) {
return obj instanceof set_custom_2.HashSetBlockBuilder;
};
return HashSetContext;
}(set_custom_1.RSetBase.ContextBase));
exports.HashSetContext = HashSetContext;
function createHashSetContext(options) {
var _a, _b, _c, _d;
return Object.freeze(new HashSetContext((_a = options === null || options === void 0 ? void 0 : options.hasher) !== null && _a !== void 0 ? _a : index_cjs_1.Hasher.defaultHasher(), (_b = options === null || options === void 0 ? void 0 : options.eq) !== null && _b !== void 0 ? _b : common_1.Eq.defaultEq(), (_c = options === null || options === void 0 ? void 0 : options.blockSizeBits) !== null && _c !== void 0 ? _c : 5, (_d = options === null || options === void 0 ? void 0 : options.listContext) !== null && _d !== void 0 ? _d : list_1.List.defaultContext()));
}
//# sourceMappingURL=context.cjs.map