UNPKG

doubly-linked-list-typed

Version:
29 lines (28 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Range = exports.DFSOperation = void 0; const utils_1 = require("../utils"); var DFSOperation; (function (DFSOperation) { DFSOperation[DFSOperation["VISIT"] = 0] = "VISIT"; DFSOperation[DFSOperation["PROCESS"] = 1] = "PROCESS"; })(DFSOperation = exports.DFSOperation || (exports.DFSOperation = {})); class Range { constructor(low, high, includeLow = true, includeHigh = true) { this.low = low; this.high = high; this.includeLow = includeLow; this.includeHigh = includeHigh; if (!((0, utils_1.isComparable)(low) && (0, utils_1.isComparable)(high))) throw new RangeError('low or high is not comparable'); if (low > high) throw new RangeError('low must be less than or equal to high'); } // Determine whether a key is within the range isInRange(key, comparator) { const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0; const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0; return lowCheck && highCheck; } } exports.Range = Range;