new MinRand(dataset, usedDataPointsopt)
Creates a new MinRand instance
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
dataset | Array | An array containing the dataset | ||
usedDataPoints | Object | <optional> | {} | A key-value object containing the arrays of used datapoints. Converted to a Map internally. |
Throws:
TypeError
Methods
addDatasetPoint(value)
Adds a value to the dataset array
Parameters:
Name | Type | Description |
---|---|---|
value | * | The value to add |
addUsedDataPoint(key, datapoint)
Adds a used datapoint to a key
Parameters:
Name | Type | Description |
---|---|---|
key | * | The key |
datapoint | * | The datapoint to add |
Throws:
- If the key does not exist or if the datapoint is not already in the dataset
- Type
- NotExistsError
- If the datapoint already exists for the specified key
- Type
- ExistsError
addUsedDataPointKey(key, forceopt)
Adds an empty used data point array for the specified key
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
key | * | The key | ||
force | boolean | <optional> | false | Whether to override an existing key |
Throws:
- An error thrown if the key already exists
- Type
- ExistsError
getDataset() → {Array}
Returns the dataset
Returns:
An array containing the dataset
- Type:
- Array
getEventEmitter() → {EventEmitter}
Returns the EventEmitter
Returns:
The EventEmitter
- Type:
- EventEmitter
getRandomDataPoint(key) → {*}
Gets a random datapoint not in the used datapoint store specified by key, and adds this to the used datapoint array for the key
Parameters:
Name | Type | Description |
---|---|---|
key | * | The key |
Fires:
Throws:
Returns:
The random datapoint
- Type:
- *
getUsedDataPointArray(key) → {Array|undefined}
Gets the used datapoints for the specified key
Parameters:
Name | Type | Description |
---|---|---|
key | * | The key |
Returns:
An array of used datapoints for this key. Undefined if it does not exist
- Type:
- Array |
undefined
getUsedDataPoints() → {Map}
Returns the used data points map
Returns:
The used data points map
- Type:
- Map
getUsedResetPercentage() → {double}
Returns the usage percentage at which the first half of the used datapoint store will be removed
Returns:
The percentage in decimal form
- Type:
- double
removeDatasetPoint(value)
Removes a value from the dataset array, and all used datapoint arrays
Parameters:
Name | Type | Description |
---|---|---|
value | * | The value to remove |
removeUsedDataPointKey(key)
Removes a used datapoint key
Parameters:
Name | Type | Description |
---|---|---|
key | * | The key |
Throws:
setDataset(dataset)
Sets the dataset
Parameters:
Name | Type | Description |
---|---|---|
dataset | Array | An array containing the dataset |
Throws:
TypeError
setUsedDataPointArray(key, array)
Sets the used datapoints for the specified key
Parameters:
Name | Type | Description |
---|---|---|
key | * | The key |
array | * | The array of datapoints |
Throws:
TypeError
setUsedResetPercentage(percentage)
Sets the usage percentage at which the first half of the used datapoint store will be removed
Parameters:
Name | Type | Description |
---|---|---|
percentage | double | A percentage in decimal form between 0.01 and 0.99 (inclusive) |
Throws:
- TypeError
- RangeError
Events
reset
The reset event fires when the first half of the used datapoints for the specified key is removed
Type:
Properties- object
Name | Type | Description |
---|---|---|
key | * | The key that was reset |