# SortedBlock

Defined in: [packages/sorted-block/src/sorted-block.ts:29](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/sorted-block/src/sorted-block.ts#L29)

An immutable sorted key-value block held in one `Uint8Array`.

Keys are distinct and ascend under `compareBytes`. Every read returns fresh copies of the bytes it reports, so a caller can mutate what it receives without changing the block, and the block owns a copy of every byte it was built from. A block never changes after construction, so its iterators never observe a modification.

## Properties

### kind

> `readonly` **kind**: `"restart-point"`

Defined in: [packages/sorted-block/src/sorted-block.ts:30](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/sorted-block/src/sorted-block.ts#L30)

***

### size

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

Defined in: [packages/sorted-block/src/sorted-block.ts:32](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/sorted-block/src/sorted-block.ts#L32)

Number of entries.

***

### byteLength

> `readonly` **byteLength**: `number`

Defined in: [packages/sorted-block/src/sorted-block.ts:34](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/sorted-block/src/sorted-block.ts#L34)

Bytes of the encoded block payload: entries, restart table, and trailer.

***

### firstKey

> `readonly` **firstKey**: `Uint8Array`<`ArrayBufferLike`> | `undefined`

Defined in: [packages/sorted-block/src/sorted-block.ts:36](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/sorted-block/src/sorted-block.ts#L36)

A copy of the smallest key, or `undefined` for an empty block.

***

### lastKey

> `readonly` **lastKey**: `Uint8Array`<`ArrayBufferLike`> | `undefined`

Defined in: [packages/sorted-block/src/sorted-block.ts:38](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/sorted-block/src/sorted-block.ts#L38)

A copy of the largest key, or `undefined` for an empty block.

***

### get

> `readonly` **get**: (`key`) => `Uint8Array`<`ArrayBufferLike`> | `undefined`

Defined in: [packages/sorted-block/src/sorted-block.ts:44](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/sorted-block/src/sorted-block.ts#L44)

A copy of the value stored under `key`, or `undefined` when the block holds no such key.

#### Parameters

##### key

`Uint8Array`

#### Returns

`Uint8Array`<`ArrayBufferLike`> | `undefined`

#### Throws

With `INVALID_KEY` when `key` is not a `Uint8Array`.

***

### has

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

Defined in: [packages/sorted-block/src/sorted-block.ts:50](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/sorted-block/src/sorted-block.ts#L50)

Whether the block holds `key`.

#### Parameters

##### key

`Uint8Array`

#### Returns

`boolean`

#### Throws

With `INVALID_KEY` when `key` is not a `Uint8Array`.

***

### ceiling

> `readonly` **ceiling**: (`key`) => [`SortedBlockEntry`](/reference/knotkit/sorted-block/type-aliases/sortedblockentry/) | `undefined`

Defined in: [packages/sorted-block/src/sorted-block.ts:57](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/sorted-block/src/sorted-block.ts#L57)

A copy of the smallest entry whose key is at or above `key` under `compareBytes`, or `undefined` when every key sorts below it.

#### Parameters

##### key

`Uint8Array`

#### Returns

[`SortedBlockEntry`](/reference/knotkit/sorted-block/type-aliases/sortedblockentry/) | `undefined`

#### Throws

With `INVALID_KEY` when `key` is not a `Uint8Array`.

***

### entries

> `readonly` **entries**: (…`bounds`) => `IterableIterator`<[`SortedBlockEntry`](/reference/knotkit/sorted-block/type-aliases/sortedblockentry/)>

Defined in: [packages/sorted-block/src/sorted-block.ts:65](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/sorted-block/src/sorted-block.ts#L65)

Walk entries in ascending key order: every entry, the open range `[start, +∞)`, or the half-open range `[start, end)`. Bounds are checked when the call is made, not on the first step.

#### Parameters

##### bounds

\[] | \[`start`: `Uint8Array`<`ArrayBufferLike`>] | \[`start`: `Uint8Array`<`ArrayBufferLike`>, `end`: `Uint8Array`<`ArrayBufferLike`>]

#### Returns

`IterableIterator`<[`SortedBlockEntry`](/reference/knotkit/sorted-block/type-aliases/sortedblockentry/)>

#### Throws

With `INVALID_KEY` when a bound is not a `Uint8Array`, or `INVALID_RANGE` when `end` sorts before `start`.

***

### \[iterator]

> `readonly` **\[iterator]**: () => `IterableIterator`<[`SortedBlockEntry`](/reference/knotkit/sorted-block/type-aliases/sortedblockentry/)>

Defined in: [packages/sorted-block/src/sorted-block.ts:69](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/sorted-block/src/sorted-block.ts#L69)

The same function as `entries`: a full walk in ascending key order.

#### Returns

`IterableIterator`<[`SortedBlockEntry`](/reference/knotkit/sorted-block/type-aliases/sortedblockentry/)>
