@@ -12,11 +12,11 @@ use crate::{
12
12
} ;
13
13
14
14
#[ inline]
15
- fn pick_one ( weight : isize , iter : & [ Arc < Instance > ] ) -> Option < ( usize , Arc < Instance > ) > {
15
+ fn pick_one ( weight : usize , iter : & [ Arc < Instance > ] ) -> Option < ( usize , Arc < Instance > ) > {
16
16
if weight == 0 {
17
17
return None ;
18
18
}
19
- let mut weight = rand:: thread_rng ( ) . gen_range ( 0 ..weight) ;
19
+ let mut weight = rand:: rng ( ) . random_range ( 0 ..weight) as isize ;
20
20
for ( offset, instance) in iter. iter ( ) . enumerate ( ) {
21
21
weight -= instance. weight as isize ;
22
22
if weight <= 0 {
@@ -29,7 +29,7 @@ fn pick_one(weight: isize, iter: &[Arc<Instance>]) -> Option<(usize, Arc<Instanc
29
29
#[ derive( Debug ) ]
30
30
pub struct InstancePicker {
31
31
shared_instances : Arc < WeightedInstances > ,
32
- sum_of_weights : isize ,
32
+ sum_of_weights : usize ,
33
33
owned_instances : OnceCell < Vec < Arc < Instance > > > ,
34
34
last_pick : Option < ( usize , Arc < Instance > ) > ,
35
35
}
@@ -54,7 +54,7 @@ impl Iterator for InstancePicker {
54
54
. get_or_init ( || shared_instances. to_vec ( ) ) ;
55
55
let owned = self . owned_instances . get_mut ( ) . unwrap ( ) ;
56
56
57
- self . sum_of_weights -= last_pick. weight as isize ;
57
+ self . sum_of_weights -= last_pick. weight as usize ;
58
58
owned. remove ( * last_offset) ;
59
59
60
60
( * last_offset, * last_pick) = pick_one ( self . sum_of_weights , owned) ?;
@@ -67,15 +67,15 @@ impl Iterator for InstancePicker {
67
67
68
68
#[ derive( Debug , Clone ) ]
69
69
struct WeightedInstances {
70
- sum_of_weights : isize ,
70
+ sum_of_weights : usize ,
71
71
instances : Vec < Arc < Instance > > ,
72
72
}
73
73
74
74
impl From < Vec < Arc < Instance > > > for WeightedInstances {
75
75
fn from ( instances : Vec < Arc < Instance > > ) -> Self {
76
76
let sum_of_weights = instances
77
77
. iter ( )
78
- . fold ( 0 , |lhs, rhs| lhs + rhs. weight as isize ) ;
78
+ . fold ( 0 , |lhs, rhs| lhs + rhs. weight as usize ) ;
79
79
Self {
80
80
instances,
81
81
sum_of_weights,
0 commit comments