# 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

### Properties

maxCount
maxNumber
minNumber
outOfNumbers

### Accessors

availableCount
isEmpty
isFull
popCount

### Methods

clear
peek
pop
push

## Constructors

### constructor

- new NumberPool(minNumber: number, maxCount: number): NumberPool

  Constructor

  #### Parameters

  - minNumber: number

    Smallest integer available to the pool

  - maxCount: number

    Number of integers available in the pool.

  #### Returns NumberPool

## Properties

### `Readonly` maxCount

maxCount: number

Number of integers available in the pool.

### `Readonly` maxNumber

maxNumber: number

Maximum integer available in the pool.

### `Readonly` minNumber

minNumber: number

Smallest integer available to the pool

### `Readonly` outOfNumbers

outOfNumbers: number

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

## Accessors

### availableCount

- get availableCount(): number

  Count of integers still available in the pool.

  #### Returns number

### isEmpty

- 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.

### isFull

- get isFull(): boolean

  If `true` then pool is full.

  #### Returns boolean

  `true` if pool is full.

### popCount

- 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

### clear

- clear(): void

  Reset pool. Makes all integers available again.

  #### Returns void

### peek

- peek(popCallCount?: number): number

  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

- pop(): number

  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

- push(n: number): boolean

  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.