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?): SortedIndexParameters
| Parameter | Type |
|---|---|
field | string |
options? | { order: number; } |
options.order? | number |
Returns
Properties
Methods
clear()
clear(): voidClear all entries from the index.
Returns
void
estimateMemoryUsage()
estimateMemoryUsage(): numberEstimate memory usage in bytes.
Returns
number
find()
find(value): string[]Find all IDs for a specific value.
Parameters
| Parameter | Type |
|---|---|
value | unknown |
Returns
string[]
getAll()
getAll(order): string[]Get all IDs in sorted order.
Parameters
| Parameter | Type | Default value |
|---|---|---|
order | "asc" | "desc" | 'asc' |
Returns
string[]
getCount()
getCount(): numberGet the number of entries in the index.
Returns
number
has()
has(value, id): booleanCheck if a value-id pair exists in the index.
Parameters
| Parameter | Type |
|---|---|
value | unknown |
id | string |
Returns
boolean
insert()
insert(value, id): voidInsert a value-id pair into the index. Null/undefined values are ignored.
Parameters
| Parameter | Type |
|---|---|
value | unknown |
id | string |
Returns
void
isEmpty()
isEmpty(): booleanCheck if the index is empty.
Returns
boolean
range()
range(options): string[]Range query returning IDs matching the criteria.
Parameters
| Parameter | Type |
|---|---|
options | RangeOptions |
Returns
string[]
remove()
remove(value, id): booleanRemove a value-id pair from the index. Returns true if found and removed.
Parameters
| Parameter | Type |
|---|---|
value | unknown |
id | string |
Returns
boolean
serialize()
serialize(): SortedIndexDataSerialize the index for persistence.
Returns
bulkLoad()
static bulkLoad(
field,
entries,
options?): SortedIndexCreate an index from entries (bulk load). Entries should be an array of { value, id }.
Parameters
| Parameter | Type |
|---|---|
field | string |
entries | { id: string; value: unknown; }[] |
options? | { order: number; } |
options.order? | number |
Returns
deserialize()
static deserialize(data): SortedIndexDeserialize an index from persisted data.
Parameters
| Parameter | Type |
|---|---|
data | SortedIndexData |
Returns
empty()
static empty(field, options?): SortedIndexCreate an empty index.
Parameters
| Parameter | Type |
|---|---|
field | string |
options? | { order: number; } |
options.order? | number |
