Class: ActiveBucket

ActiveBucket

new ActiveBucket(orderBy)

Creates an always-sorted multi-key bucket that allows ForerunnerDB to know the index that a document will occupy in an array with minimal processing, speeding up things like sorted views.
Parameters:
Name Type Description
orderBy object An order object.
Source:

Methods

(private) _sortFunc(sorter, obj, a, b) → {number}

Calculates the sort position of an item against another item.
Parameters:
Name Type Description
sorter object An object or instance that contains sortAsc and sortDesc methods.
obj object The document to compare.
a string The first key to compare.
b string The second key to compare.
Source:
Returns:
Either 1 for sort a after b or -1 to sort a before b.
Type
number

count() → {number}

Get the number of documents currently indexed in the active bucket instance.
Source:
Returns:
The number of documents.
Type
number

documentKey(obj) → {string}

The key that represents the passed document.
Parameters:
Name Type Description
obj object The document to get the key for.
Source:
Returns:
The document key.
Type
string

index(obj) → {number}

Get the index that the passed document currently occupies or the index it will occupy if added to the active bucket.
Parameters:
Name Type Description
obj object The document to get the index for.
Source:
Returns:
The index.
Type
number

insert(obj) → {number}

Inserts a document into the active bucket.
Parameters:
Name Type Description
obj object The document to insert.
Source:
Returns:
The index the document now occupies.
Type
number

qs(obj, arr, item, fn) → {number}

Quicksorts a single document into the passed array and returns the index that the document should occupy.
Parameters:
Name Type Description
obj object The document to calculate index for.
arr array The array the document index will be calculated for.
item string The string key representation of the document whose index is being calculated.
fn function The comparison function that is used to determine if a document is sorted below or above the document we are calculating the index for.
Source:
Returns:
The index the document should occupy.
Type
number

remove(obj) → {boolean}

Removes a document from the active bucket.
Parameters:
Name Type Description
obj object The document to remove.
Source:
Returns:
True if the document was removed successfully or false if it wasn't found in the active bucket.
Type
boolean