Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class mod_random ~kind ?replay_meta mode children =
- let name ="quota" in
- object
- inherit switch ~name ~kind ?replay_meta ~mode (List.map snd children)
- val mutable pos = 0
- val mutable play_list=[]
- (* Annihilate the reversal in #select once for all. *)
- val children = List.rev children
- method private select =
- let (ready_list,n) =
- (*
- fold_left função valor_inicial lista
- :: add na lista
- l é a lista vazia, k é 0
- Ao passar por aqui ela é revertida com a lista das filhas ficando em primeiro,peso em ultimo
- *)
- List.fold_left
- (fun (l,k) (w,s) -> if s.source#is_ready then (s,w)::l,(k+w) else l,k)
- ([],0) children
- in
- if n = 0 then None else
- begin
- let sel = pos+1 in
- pos <- sel ;
- print_string("AKI "^string_of_int(pos)^"%!");
- let (play_list,pos)=List.fold_left (fun (l,n) (s,w) -> if n mod w=0 then
- (s::l,n)
- else if (List.length(l))<=0 then(l,n+1)
- else(l,n))
- ([],sel) ready_list in
- let retval=List.hd(play_list) in
- play_list<-List.tl(play_list);
- Some retval
- end;
- method stype =
- if List.exists (fun (_,s) -> s.source#stype = Infallible) children then
- Infallible
- else
- Fallible
- end
Add Comment
Please, Sign In to add comment