[yul-phaser] Add RangeSelection, MosaicSelection and RandomSelection classes

This commit is contained in:
cameel
2020-02-25 15:25:16 +01:00
committed by Kamil Śliwak
parent 3c41bfbc4e
commit 83b8ab8012
4 changed files with 319 additions and 0 deletions
+42
View File
@@ -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;
}