Show
Ignore:
Timestamp:
01/31/08 00:09:35 (5 years ago)
Author:
mrkn
Message:

lang/cplusplus/boost-supplement/trunk/boost_supplement/random/discrete_distribution.hpp (boost_supplement::discrete_distribution): Adds a comment about Walker's original paper of the algorithm for this class. Some lines are moved for easy reading. An assertion is added.

Location:
lang/cplusplus/boost-supplement/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/cplusplus/boost-supplement/trunk/ChangeLog

    r5902 r5906  
     12008-01-31  Kenta Murata  <muraken@gmail.com> 
     2 
     3        * boost_supplement/random/discrete_distribution.hpp 
     4        (boost_supplement::discrete_distribution): Adds a comment about 
     5        Walker's original paper of the algorithm for this class. 
     6        Some lines are moved for easy reading. An assertion is added. 
     7 
    182008-01-30  Kenta Murata  <muraken@gmail.com> 
    29 
  • lang/cplusplus/boost-supplement/trunk/boost_supplement/random/discrete_distribution.hpp

    r5902 r5906  
    2121 
    2222namespace boost_supplement { 
     23 
     24/* Alastair J. Walker.  An Efficient Method for Generating Discrete 
     25 * Random Variables With General Distributions.  ACM TOMS 3(3), 
     26 * 253--256 (1977). */ 
    2327template<class IntType = long, class RealType = double> 
    2428class discrete_distribution 
     
    2832  typedef IntType result_type; 
    2933 
     34#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300) 
     35  BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer); 
     36  BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer); 
     37#endif 
     38 
    3039  typedef typename std::vector<input_type>::const_iterator probability_iterator; 
    3140  typedef typename std::vector<input_type>::const_reverse_iterator probability_reverse_iterator; 
     
    3342  typedef typename std::vector<result_type>::const_iterator alias_iterator; 
    3443  typedef typename std::vector<result_type>::const_reverse_iterator alias_reverse_iterator; 
    35  
    36 #if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300) 
    37   BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer); 
    38   BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer); 
    39 #endif 
    4044 
    4145private: 
     
    5155 
    5256      result_type n = std::distance(first, last); 
    53       aliases_.resize(n, n); 
     57      BOOST_ASSERT(0 < n); 
    5458 
    5559      while (first != last) { 
     
    5761        ++first; 
    5862      } 
     63      BOOST_ASSERT(n == probabilities_.size()); 
    5964 
    60       BOOST_ASSERT(n == probabilities_.size()); 
     65      aliases_.resize(n, n); 
    6166 
    6267      for (result_type i = 0; i < n; ++i) {