LogoRobo.js
Framework

SortedIndex

Class: SortedIndex

SortedIndex implementation using a B+Tree.

Provides efficient range queries and ordered iteration. Values are compared using standard JavaScript comparison. Records with the same value are secondarily sorted by id.

Constructors

new SortedIndex()

new SortedIndex(field, options?): SortedIndex

Parameters

ParameterType
fieldstring
options?{ order: number; }
options.order?number

Returns

SortedIndex

Properties

PropertyModifierType
fieldreadonlystring

Methods

clear()

clear(): void

Clear all entries from the index.

Returns

void


estimateMemoryUsage()

estimateMemoryUsage(): number

Estimate memory usage in bytes.

Returns

number


find()

find(value): string[]

Find all IDs for a specific value.

Parameters

ParameterType
valueunknown

Returns

string[]


getAll()

getAll(order): string[]

Get all IDs in sorted order.

Parameters

ParameterTypeDefault value
order"asc" | "desc"'asc'

Returns

string[]


getCount()

getCount(): number

Get the number of entries in the index.

Returns

number


has()

has(value, id): boolean

Check if a value-id pair exists in the index.

Parameters

ParameterType
valueunknown
idstring

Returns

boolean


insert()

insert(value, id): void

Insert a value-id pair into the index. Null/undefined values are ignored.

Parameters

ParameterType
valueunknown
idstring

Returns

void


isEmpty()

isEmpty(): boolean

Check if the index is empty.

Returns

boolean


range()

range(options): string[]

Range query returning IDs matching the criteria.

Parameters

ParameterType
optionsRangeOptions

Returns

string[]


remove()

remove(value, id): boolean

Remove a value-id pair from the index. Returns true if found and removed.

Parameters

ParameterType
valueunknown
idstring

Returns

boolean


serialize()

serialize(): SortedIndexData

Serialize the index for persistence.

Returns

SortedIndexData


bulkLoad()

static bulkLoad(
   field, 
   entries, 
   options?): SortedIndex

Create an index from entries (bulk load). Entries should be an array of { value, id }.

Parameters

ParameterType
fieldstring
entries{ id: string; value: unknown; }[]
options?{ order: number; }
options.order?number

Returns

SortedIndex


deserialize()

static deserialize(data): SortedIndex

Deserialize an index from persisted data.

Parameters

ParameterType
dataSortedIndexData

Returns

SortedIndex


empty()

static empty(field, options?): SortedIndex

Create an empty index.

Parameters

ParameterType
fieldstring
options?{ order: number; }
options.order?number

Returns

SortedIndex

On this page