-
-
Save bpatra/003404081d81a3c24930 to your computer and use it in GitHub Desktop.
Build Union of even lines with a fast approach based on divide and conquer.
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
private static Range UnionDivideAndConquer(int[] excelRows, int start, int end) | |
{ | |
if (excelRows.Length == 0) return null; | |
if (start == end) | |
{ | |
return ExcelAddIn.ActiveSheet.Range["A" + excelRows[start] + ":" + "C" + excelRows[start]]; | |
} | |
int middle = (start + end) / 2; | |
Range left = UnionDivideAndConquer(excelRows, start, middle); | |
Range right = UnionDivideAndConquer(excelRows, middle + 1, end); | |
return ExcelAddIn.Application.Union(left, right); | |
} | |
public BuildUnionFast(int count) | |
{ | |
var rowIndices = Enumerable.Range(1, 2*count+1).Where(k => k % 2 == 1).ToArray(); | |
Range range = UnionDivideAndConquer(rowIndices, 0, rowIndices.Length-1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment