only weight tasks and task_sets one time
@@ -104,6 +104,13 @@ fn load_goosefile(goosefile: PathBuf) -> Result<GooseTaskSets, &'static str> {
/// Returns a bucket of weighted Goose Task Sets, optionally shuffled
fn weight_task_sets(task_sets: &GooseTaskSets, shuffle: bool) -> Vec<usize> {
trace!("weight_tasksets");
+
+ let mut bucket;
+ if task_sets.weighted_task_sets.len() > 0 {
+ bucket = task_sets.weighted_task_sets.clone();
+ trace!("re-using existing weighted_task_sets: {:?}", bucket);
+ }
+ else {
let mut u: usize = 0;
let mut v: usize;
for task_set in &task_sets.task_sets {
@@ -120,7 +127,7 @@ fn weight_task_sets(task_sets: &GooseTaskSets, shuffle: bool) -> Vec<usize> {
// u will always be the greatest common divisor
debug!("gcd: {}", u);
- let mut bucket: Vec<usize> = Vec::new();
+ bucket = Vec::new();
for (index, task_set) in task_sets.task_sets.iter().enumerate() {
// divide by greatest common divisor so bucket is as small as possible
let weight = task_set.weight / u;
@@ -128,6 +135,9 @@ fn weight_task_sets(task_sets: &GooseTaskSets, shuffle: bool) -> Vec<usize> {
let mut task_sets = vec![index; weight];
bucket.append(&mut task_sets);
}
+ trace!("created weighted_task_sets: {:?}", bucket);
+ }
+
if shuffle {
bucket.shuffle(&mut thread_rng());
}
@@ -137,6 +147,13 @@ fn weight_task_sets(task_sets: &GooseTaskSets, shuffle: bool) -> Vec<usize> {
/// Returns a bucket of weighted Goose Tasks, optionally shuffled
fn weight_tasks(task_set: &GooseTaskSet, shuffle: bool) -> Vec<usize> {
trace!("weight_tasks for {}", task_set.name);
+
+ let mut bucket;
+ if task_set.weighted_tasks.len() > 0 {
+ bucket = task_set.weighted_tasks.clone();
+ trace!("re-using existing weighted_tasks: {:?}", bucket);
+ }
+ else {
let mut u: usize = 0;
let mut v: usize;
for task in &task_set.tasks {
@@ -153,7 +170,7 @@ fn weight_tasks(task_set: &GooseTaskSet, shuffle: bool) -> Vec<usize> {
// u will always be the greatest common divisor
debug!("gcd: {}", u);
- let mut bucket: Vec<usize> = Vec::new();
+ bucket = Vec::new();
for (index, task) in task_set.tasks.iter().enumerate() {
// divide by greatest common divisor so bucket is as small as possible
let weight = task.weight / u;
@@ -161,6 +178,8 @@ fn weight_tasks(task_set: &GooseTaskSet, shuffle: bool) -> Vec<usize> {
let mut tasks = vec![index; weight];
bucket.append(&mut tasks);
}
+ trace!("created weighted_tasks: {:?}", bucket);
+ }
if shuffle {
bucket.shuffle(&mut thread_rng());
}
