aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-01-18 15:46:15 -0500
committerHolden Rohrer <hr@hrhr.dev>2020-01-18 15:46:15 -0500
commit7386e7324aed533e28b26e666525a036e6dac47a (patch)
treef729c02001935231aa7bb80be484e4306866e569
parente8ebf9ec7639a95ddf1a0a61a7a4996a570e261a (diff)
Implemented bug fix for maxr in schedule.js
Rankings may have been messed up because as new insertions get added, the data.length changes per write.
-rw-r--r--tools/schedule.js6
1 files changed, 2 insertions, 4 deletions
diff --git a/tools/schedule.js b/tools/schedule.js
index 18278f0..033fddb 100644
--- a/tools/schedule.js
+++ b/tools/schedule.js
@@ -1,7 +1,5 @@
// A mixed paradigm scheduler
-// RECOMMENDED: Adjust maxr with each round, unless this is determined to be potentially circumventable (maybe maxr ranks remain constant as long as they are recalc on insertion---so function-style?)
-
const bs = require('binary-search');
// The core managed data type: a queue will be pushed a number of these and asked to manage it.
@@ -14,7 +12,7 @@ exports.Job = function(data, prio=0, wt=1){
this.data = data; //A set of work to be done (like character writes)
this.prio = prio; // If a.prio > b.prio, all of `a.data` will be sent before any of `b.data`
this.wt = wt; // After numerous calls, (amount called of a/amount called of b) = a.wt/b.wt if a.prio = b.prio
- this.maxr = data.length/wt; // A utility calculation: If a job has a lower maxr, it will run out of data earlier.
+ this.maxr = () => this.data.length/this.wt; // A utility calculation: If a job has a lower maxr, it will run out of data earlier.
// Mutable Properties
this.wacc = 0; // mutable property: Queue will change this to keep track between dequeues of how much "left over" push real estate this should have.
@@ -31,7 +29,7 @@ exports.Queue = function(delayms, maxExport, call){
if (! (job instanceof exports.Job)) job = new exports.Job(job);
let prio = job.prio;
if (!jobs[prio]) jobs[prio] = [];
- jobs[prio].splice(0, Math.abs(bs(jobs[prio], job, (el, ne) => el.maxr - ne.maxr)), job);
+ jobs[prio].splice(0, Math.abs(bs(jobs[prio], job, (el, ne) => el.maxr() - ne.maxr())), job);
prios.splice(0, Math.abs(bs(prios, prio, (el, ne) => el-ne)), prio); // prios is meant to be sorted least to most, and each job layer is too (by "maximum number of rounds").
// These were sorted like this so that getNumOrAll could use [0] or [.length-1] or .pop instead of having to re-sort lists repetitively.
if (open) dequeue();