# Heap | data-structure-typed
Documentation for data-structure-typed

# Class Heap<T>`Abstract`

#### Type Parameters

- #### T = number

#### Hierarchy

- Heap
  - MaxHeap
  - MinHeap

- Defined in src/data-structures/heap/heap.ts:45

#####
Index

### Constructors

constructor

### Properties

_pq
_priorityExtractor

### Accessors

pq
priorityExtractor
size

### Methods

add
clear
has
isEmpty
peek
peekLast
poll
sort
toArray

## Constructors

### `Protected` constructor

- new Heap<T>(options?): Heap <T>

- The function is a constructor for a class that initializes a priority callback function based on the options provided.

  #### Type Parameters

  - #### T = number

  #### Parameters

  - ##### `Optional` options: HeapOptions <T>

    An optional object that contains configuration options for the Heap.

  #### Returns Heap <T>

  - Defined in src/data-structures/heap/heap.ts:51

## Properties

### `Protected` `Abstract` _pq

_pq: PriorityQueue < HeapItem <T>>

- Defined in src/data-structures/heap/heap.ts:63

### `Protected` _priorityExtractor

_priorityExtractor: ((val) => number)

#### Type declaration

- - (val): number

  - #### Parameters

    - ##### val: T

    #### Returns number

- Defined in src/data-structures/heap/heap.ts:69

## Accessors

### pq

- get pq(): PriorityQueue < HeapItem <T>>

- #### Returns PriorityQueue < HeapItem <T>>

  - Defined in src/data-structures/heap/heap.ts:65

### priorityExtractor

- get priorityExtractor(): ((val) => number)

- #### Returns ((val) => number)

  - - (val): number

    - #### Parameters

      - ##### val: T

      #### Returns number

  - Defined in src/data-structures/heap/heap.ts:70

### size

- get size(): number

- The function returns the size of a priority queue.

  #### Returns number

  The size of the priority queue.

  - Defined in src/data-structures/heap/heap.ts:78

## Methods

### add

- add(priority?, val?): Heap <T>

- The `add` function adds an val to a priority queue with an optional priority value.

  #### Parameters

  - ##### `Optional` priority: number

    The `priority` parameter is an optional number that represents the priority of the val being added to the heap. If the `val` parameter is a number, then the `priority` parameter is set to the value of `val`. If the `val` parameter is not a number, then the

  - ##### `Optional` val: T

    The `val` parameter represents the value that you want to add to the heap. It can be of any type.

  #### Returns Heap <T>

  The `add` method returns the instance of the `Heap` class.

  #### Throws

  if priority is not a valid number

  - Defined in src/data-structures/heap/heap.ts:130

### clear

- clear(): void

- The clear function clears the priority queue.

  #### Returns void

  - Defined in src/data-structures/heap/heap.ts:209

### has

- has(node): boolean

- The function checks if a given node or value exists in the priority queue.

  #### Parameters

  - ##### node: T | HeapItem <T>

    The parameter `node` can be of type `T` or `HeapItem<T>`.

  #### Returns boolean

  a boolean value.

  - Defined in src/data-structures/heap/heap.ts:160

### isEmpty

- isEmpty(): boolean

- The function checks if a priority queue is empty.

  #### Returns boolean

  A boolean value indicating whether the size of the priority queue is less than 1.

  - Defined in src/data-structures/heap/heap.ts:86

### peek

- peek(isItem?): undefined | T

- The `peek` function returns the top item in the priority queue without removing it.

  #### Parameters

  - ##### `Optional` isItem: undefined

  #### Returns undefined | T

  The `peek()` method is returning either a `HeapItem<T>` object or `null`.Returns an val with the highest priority in the queue

  - Defined in src/data-structures/heap/heap.ts:90
- peek(isItem): undefined | T

- The `peek` function returns the top item in the priority queue without removing it.

  #### Parameters

  - ##### isItem: false

  #### Returns undefined | T

  The `peek()` method is returning either a `HeapItem<T>` object or `null`.Returns an val with the highest priority in the queue

  - Defined in src/data-structures/heap/heap.ts:91
- peek(isItem): null | HeapItem <T>

- The `peek` function returns the top item in the priority queue without removing it.

  #### Parameters

  - ##### isItem: true

  #### Returns null | HeapItem <T>

  The `peek()` method is returning either a `HeapItem<T>` object or `null`.Returns an val with the highest priority in the queue

  - Defined in src/data-structures/heap/heap.ts:92

### peekLast

- peekLast(isItem?): undefined | T

- The `peekLast` function returns the last item in the heap.

  #### Parameters

  - ##### `Optional` isItem: undefined

  #### Returns undefined | T

  The method `peekLast()` returns either a `HeapItem<T>` object or `null`.Returns an val with the lowest priority in the queue

  - Defined in src/data-structures/heap/heap.ts:105
- peekLast(isItem): undefined | T

- The `peekLast` function returns the last item in the heap.

  #### Parameters

  - ##### isItem: false

  #### Returns undefined | T

  The method `peekLast()` returns either a `HeapItem<T>` object or `null`.Returns an val with the lowest priority in the queue

  - Defined in src/data-structures/heap/heap.ts:106
- peekLast(isItem): null | HeapItem <T>

- The `peekLast` function returns the last item in the heap.

  #### Parameters

  - ##### isItem: true

  #### Returns null | HeapItem <T>

  The method `peekLast()` returns either a `HeapItem<T>` object or `null`.Returns an val with the lowest priority in the queue

  - Defined in src/data-structures/heap/heap.ts:107

### poll

- poll(isItem?): undefined | T

- The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an val with the highest priority in the queue

  #### Parameters

  - ##### `Optional` isItem: undefined

  #### Returns undefined | T

  either a HeapItem<T> object or null.

  - Defined in src/data-structures/heap/heap.ts:137
- poll(isItem): undefined | T

- The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an val with the highest priority in the queue

  #### Parameters

  - ##### isItem: false

  #### Returns undefined | T

  either a HeapItem<T> object or null.

  - Defined in src/data-structures/heap/heap.ts:138
- poll(isItem): null | HeapItem <T>

- The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an val with the highest priority in the queue

  #### Parameters

  - ##### isItem: true

  #### Returns null | HeapItem <T>

  either a HeapItem<T> object or null.

  - Defined in src/data-structures/heap/heap.ts:139

### sort

- sort(isItem?): (undefined | T)[]

- The function sorts the elements in the priority queue and returns either the sorted items or their values depending on the value of the isItem parameter.

  #### Parameters

  - ##### `Optional` isItem: undefined

    The `isItem` parameter is a boolean flag that indicates whether the sorted result should be an array of `HeapItem<T>` objects or an array of the values (`T`) of those objects. If `isItem` is `true`, the sorted result will be an array of `HeapItem @returns an array of either` HeapItem<T>`,` null`,` T`, or` undefined` values.

  #### Returns (undefined | T)[]

  - Defined in src/data-structures/heap/heap.ts:187
- sort(isItem): (undefined | T)[]

- The function sorts the elements in the priority queue and returns either the sorted items or their values depending on the value of the isItem parameter.

  #### Parameters

  - ##### isItem: false

    The `isItem` parameter is a boolean flag that indicates whether the sorted result should be an array of `HeapItem<T>` objects or an array of the values (`T`) of those objects. If `isItem` is `true`, the sorted result will be an array of `HeapItem @returns an array of either` HeapItem<T>`,` null`,` T`, or` undefined` values.

  #### Returns (undefined | T)[]

  - Defined in src/data-structures/heap/heap.ts:188
- sort(isItem): (null | HeapItem <T>)[]

- The function sorts the elements in the priority queue and returns either the sorted items or their values depending on the value of the isItem parameter.

  #### Parameters

  - ##### isItem: true

    The `isItem` parameter is a boolean flag that indicates whether the sorted result should be an array of `HeapItem<T>` objects or an array of the values (`T`) of those objects. If `isItem` is `true`, the sorted result will be an array of `HeapItem @returns an array of either` HeapItem<T>`,` null`,` T`, or` undefined` values.

  #### Returns (null | HeapItem <T>)[]

  - Defined in src/data-structures/heap/heap.ts:189

### toArray

- toArray(isItem?): (undefined | T)[]

- The `toArray` function returns an array of `HeapItem<T>` objects.

  #### Parameters

  - ##### `Optional` isItem: undefined

  #### Returns (undefined | T)[]

  An array of HeapItem<T> objects.Returns a sorted list of vals

  - Defined in src/data-structures/heap/heap.ts:172
- toArray(isItem): (undefined | T)[]

- The `toArray` function returns an array of `HeapItem<T>` objects.

  #### Parameters

  - ##### isItem: false

  #### Returns (undefined | T)[]

  An array of HeapItem<T> objects.Returns a sorted list of vals

  - Defined in src/data-structures/heap/heap.ts:173
- toArray(isItem): (null | HeapItem <T>)[]

- The `toArray` function returns an array of `HeapItem<T>` objects.

  #### Parameters

  - ##### isItem: true

  #### Returns (null | HeapItem <T>)[]

  An array of HeapItem<T> objects.Returns a sorted list of vals

  - Defined in src/data-structures/heap/heap.ts:174

Generated using TypeDoc