UNPKG

express-service-bootstrap

Version:

This is a convenience package for starting a express API with security, health checks, process exits etc.

48 lines 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SortedMap = void 0; //TODO: This is to be moved to a table data structure class SortedMap { constructor(map = new Map(), sortedKeys = new Map()) { this.map = map; this.sortedKeys = sortedKeys; this.maxOrder = 0; } set(key, value, order = undefined) { if (Number.isNaN(order) || (!Number.isSafeInteger(order))) throw new Error('Order must be a valid 32 bit finite number'); if (order !== undefined) { this.maxOrder = Math.max(this.maxOrder, order); } else { order = ++this.maxOrder; } this.map.set(key, value); this.sortedKeys.set(key, order); } get(key) { return this.map.get(key); } sort() { const sortedKeys = Array.from(this.sortedKeys.entries()) .sort((a, b) => a[1] - b[1]); const sortedMap = new Map(); for (const [key, order] of sortedKeys) { const value = this.map.get(key); if (value === undefined) continue; sortedMap.set(key, value); } return sortedMap; } clear() { this.map.clear(); this.sortedKeys.clear(); this.maxOrder = 0; } [Symbol.dispose]() { this.clear(); } } exports.SortedMap = SortedMap; //# sourceMappingURL=sorted-map.js.map