UNPKG

@rimbu/hashed

Version:

Immutable HashMap and HashSet implementations for TypeScript

57 lines 1.74 kB
import { TraverseState } from '@rimbu/common'; import { List } from '@rimbu/list'; export class BlockBuilderBase { get isEmpty() { return this.size === 0; } forEach(f, options = {}) { const { state = TraverseState() } = options; if (this.isEmpty || state.halted) return; if (undefined !== this.source) return this.source.forEach(f, { state }); const { halt } = state; if (undefined !== this._entries) { for (const key in this._entries) { f(this._entries[key], state.nextIndex(), halt); if (state.halted) break; } } if (undefined !== this._entrySets) { for (const key in this._entrySets) { this._entrySets[key].forEach(f, { state }); if (state.halted) break; } } } } export class CollisionBuilderBase { get size() { if (undefined !== this.source) return this.source.size; return this.entries.length; } get entries() { if (undefined === this._entries) { if (undefined !== this.source) { this._entries = this.source.entries.toBuilder(); } else { this._entries = List.builder(); } } return this._entries; } forEach(f, options = {}) { const { state = TraverseState() } = options; if (state.halted) return; if (undefined !== this.source) { return this.source.forEach(f, { state }); } this.entries.forEach(f, { state }); } } //# sourceMappingURL=hashed-custom.mjs.map