@rimbu/hashed
Version:
Immutable HashMap and HashSet implementations for TypeScript
68 lines • 3.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HashMapContext = void 0;
exports.createHashMapContext = createHashMapContext;
var tslib_1 = require("tslib");
var map_custom_1 = require("@rimbu/collection-types/map-custom");
var common_1 = require("@rimbu/common");
var list_1 = require("@rimbu/list");
var index_cjs_1 = require("../../common/index.cjs");
var map_custom_2 = require("@rimbu/hashed/map-custom");
var HashMapContext = /** @class */ (function (_super) {
tslib_1.__extends(HashMapContext, _super);
function HashMapContext(hasher, eq, blockSizeBits, listContext) {
var _this = _super.call(this) || this;
_this.hasher = hasher;
_this.eq = eq;
_this.blockSizeBits = blockSizeBits;
_this.listContext = listContext;
_this.typeTag = 'HashMap';
_this.builder = function () {
return new map_custom_2.HashMapBlockBuilder(_this);
};
_this.blockCapacity = 1 << blockSizeBits;
_this.blockMask = _this.blockCapacity - 1;
_this.maxDepth = Math.ceil(32 / blockSizeBits);
_this._empty = Object.freeze(new map_custom_2.HashMapEmpty(_this));
_this._emptyBlock = Object.freeze(new map_custom_2.HashMapBlock(_this, null, null, 0, 0));
return _this;
}
HashMapContext.prototype.hash = function (value) {
return this.hasher.hash(value);
};
HashMapContext.prototype.getKeyIndex = function (level, hash) {
var shift = this.blockSizeBits * level;
return (hash >>> shift) & this.blockMask;
};
HashMapContext.prototype.isNonEmptyInstance = function (source) {
return source instanceof map_custom_2.HashMapNonEmptyBase;
};
HashMapContext.prototype.createBuilder = function (source) {
return new map_custom_2.HashMapBlockBuilder(this, source);
};
HashMapContext.prototype.isValidKey = function (key) {
return this.hasher.isValid(key);
};
HashMapContext.prototype.emptyBlock = function () {
return this._emptyBlock;
};
HashMapContext.prototype.block = function (entries, entrySets, size, level) {
return new map_custom_2.HashMapBlock(this, entries, entrySets, size, level);
};
HashMapContext.prototype.collision = function (entries) {
return new map_custom_2.HashMapCollision(this, entries);
};
HashMapContext.prototype.isHashMapBlock = function (obj) {
return obj instanceof map_custom_2.HashMapBlock;
};
HashMapContext.prototype.isHashMapBlockBuilder = function (obj) {
return obj instanceof map_custom_2.HashMapBlockBuilder;
};
return HashMapContext;
}(map_custom_1.RMapBase.ContextBase));
exports.HashMapContext = HashMapContext;
function createHashMapContext(options) {
var _a, _b, _c, _d;
return Object.freeze(new HashMapContext((_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