Created
January 4, 2013 18:07
-
-
Save pnkfelix/4454622 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
function ComputeSliceBounds(len, id, n) { | |
// Computes the bounds for slice |id| of |len| items, assuming |n| | |
// total slices. If len is not evenly divisible by n, then the | |
// initial threads may have a bit more work. | |
var slice = ((len + n - 1) / n) | 0; // i.e. ceil(len / n). | |
var prevDone = slice * id; // work distributed to threads before this one. | |
var start = (prevDone >= len) ? len : prevDone; // clamp start by len. | |
var end = (start + slice) > len ? len : (start + slice); // clamp end by len. | |
return [start, end]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment