diff options
author | Holden Rohrer <hr@hrhr.dev> | 2020-03-26 00:07:38 -0400 |
---|---|---|
committer | Holden Rohrer <hr@hrhr.dev> | 2020-03-26 00:07:38 -0400 |
commit | 9634a1c6d79a93ab79c5354d2240ed11ad9abbe7 (patch) | |
tree | ec579b22851d7e91f6ac854ac414fbfe66a80351 /tools/schedule.js | |
parent | 7f3110ec388bdf6b72579b70a5736f3f53809de4 (diff) | |
parent | 183b38854c8efef2af9e4118060bc2dc4a84befc (diff) |
Merge branch 'master' into bulletbullet
Diffstat (limited to 'tools/schedule.js')
-rw-r--r-- | tools/schedule.js | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/tools/schedule.js b/tools/schedule.js index d8509b8..c110bb3 100644 --- a/tools/schedule.js +++ b/tools/schedule.js @@ -86,14 +86,17 @@ exports.Queue = function(delayms, maxExport, call){ // Step 2: Start at lowest, and pop all until job.data.length>job.normweight*num (decreasing num as popping and recalc job.normweight). Delete the job. let weightsum = jobq.map(job => job.wt).reduce((acc, cur)=>acc+cur); - while (jobq[0] && jobq[0].data.length<(jobq[0].wacc+jobq[0].wt*num/weightsum)){ - weightsum -= jobq[0].wt; + while (jobq[0] && jobq[0].data.length<(jobq[0].wt*num/weightsum)){ + // The second req is SO weird. Think about it this way: for len objs + // to be pushed, the "odds" of the job getting a push must >= len (pushed + // len times). But it gets num tries, so the odds*num >= len. + // The odds are wt/wtsum for each try. dequeued.push(...jobq.shift().data); } // Step 3: Then, pop job.normweight*num//1 elems from remaining, without num decrease or normweight recalc. But keep job.wacc = job.normweight*num%1 let efflen = num - dequeued.length; - for (job of jobq){ + for (let job of jobq){ let topop = job.wt*efflen/weightsum; job.wacc += topop%1; topop = topop-topop%1; @@ -102,7 +105,7 @@ exports.Queue = function(delayms, maxExport, call){ } // Step 4: Shallow copy job array, and sort by job.wacc. - for (job of jobq.slice().sort((el, ne) => el.wacc-ne.wacc)){ + for (let job of jobq.slice().sort((el, ne) => el.wacc-ne.wacc)){ // Step 5: Iterate through array (high->low), and subtract 1 until the length of output is num. if (dequeued.length == num || job.data.length == 0) break; job.wacc--; |