# 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:
  - ActiveBucket.js, line 14

### Methods

- count() → {Number}
- documentKey(obj) → {String}
- index(obj) → {Number}
- insert(obj) → {Number}
- qs(obj, arr, item, fn) → {Number}
- remove(obj) → {Number}

#### count() → {Number}

Get the number of documents currently indexed in the active bucket instance.

Source:
  - ActiveBucket.js, line 263

##### 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:
  - ActiveBucket.js, line 224

##### 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:
  - ActiveBucket.js, line 204

##### 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:
  - ActiveBucket.js, line 146

##### 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:
  - ActiveBucket.js, line 48

##### Returns:

The index the document should occupy.

Type
  Number

#### remove(obj) → {Number}

Removes a document from the active bucket.

##### Parameters:

Name | Type | Description
--- | --- | ---
`obj` | Object | The document to remove.

Source:
  - ActiveBucket.js, line 175

##### Returns:

The index of the document if the document was removed successfully or -1 if it wasn't found in the active bucket.

Type
  Number