# DenseIntegerPriorityQueue

Defined in: [packages/heap/src/dense-integer-priority-queue.ts:12](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/dense-integer-priority-queue.ts#L12)

A minimum queue of numeric keys over a fixed domain of integer values.

## Extends

* [`PriorityQueueSurface`](/reference/knotkit/heap/interfaces/priorityqueuesurface/)<`number`, `number`>

## Properties

### kind

> `readonly` **kind**: `"dense-integer-priority-queue-min"`

Defined in: [packages/heap/src/dense-integer-priority-queue.ts:13](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/dense-integer-priority-queue.ts#L13)

***

### capacity

> `readonly` **capacity**: `number`

Defined in: [packages/heap/src/dense-integer-priority-queue.ts:15](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/dense-integer-priority-queue.ts#L15)

Exclusive upper bound on a value. O(1).

***

### push

> `readonly` **push**: (`key`, `value`) => `void`

Defined in: [packages/heap/src/dense-integer-priority-queue.ts:21](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/dense-integer-priority-queue.ts#L21)

Insert a value by key. O(log(size + 1)).

#### Parameters

##### key

`number`

##### value

`number`

#### Returns

`void`

#### Throws

With `INVALID_VALUE` outside the declared domain or `DUPLICATE_VALUE` while the value is resident.

#### Overrides

[`PriorityQueueSurface`](/reference/knotkit/heap/interfaces/priorityqueuesurface/).[`push`](/reference/knotkit/heap/interfaces/priorityqueuesurface/#push)

***

### size

> `readonly` **size**: `number`

Defined in: [packages/heap/src/priority-queue.ts:80](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/priority-queue.ts#L80)

Number of entries. O(1). The queue is empty when this is `0`.

#### Inherited from

[`PriorityQueueSurface`](/reference/knotkit/heap/interfaces/priorityqueuesurface/).[`size`](/reference/knotkit/heap/interfaces/priorityqueuesurface/#size)

***

### peek

> `readonly` **peek**: () => `number`

Defined in: [packages/heap/src/priority-queue.ts:89](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/priority-queue.ts#L89)

Return the value of the extreme entry — minimum key for min kinds, maximum key for max kinds — without removing it. O(1).

Property syntax for the same variance reason as [push](/reference/knotkit/heap/interfaces/priorityqueuesurface/#push).

#### Returns

`number`

#### Throws

With code `EMPTY` when the queue is empty.

#### Inherited from

[`PriorityQueueSurface`](/reference/knotkit/heap/interfaces/priorityqueuesurface/).[`peek`](/reference/knotkit/heap/interfaces/priorityqueuesurface/#peek)

***

### peekEntry

> `readonly` **peekEntry**: () => readonly \[`number`, `number`]

Defined in: [packages/heap/src/priority-queue.ts:99](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/priority-queue.ts#L99)

Return a fresh `readonly [key, value]` tuple for the extreme entry, without removing it. O(1). Each call allocates its own tuple, so mutating a returned tuple cannot corrupt the queue.

Property syntax for the same variance reason as [push](/reference/knotkit/heap/interfaces/priorityqueuesurface/#push).

#### Returns

readonly \[`number`, `number`]

#### Throws

With code `EMPTY` when the queue is empty.

#### Inherited from

[`PriorityQueueSurface`](/reference/knotkit/heap/interfaces/priorityqueuesurface/).[`peekEntry`](/reference/knotkit/heap/interfaces/priorityqueuesurface/#peekentry)

***

### pop

> `readonly` **pop**: () => `number`

Defined in: [packages/heap/src/priority-queue.ts:108](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/priority-queue.ts#L108)

Remove and return the value of the extreme entry. O(log n) binary, O(k log_k n) k-ary.

Property syntax for the same variance reason as [push](/reference/knotkit/heap/interfaces/priorityqueuesurface/#push).

#### Returns

`number`

#### Throws

With code `EMPTY` when the queue is empty.

#### Inherited from

[`PriorityQueueSurface`](/reference/knotkit/heap/interfaces/priorityqueuesurface/).[`pop`](/reference/knotkit/heap/interfaces/priorityqueuesurface/#pop)

***

### popEntry

> `readonly` **popEntry**: () => readonly \[`number`, `number`]

Defined in: [packages/heap/src/priority-queue.ts:118](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/priority-queue.ts#L118)

Remove the extreme entry and return a fresh `readonly [key, value]` tuple for it. Same cost and freshness contract as [pop](/reference/knotkit/heap/interfaces/priorityqueuesurface/#pop) and [peekEntry](/reference/knotkit/heap/interfaces/priorityqueuesurface/#peekentry).

Property syntax for the same variance reason as [push](/reference/knotkit/heap/interfaces/priorityqueuesurface/#push).

#### Returns

readonly \[`number`, `number`]

#### Throws

With code `EMPTY` when the queue is empty.

#### Inherited from

[`PriorityQueueSurface`](/reference/knotkit/heap/interfaces/priorityqueuesurface/).[`popEntry`](/reference/knotkit/heap/interfaces/priorityqueuesurface/#popentry)

***

### updateKey

> `readonly` **updateKey**: (`key`, `value`) => `void`

Defined in: [packages/heap/src/priority-queue.ts:143](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/priority-queue.ts#L143)

Replace the key of a resident value and restore the heap invariant in the one direction the change requires. O(log n) binary, O(k log_k n) k-ary; O(1) when the new key compares equal to the old, in which case nothing moves and only the stored key (the whole entry object) is replaced.

Property syntax for the same variance reason as [push](/reference/knotkit/heap/interfaces/priorityqueuesurface/#push).

#### Parameters

##### key

`number`

##### value

`number`

#### Returns

`void`

#### Throws

With code `VALUE_NOT_FOUND` when `value` is not resident.

#### Inherited from

[`PriorityQueueSurface`](/reference/knotkit/heap/interfaces/priorityqueuesurface/).[`updateKey`](/reference/knotkit/heap/interfaces/priorityqueuesurface/#updatekey)

***

### keyOf

> `readonly` **keyOf**: (`value`) => `number`

Defined in: [packages/heap/src/priority-queue.ts:152](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/priority-queue.ts#L152)

Return the key currently stored for `value`. O(1) average.

Property syntax for the same variance reason as [push](/reference/knotkit/heap/interfaces/priorityqueuesurface/#push).

#### Parameters

##### value

`number`

#### Returns

`number`

#### Throws

With code `VALUE_NOT_FOUND` when `value` is not resident.

#### Inherited from

[`PriorityQueueSurface`](/reference/knotkit/heap/interfaces/priorityqueuesurface/).[`keyOf`](/reference/knotkit/heap/interfaces/priorityqueuesurface/#keyof)

***

### has

> `readonly` **has**: (`value`) => `boolean`

Defined in: [packages/heap/src/priority-queue.ts:158](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/priority-queue.ts#L158)

Return `true` when `value` is resident. O(1) average.

Property syntax for the same variance reason as [push](/reference/knotkit/heap/interfaces/priorityqueuesurface/#push).

#### Parameters

##### value

`number`

#### Returns

`boolean`

#### Inherited from

[`PriorityQueueSurface`](/reference/knotkit/heap/interfaces/priorityqueuesurface/).[`has`](/reference/knotkit/heap/interfaces/priorityqueuesurface/#has)

***

### clear

> `readonly` **clear**: () => `void`

Defined in: [packages/heap/src/priority-queue.ts:166](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/priority-queue.ts#L166)

Remove every entry, keeping the kind, arity, and key order. O(n): the value index is released along with the entries. Every previously resident value can be pushed again.

Property syntax for the same variance reason as [push](/reference/knotkit/heap/interfaces/priorityqueuesurface/#push).

#### Returns

`void`

#### Inherited from

[`PriorityQueueSurface`](/reference/knotkit/heap/interfaces/priorityqueuesurface/).[`clear`](/reference/knotkit/heap/interfaces/priorityqueuesurface/#clear)

***

### entries

> `readonly` **entries**: () => `IterableIterator`\<readonly \[`number`, `number`]>

Defined in: [packages/heap/src/priority-queue.ts:178](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/priority-queue.ts#L178)

Walk the entries lazily as fresh `readonly [key, value]` tuples in internal heap-array order, which is neither sorted nor insertion order: the extreme entry comes first and every parent precedes its children. O(n) for a full walk, O(1) extra space besides each yielded tuple. Does not mutate the queue. The walk reads the live array, so changing the queue while a walk is open is unsupported: the walk still ends, but which entries it yields is unspecified.

Property syntax for the same variance reason as [push](/reference/knotkit/heap/interfaces/priorityqueuesurface/#push).

#### Returns

`IterableIterator`\<readonly \[`number`, `number`]>

#### Inherited from

[`PriorityQueueSurface`](/reference/knotkit/heap/interfaces/priorityqueuesurface/).[`entries`](/reference/knotkit/heap/interfaces/priorityqueuesurface/#entries)

***

### \[iterator]

> `readonly` **\[iterator]**: () => `IterableIterator`\<readonly \[`number`, `number`]>

Defined in: [packages/heap/src/priority-queue.ts:180](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/priority-queue.ts#L180)

The same walk as [entries](/reference/knotkit/heap/interfaces/priorityqueuesurface/#entries), as the same function, so `for (const [key, value] of queue)` works.

#### Returns

`IterableIterator`\<readonly \[`number`, `number`]>

#### Inherited from

[`PriorityQueueSurface`](/reference/knotkit/heap/interfaces/priorityqueuesurface/).[`[iterator]`](/reference/knotkit/heap/interfaces/priorityqueuesurface/#iterator)
