@rimbu/hashed
Version:
Immutable HashMap and HashSet implementations for TypeScript
90 lines • 3.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CollisionBuilderBase = exports.BlockBuilderBase = void 0;
var common_1 = require("@rimbu/common");
var list_1 = require("@rimbu/list");
/**
* Base class for mutable builders that construct hash blocks for hashed collections.
* @typeparam E - the entry type stored in the block
*/
var BlockBuilderBase = /** @class */ (function () {
function BlockBuilderBase() {
}
Object.defineProperty(BlockBuilderBase.prototype, "isEmpty", {
get: function () {
return this.size === 0;
},
enumerable: false,
configurable: true
});
BlockBuilderBase.prototype.forEach = function (f, options) {
if (options === void 0) { options = {}; }
var _a = options.state, state = _a === void 0 ? (0, common_1.TraverseState)() : _a;
if (this.isEmpty || state.halted)
return;
if (undefined !== this.source)
return this.source.forEach(f, { state: state });
var halt = state.halt;
if (undefined !== this._entries) {
for (var key in this._entries) {
f(this._entries[key], state.nextIndex(), halt);
if (state.halted)
break;
}
}
if (undefined !== this._entrySets) {
for (var key in this._entrySets) {
this._entrySets[key].forEach(f, { state: state });
if (state.halted)
break;
}
}
};
return BlockBuilderBase;
}());
exports.BlockBuilderBase = BlockBuilderBase;
/**
* Base class for mutable builders that handle hash collisions in hashed collections.
* @typeparam E - the entry type contained in the collision bucket
*/
var CollisionBuilderBase = /** @class */ (function () {
function CollisionBuilderBase() {
}
Object.defineProperty(CollisionBuilderBase.prototype, "size", {
get: function () {
if (undefined !== this.source)
return this.source.size;
return this.entries.length;
},
enumerable: false,
configurable: true
});
Object.defineProperty(CollisionBuilderBase.prototype, "entries", {
get: function () {
if (undefined === this._entries) {
if (undefined !== this.source) {
this._entries = this.source.entries.toBuilder();
}
else {
this._entries = list_1.List.builder();
}
}
return this._entries;
},
enumerable: false,
configurable: true
});
CollisionBuilderBase.prototype.forEach = function (f, options) {
if (options === void 0) { options = {}; }
var _a = options.state, state = _a === void 0 ? (0, common_1.TraverseState)() : _a;
if (state.halted)
return;
if (undefined !== this.source) {
return this.source.forEach(f, { state: state });
}
this.entries.forEach(f, { state: state });
};
return CollisionBuilderBase;
}());
exports.CollisionBuilderBase = CollisionBuilderBase;
//# sourceMappingURL=hashed-custom.cjs.map