"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Bounded = exports.Unbounded = void 0;
// ets_tracing: off
require("../../Operator");
const Chunk = __importStar(require("../../Collections/Immutable/Chunk/core"));
const DoublyLinkedList_1 = require("../DoublyLinkedList");
class Unbounded {
    constructor() {
        this.queue = new DoublyLinkedList_1.DoublyLinkedList();
    }
    get size() {
        return this.queue.length;
    }
    get isEmpty() {
        return this.size === 0;
    }
    get isFull() {
        return false;
    }
    get capacity() {
        return Number.MAX_SAFE_INTEGER;
    }
    offer(a) {
        this.queue.add(a);
        return true;
    }
    offerAll(as) {
        for (const a of as) {
            this.offer(a);
        }
        return Chunk.empty();
    }
    poll(a) {
        if (this.isEmpty) {
            return a;
        }
        return this.queue.shift();
    }
    pollUpTo(n) {
        let result = Chunk.empty();
        let count = 0;
        while (count < n) {
            const elem = this.poll(undefined);
            if (elem === undefined) {
                break;
            }
            result = Chunk.append_(result, elem);
            count += 1;
        }
        return result;
    }
}
exports.Unbounded = Unbounded;
class Bounded {
    constructor(n) {
        this.queue = new DoublyLinkedList_1.DoublyLinkedList();
        this.n = n;
    }
    get size() {
        return this.queue.length;
    }
    get isEmpty() {
        return this.size === 0;
    }
    get isFull() {
        return this.size === this.capacity;
    }
    get capacity() {
        return this.n;
    }
    offer(a) {
        if (this.isFull) {
            return false;
        }
        this.queue.add(a);
        return true;
    }
    offerAll(as) {
        const it = as[Symbol.iterator]();
        let next;
        let rem = Chunk.empty();
        let offerig = true;
        while (offerig && (next = it.next()) && !next.done) {
            offerig = this.offer(next.value);
        }
        while (next && !next.done) {
            rem = Chunk.append_(rem, next.value);
            next = it.next();
        }
        return rem;
    }
    poll(a) {
        if (this.isEmpty) {
            return a;
        }
        return this.queue.shift();
    }
    pollUpTo(n) {
        let result = Chunk.empty();
        let count = 0;
        while (count < n) {
            const elem = this.poll(undefined);
            if (elem === undefined) {
                break;
            }
            result = Chunk.append_(result, elem);
            count += 1;
        }
        return result;
    }
}
exports.Bounded = Bounded;
//# sourceMappingURL=index.js.map