Skip to content

Commit

Permalink
ValuePercent -> ValueWeight
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-derevenetz committed Oct 19, 2024
1 parent ffa181c commit f0d6fbe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/engine/rand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ int32_t Rand::Queue::Get( const std::function<uint32_t( uint32_t )> & randomFunc
return 0;
}

const uint32_t sum = std::accumulate( begin(), end(), static_cast<uint32_t>( 0 ), []( const uint32_t total, const ValuePercent & vp ) { return total + vp.second; } );
const uint32_t sum = std::accumulate( begin(), end(), static_cast<uint32_t>( 0 ), []( const uint32_t total, const ValueWeight & vw ) { return total + vw.second; } );
assert( sum > 0 );

uint32_t rand = randomFunc( sum - 1 );
assert( rand < sum );

for ( const ValuePercent & vp : *this ) {
if ( rand < vp.second ) {
return vp.first;
for ( const ValueWeight & vw : *this ) {
if ( rand < vw.second ) {
return vw.first;
}

rand -= vp.second;
rand -= vw.second;
}

assert( 0 );
Expand Down
4 changes: 2 additions & 2 deletions src/engine/rand.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ namespace Rand
return vec[id];
}

using ValuePercent = std::pair<int32_t, uint32_t>;
using ValueWeight = std::pair<int32_t, uint32_t>;

class Queue : private std::vector<ValuePercent>
class Queue : private std::vector<ValueWeight>
{
public:
explicit Queue( uint32_t size = 0 )
Expand Down

0 comments on commit f0d6fbe

Please sign in to comment.