import DiceSet from 'Artistoo/src/DiceSet.js'
public class | source

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.

Test:

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:

NameTypeAttributeDescription
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 length: number source

The number of elements currently present in the DiceSet.

Public Methods

public contains(v: uniqueID): boolean source

Check if the DiceSet already contains element v.

Params:

NameTypeAttributeDescription
v uniqueID

The element to check presence of.

Return:

boolean

true or false depending on whether the element is present or not.

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:

NameTypeAttributeDescription
v uniqueID

The element to add.

public remove(v: uniqueID) source

Remove element v.

Params:

NameTypeAttributeDescription
v uniqueID

The element to remove.

public sample(): uniqueID source

Sample a random element from v.

Return:

uniqueID

the element sampled.