added process scheduling algorithms
This commit is contained in:
		
							
								
								
									
										30
									
								
								process-scheduling/algorithms/utils.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								process-scheduling/algorithms/utils.typ
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| #import "../utils.typ": UNBORN, READY, RUNNING, TERMINATED | ||||
|  | ||||
| #let _prepare-tasks(tasks) = { | ||||
|   let processes = (:) | ||||
|   for (i, task) in tasks.enumerate() { | ||||
|     let id = str(i) | ||||
|     task.insert("id", id) | ||||
|     task.insert("state", UNBORN) | ||||
|     processes.insert(id, (task: task, events: ())) | ||||
|     tasks.at(i) = task | ||||
|   } | ||||
|   return (processes, tasks) | ||||
| } | ||||
|  | ||||
| #let _prepare-output(processes) = { | ||||
|   return processes.values() | ||||
|                   .map(p => ( | ||||
|                     pid: p.task.pid, | ||||
|                     priority: p.task.priority, | ||||
|                     events: p.events | ||||
|                   )) | ||||
|                   .sorted(key: t => t.pid) | ||||
| } | ||||
|  | ||||
| #let log-list(list) = { | ||||
|   if list == none or list.len() == 0 { | ||||
|     return "queue:" | ||||
|   } | ||||
|   return "queue: " + list.map(t => str(t.pid)).join(", ") | ||||
| } | ||||
		Reference in New Issue
	
	Block a user