1 | {"version":3,"file":"queue.cjs","sources":["../queue.js"],"sourcesContent":["export class QueueNode {\n constructor () {\n /**\n * @type {QueueNode|null}\n */\n this.next = null\n }\n}\n\n/**\n * @template V\n */\nexport class QueueValue extends QueueNode {\n /**\n * @param {V} v\n */\n constructor (v) {\n super()\n this.v = v\n }\n}\n\n/**\n * @template {QueueNode} N\n */\nexport class Queue {\n constructor () {\n /**\n * @type {N | null}\n */\n this.start = null\n /**\n * @type {N | null}\n */\n this.end = null\n }\n}\n\n/**\n * @note The queue implementation is experimental and unfinished.\n * Don't use this in production yet.\n *\n * @template {QueueNode} N\n * @return {Queue<N>}\n */\nexport const create = () => new Queue()\n\n/**\n * @param {Queue<any>} queue\n */\nexport const isEmpty = queue => queue.start === null\n\n/**\n * @template {Queue<any>} Q\n * @param {Q} queue\n * @param {Q extends Queue<infer N> ? N : never} n\n */\nexport const enqueue = (queue, n) => {\n if (queue.end !== null) {\n queue.end.next = n\n queue.end = n\n } else {\n queue.end = n\n queue.start = n\n }\n}\n\n/**\n * @template {QueueNode} N\n * @param {Queue<N>} queue\n * @return {N | null}\n */\nexport const dequeue = queue => {\n const n = queue.start\n if (n !== null) {\n // @ts-ignore\n queue.start = n.next\n if (queue.start === null) {\n queue.end = null\n }\n return n\n }\n return null\n}\n"],"names":[],"mappings":";;;;AAAO,MAAM,SAAS,CAAC;AACvB,EAAE,WAAW,CAAC,GAAG;AACjB;AACA;AACA;AACA,IAAI,IAAI,CAAC,IAAI,GAAG,KAAI;AACpB,GAAG;AACH,CAAC;AACD;AACA;AACA;AACA;AACO,MAAM,UAAU,SAAS,SAAS,CAAC;AAC1C;AACA;AACA;AACA,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE;AAClB,IAAI,KAAK,GAAE;AACX,IAAI,IAAI,CAAC,CAAC,GAAG,EAAC;AACd,GAAG;AACH,CAAC;AACD;AACA;AACA;AACA;AACO,MAAM,KAAK,CAAC;AACnB,EAAE,WAAW,CAAC,GAAG;AACjB;AACA;AAC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