@twinfinity/core
    Preparing search index...

    Class NumberPool

    A pool of integers in a specified range [min, max]. Integers can be popped from the pool and later pushed back so they become available for pop again. When all numbers in range [min, max] have been popped the pool is empty. The pool is optimized to use as little memory as possible with the assumption that push is called a lot less than pop.

    Index

    Constructors

    • Constructor

      Parameters

      • minNumber: number

        Smallest integer available to the pool

      • maxCount: number

        Number of integers available in the pool.

      Returns NumberPool

    Properties

    maxCount: number

    Number of integers available in the pool.

    maxNumber: number

    Maximum integer available in the pool.

    minNumber: number

    Smallest integer available to the pool

    outOfNumbers: number

    Integer that is returned by peek and pop when pool is empty.

    Accessors

    • get availableCount(): number

      Count of integers still available in the pool.

      Returns number

    • get isEmpty(): boolean

      If true then no more integers can be popped from the pool (by calling pop).

      Returns boolean

      true then no more integers can be popped from the pool.

    • get isFull(): boolean

      If true then pool is full.

      Returns boolean

      true if pool is full.

    • get popCount(): number

      Count of integers that have been popped from the pool by calling pop and that have not yet been pushed by into the pool by using push.

      Returns number

    Methods

    • Reset pool. Makes all integers available again.

      Returns void

    • Peek on next integers that will be returned when pop is called popCallCount number of times (default is 1, must be >= 1). If pool would be empty after popCallCount number of calls to pop then outOfNumbers is returned.

      Parameters

      • popCallCount: number = 1

        Default is 1, must be >= 1.

      Returns number

      Next integer that will be returned when pop is called popCallCount number of of times.

    • Pop next available integer. Can be a number that have been pushed by calling push.

      Returns number

      Next available integer. Will be outOfNumbers if pool is empty.

    • Push a integer to the pool. It must previously have been popped by calling pop. A later call to pop may then return it.

      Parameters

      • n: number

        number to push.

      Returns boolean

      true if integer was added to the pool. Otherwise false. Either the integer already existed in the pool or it has never been popped by calling pop.