code_junkie

Balanced Distribution Algorithm

Nov 11th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. foreach ( child in children ) {
  2. if ( child.dataLoad > avg + 1 ) {
  3. foreach ( child2 in children ) {
  4. if ( child != child2 && child2.dataLoad < avg ) {
  5. sendLoad(child, child2)
  6. }
  7. }
  8. }
  9. }
  10.  
  11. for each child in list {
  12. if child2 == nil then assert("Error in logic");
  13. while child.workload > avg + 1 {
  14. sendwork(child, child2, min(avg + 1 - child2.workload, child.workload - (avg + 1)))
  15. if child2.workload == avg + 1 then child2 = child2.next;
  16. }
  17. }
Add Comment
Please, Sign In to add comment