📄 tanstack/db/latest/docs/reference/classes/SortedMap

File: SortedMap.md | Updated: 11/15/2025

Source: https://tanstack.com/db/latest/docs/reference/classes/SortedMap



TanStack

DB v0v0

Search...

+ K

Auto

Log In

TanStack StartRC

Docs Examples GitHub Contributors

TanStack Router

Docs Examples GitHub Contributors

TanStack Query

Docs Examples GitHub Contributors

TanStack Table

Docs Examples Github Contributors

TanStack Formnew

Docs Examples Github Contributors

TanStack DBbeta

Docs Github Contributors

TanStack Virtual

Docs Examples Github Contributors

TanStack Paceralpha

Docs Examples Github Contributors

TanStack Storealpha

Docs Examples Github Contributors

TanStack Devtoolsalpha

Docs Github Contributors

More Libraries

Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide

Documentation

Framework

React logo

React

Version

Latest

Search...

+ K

Menu

Getting Started

Guides

Collections

Frameworks

Community

API Reference

Framework

React logo

React

Version

Latest

Menu

Getting Started

Guides

Collections

Frameworks

Community

API Reference

On this page

SortedMap

Copy Markdown

Class: SortedMap<TKey, TValue>
==============================

Defined in: packages/db/src/SortedMap.ts:6

A Map implementation that keeps its entries sorted based on a comparator function

Type Parameters
---------------
### TKey

TKey

The type of keys in the map

### TValue

TValue

The type of values in the map

Constructors
------------
### Constructor

ts

new SortedMap<TKey, TValue>(comparator?): SortedMap<TKey, TValue>;


new SortedMap<TKey, TValue>(comparator?): SortedMap<TKey, TValue>;

Defined in: packages/db/src/SortedMap.ts:16

Creates a new SortedMap instance

#### Parameters ##### comparator?

(a, b) => number

Optional function to compare values for sorting

#### Returns

SortedMap<TKey, TValue>

Accessors
---------
### size #### Get Signature

ts

get size(): number;


get size(): number;

Defined in: packages/db/src/SortedMap.ts:138

Gets the number of key-value pairs in the map

##### Returns

number

Methods
-------
### [iterator]()

ts

iterator: IterableIterator<[TKey, TValue]>;


iterator: IterableIterator<[TKey, TValue]>;

Defined in: packages/db/src/SortedMap.ts:147

Default iterator that returns entries in sorted order

#### Returns

IterableIterator<[TKey, TValue]>

An iterator for the map's entries


### clear()

ts

clear(): void;


clear(): void;

Defined in: packages/db/src/SortedMap.ts:130

Removes all key-value pairs from the map

#### Returns

void


### delete()

ts

delete(key): boolean;


delete(key): boolean;

Defined in: packages/db/src/SortedMap.ts:106

Removes a key-value pair from the map

#### Parameters ##### key

TKey

The key to remove

#### Returns

boolean

True if the key was found and removed, false otherwise


### entries()

ts

entries(): IterableIterator<[TKey, TValue]>;


entries(): IterableIterator<[TKey, TValue]>;

Defined in: packages/db/src/SortedMap.ts:158

Returns an iterator for the map's entries in sorted order

#### Returns

IterableIterator<[TKey, TValue]>

An iterator for the map's entries


### forEach()

ts

forEach(callbackfn): void;


forEach(callbackfn): void;

Defined in: packages/db/src/SortedMap.ts:189

Executes a callback function for each key-value pair in the map in sorted order

#### Parameters ##### callbackfn

(value, key, map) => void

Function to execute for each entry

#### Returns

void


### get()

ts

get(key): TValue | undefined;


get(key): TValue | undefined;

Defined in: packages/db/src/SortedMap.ts:96

Gets a value by its key

#### Parameters ##### key

TKey

The key to look up

#### Returns

TValue | undefined

The value associated with the key, or undefined if not found


### has()

ts

has(key): boolean;


has(key): boolean;

Defined in: packages/db/src/SortedMap.ts:123

Checks if a key exists in the map

#### Parameters ##### key

TKey

The key to check

#### Returns

boolean

True if the key exists, false otherwise


### keys()

ts

keys(): IterableIterator<TKey>;


keys(): IterableIterator<TKey>;

Defined in: packages/db/src/SortedMap.ts:167

Returns an iterator for the map's keys in sorted order

#### Returns

IterableIterator<TKey>

An iterator for the map's keys


### set()

ts

set(key, value): this;


set(key, value): this;

Defined in: packages/db/src/SortedMap.ts:73

Sets a key-value pair in the map and maintains sort order

#### Parameters ##### key

TKey

The key to set

##### value

TValue

The value to associate with the key

#### Returns

this

This SortedMap instance for chaining


### values()

ts

values(): IterableIterator<TValue>;


values(): IterableIterator<TValue>;

Defined in: packages/db/src/SortedMap.ts:176

Returns an iterator for the map's values in sorted order

#### Returns

IterableIterator<TValue>

An iterator for the map's values

Edit on GitHub

Home

Partners Become a Partner

Code RabbitCode Rabbit CloudflareCloudflare AG GridAG Grid NetlifyNetlify NeonNeon WorkOSWorkOS ClerkClerk ConvexConvex ElectricElectric SentrySentry PrismaPrisma StrapiStrapi UnkeyUnkey

scarf analytics