UNPKG

lazzy.ts

Version:

Fast and lightweight library for lazy operations with iterable objects.

75 lines 3.85 kB
"use strict"; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var _Queue_head, _Queue_tail, _Queue_count, _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.Queue = void 0; const node_1 = require("./node"); class Queue { constructor() { _Queue_head.set(this, void 0); _Queue_tail.set(this, void 0); _Queue_count.set(this, 0); this[_a] = () => { let current = __classPrivateFieldGet(this, _Queue_tail, "f"); return { next: function () { if (current == null) { return { done: true, value: undefined }; } const value = current.value; current = current.right; return { done: false, value }; } }; }; } count() { return __classPrivateFieldGet(this, _Queue_count, "f"); } isEmpty() { return __classPrivateFieldGet(this, _Queue_count, "f") === 0; } isNotEmpty() { return __classPrivateFieldGet(this, _Queue_count, "f") > 0; } enqueue(value) { const newNode = new node_1.Node(value); if (__classPrivateFieldGet(this, _Queue_head, "f") == null || __classPrivateFieldGet(this, _Queue_tail, "f") == null) { __classPrivateFieldSet(this, _Queue_head, newNode, "f"); __classPrivateFieldSet(this, _Queue_tail, newNode, "f"); __classPrivateFieldSet(this, _Queue_count, +__classPrivateFieldGet(this, _Queue_count, "f") + 1, "f"); return; } const oldHead = __classPrivateFieldGet(this, _Queue_head, "f"); oldHead.right = newNode; newNode.left = oldHead; __classPrivateFieldSet(this, _Queue_head, newNode, "f"); __classPrivateFieldSet(this, _Queue_count, +__classPrivateFieldGet(this, _Queue_count, "f") + 1, "f"); } ; dequeue() { var _b; const tail = __classPrivateFieldGet(this, _Queue_tail, "f"); if (__classPrivateFieldGet(this, _Queue_tail, "f") == __classPrivateFieldGet(this, _Queue_head, "f")) { __classPrivateFieldSet(this, _Queue_head, undefined, "f"); } __classPrivateFieldSet(this, _Queue_tail, (_b = __classPrivateFieldGet(this, _Queue_tail, "f")) === null || _b === void 0 ? void 0 : _b.right, "f"); if (__classPrivateFieldGet(this, _Queue_count, "f") > 0) { __classPrivateFieldSet(this, _Queue_count, +__classPrivateFieldGet(this, _Queue_count, "f") - 1, "f"); } return tail === null || tail === void 0 ? void 0 : tail.value; } } exports.Queue = Queue; _Queue_head = new WeakMap(), _Queue_tail = new WeakMap(), _Queue_count = new WeakMap(), _a = Symbol.iterator; //# sourceMappingURL=queue.js.map