# AdaptableHeapPriorityQueue

### new AdaptableHeapPriorityQueue()

```typescript
/**
 * Creates an instance of AdaptableHeapPriorityQueue.
 *
 * @param elements List of elements to create the new priority queue with.
 * @param compare Comparison function for element search. Elements are compared as numbers by default.
 */
constructor(elements: K[] | [K, V][] = [], protected compare: CompareFunc<K> = compareAsNumbers)
```

### length

```typescript
length: number
```

Number of elements in the queue. This field is read only.

#### Examples:

```typescript
import { SortedPriorityQueue } from 'ads-js/queues';

const queue = new SortedPriorityQueue();

queue.length === 0; // true
queue.enqueue(1);
queue.length === 1; // true
```

### clear()

```typescript
/**
 * Clears the queue.
 */
clear(): void;
```

### dequeue()

```typescript
/**
 * Removes the first element from the front of the queue and returns it.
 * Throws an error if the queue is empty.
 *
 * @returns Removed element.
 */
dequeue(): T;
```

### enqueue()

```typescript
/**
 * Adds element at the rear of the queue.
 *
 * @param element Element to add.
 */
enqueue(element: T): void;
```

### getFirst()

```typescript
/**
 * Gets element from the front of the queue without its removal.
 *
 * @returns Queue element.
 */
getFirst(): T;
```

### isEmpty()

```typescript
isEmpty(): boolean
```

> Running time O(1)

Checks whether the queue is empty or not.

#### Returns:

TRUE if the queue is empty, FALSE otherwise.

#### Examples:

```typescript
import { SortedPriorityQueue } from 'ads-js/queues';

const queue = new SortedPriorityQueue();

queue.isEmpty(); // true
queue.enqueue(1);
queue.isEmpty(); // false
```

### remove()

```typescript
/**
 * Removes element from the queue by locator and returns it. Throws an error if the queue is empty
 * or the locator is not valid.
 *
 * @param locator Locator of the element.
 * @returns Removed element.
 */
remove(locator: Locator<K | [K, V]>): K | [K, V];
```

### update()

```typescript
/**
 * Updates element in the queue by locator. Throws an error if the locator is not valid.
 *
 * @param locator Locator of the element.
 * @param element The element updatement.
 */
update(locator: Locator<K | [K, V]>, element: K | [K, V]): void;
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://alex-myznikov.gitbook.io/adsjs/api/stacks-and-queues/adaptableheappriorityqueue.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
