mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] Add RangeSelection, MosaicSelection and RandomSelection classes
This commit is contained in:
@@ -16,3 +16,45 @@
|
||||
*/
|
||||
|
||||
#include <tools/yulPhaser/Selections.h>
|
||||
|
||||
#include <tools/yulPhaser/SimulationRNG.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity::phaser;
|
||||
|
||||
vector<size_t> RangeSelection::materialise(size_t _poolSize) const
|
||||
{
|
||||
size_t beginIndex = static_cast<size_t>(round(_poolSize * m_startPercent));
|
||||
size_t endIndex = static_cast<size_t>(round(_poolSize * m_endPercent));
|
||||
vector<size_t> selection;
|
||||
|
||||
for (size_t i = beginIndex; i < endIndex; ++i)
|
||||
selection.push_back(i);
|
||||
|
||||
return selection;
|
||||
}
|
||||
|
||||
vector<size_t> MosaicSelection::materialise(size_t _poolSize) const
|
||||
{
|
||||
size_t count = static_cast<size_t>(round(_poolSize * m_selectionSize));
|
||||
|
||||
vector<size_t> selection;
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
selection.push_back(min(m_pattern[i % m_pattern.size()], _poolSize - 1));
|
||||
|
||||
return selection;
|
||||
}
|
||||
|
||||
vector<size_t> RandomSelection::materialise(size_t _poolSize) const
|
||||
{
|
||||
size_t count = static_cast<size_t>(round(_poolSize * m_selectionSize));
|
||||
|
||||
vector<size_t> selection;
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
selection.push_back(SimulationRNG::uniformInt(0, _poolSize - 1));
|
||||
|
||||
return selection;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user