DiceSet
This class implements a data structure with constant-time insertion, deletion, and random sampling. That's crucial for the CPM metropolis algorithm, which repeatedly needs to sample pixels at cell borders. Elements in this set must be unique.
Constructor Summary
Public Constructor | ||
public |
The constructor of class DiceSet takes a MersenneTwister object as input, to allow seeding of the random number generator used for random sampling. |
Member Summary
Public Members | ||
public |
Use an array for constant time random sampling of pixels at the border of cells. |
|
public |
Object or hash map used to check in constant time whether a pixel is at the cell border. |
|
public |
The number of elements currently present in the DiceSet. |
Method Summary
Public Methods | ||
public |
Check if the DiceSet already contains element v. |
|
public |
Insert a new element. |
|
public |
Remove element v. |
|
public |
Sample a random element from v. |
Public Constructors
public constructor(mt: MersenneTwister) source
The constructor of class DiceSet takes a MersenneTwister object as input, to allow seeding of the random number generator used for random sampling.
Params:
Name | Type | Attribute | Description |
mt | MersenneTwister | MersenneTwister object used for random numbers. |
Public Members
public elements: number[] source
Use an array for constant time random sampling of pixels at the border of cells.
public indices: object source
Object or hash map used to check in constant time whether a pixel is at the cell border. Keys are the actual values stored in the DiceSet, numbers are their location in the elements arrray. Currently (Mar 6, 2019), it seems that vanilla objects perform BETTER than ES6 maps, at least in nodejs. This is weird given that in vanilla objects, all keys are converted to strings, which does not happen for Maps.
Public Methods
public contains(v: uniqueID): boolean source
Check if the DiceSet already contains element v.
Params:
Name | Type | Attribute | Description |
v | uniqueID | The element to check presence of. |
public insert(v: uniqueID) source
Insert a new element. It is added as an index in the indices, and pushed to the end of the elements array.
Params:
Name | Type | Attribute | Description |
v | uniqueID | The element to add. |