Created
February 1, 2021 08:38
-
-
Save bubnenkoff/1a4a77f8b90d08437226cbd53db8e38a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() { | |
genJobs(int activeWorkers, List<int> numbersOfAlreadyActiveJobs) { | |
final maxJobs = 16; | |
List<int> jobs = List<int>.generate(maxJobs, (i) => i + 1); | |
final workerCapacity = (jobs.length / activeWorkers).floor(); | |
jobs.removeWhere((item) => numbersOfAlreadyActiveJobs.contains(item)); | |
if(jobs.length > 0) { // если нужно что-то запускать | |
for (var workerNumber = 0; workerNumber < activeWorkers; workerNumber++) { | |
final startIndex = workerNumber * workerCapacity; | |
final endIndex = startIndex + workerCapacity; | |
final chunk = jobs.sublist( | |
startIndex, | |
endIndex > jobs.length || workerNumber == activeWorkers - 1 | |
? jobs.length | |
: endIndex, | |
); | |
} | |
} | |
return null; | |
} | |
genJobs(8, [7, 8, 3, 4]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If
workerCapacity
depends on length ofjobs
, you should calculate it after removing items fromjobs
. And remember to check whether the boundary conditions are satisfied or not.