---
description: >-
  Container which stores only pairs forming strictly increasing trend in both
  keys and values. This structure is based on SortedMap.
---

# MaximaSet

### new MaximaSet()

```typescript
/**
 * Creates an instance of MaximaSet.
 *
 * @param iterable Iterable of X, Y pairs to create the new maxima set with.
 * @param compareX Comparison function for pairs sorting by X values. Xs are compared as numbers by default.
 * @param compareY Comparison function for pairs sorting by Y values. Ys are compared as numbers by default.
 */
constructor(
  iterable: Iterable<[X, Y]> = [],
  protected compareX: CompareFunc<X> = compareAsNumbers,
  protected compareY: CompareFunc<Y> = compareAsNumbers,
)
```

### length

```typescript
/**
 * Number of pairs in the set.
 *
 * @readonly
 */
get length(): number;
```

### add()

```typescript
/**
 * Adds X, Y pair to the maxima set if there is no better pair in it.
 *
 * @param x X value.
 * @param y Y value.
 */
add(x: X, y: Y)
```

### getBest()

```typescript
/**
 * Gets X, Y pair with largest X not exceeding the specified value.
 *
 * @param x X value.
 * @returns X, Y pair or undefined if the set is empty.
 */
getBest(x: X): [X, Y] | undefined
```

### clear()

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

### getFirst()

```typescript
/**
 * Gets X, Y pair with least X.
 *
 * @returns X, Y pair or undefined if the set is empty.
 */
getFirst(): [X, Y] | undefined;
```

### getLast()

```typescript
/**
 * Gets X, Y pair with greatest X.
 *
 * @returns X, Y pair or undefined if the set is empty.
 */
getLast(): [X, Y] | undefined;
```

### isEmpty()

```typescript
/**
 * Checks whether the set is empty or not.
 *
 * @returns TRUE if the map is empty, FALSE otherwise.
 */
isEmpty(): boolean;
```

### \[Symbol.iterator]\()

```typescript
[Symbol.iterator](): IterableIterator<[X, Y]>
```
