Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2016
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. /*
  2.              /-> B -\
  3. begin -> A -<       >-> D -> E ->end
  4.              \-> C -/
  5.  
  6. depenendencies  |  dependents
  7. ----------------|-------------
  8. [E]             :  [end]
  9. [D]             :  [E]
  10. [B, C]          :  [D]
  11. [A]             :  [B, C]
  12. [begin]         :  [A]
  13. */
  14.  
  15. auto expand(node n)
  16. {
  17.     if(n == begin)
  18.     {
  19.         return n;
  20.     }
  21.     else if(is_linear_to(n))
  22.     {
  23.         return expand(only_dependency(n)).then(n);
  24.     }
  25.     else if(is_join)
  26.     {
  27.         return when_all(expand_fork(dependencies(n)...)).then(n);
  28.     }
  29. }
  30.  
  31. auto expand_fork(nodes... ns)
  32. {
  33.     return expand(fork_origin_of(ns...)).then_in_parallel(ns...);
  34. }
  35.  
  36. // begin...
  37. expand(end)
  38.  
  39. // is_linear_to(end)? true
  40. expand(E).then(end)
  41.  
  42. // is_linear_to(E)? true
  43. expand(D).then(E).then(end)
  44.  
  45. // is_join_to(D)? true
  46. when_all(expand_fork(B, C)).then(D).then(E)).then(end)
  47.  
  48. // expand_fork(B, C)
  49. when_all(expand(A).then_in_parallel(B, C)).then(D).then(E)).then(end)
  50.  
  51. // is_linear_to(A)? true
  52. when_all(expand(begin).then(A).then_in_parallel(B, C)).then(D).then(E)).then(end)
  53.  
  54. // is_begin? true
  55. when_all(begin.then(A).then_in_parallel(B, C)).then(D).then(E)).then(end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement