Guest User

Untitled

a guest
Jan 5th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 1.29 KB | None | 0 0
  1. class mod_random ~kind ?replay_meta  mode children =
  2.   let name ="quota" in
  3. object
  4.   inherit switch ~name ~kind ?replay_meta ~mode (List.map snd children)
  5.  
  6.   val mutable pos = 0
  7.   val mutable play_list=[]
  8.   (* Annihilate the reversal in #select once for all. *)
  9.   val children = List.rev children
  10.  
  11.   method private select =
  12.    
  13.     let (ready_list,n) =
  14.    
  15.       (*
  16.       fold_left função valor_inicial lista
  17.       :: add na lista
  18.         l é a lista vazia, k é 0
  19.         Ao passar por aqui ela é revertida com a lista das filhas ficando em primeiro,peso em ultimo
  20.       *)
  21.       List.fold_left
  22.         (fun (l,k) (w,s) -> if s.source#is_ready then (s,w)::l,(k+w) else l,k)
  23.         ([],0) children
  24.     in
  25.    
  26.       if n = 0 then None else
  27.                     begin
  28.                     let sel = pos+1 in
  29.                     pos <- sel ;
  30.                      print_string("AKI "^string_of_int(pos)^"%!");
  31.                     let (play_list,pos)=List.fold_left (fun (l,n) (s,w) -> if n mod w=0 then
  32.                                      (s::l,n)
  33.                             else if (List.length(l))<=0 then(l,n+1)
  34.                             else(l,n))
  35.                         ([],sel) ready_list in
  36.                        
  37.                  let retval=List.hd(play_list) in
  38.                  play_list<-List.tl(play_list);
  39.    
  40.                     Some  retval
  41.                 end;
  42.   method stype =
  43.     if List.exists (fun (_,s) -> s.source#stype = Infallible) children then
  44.       Infallible
  45.     else
  46.       Fallible
  47. end
Add Comment
Please, Sign In to add comment