/// <summary> /// Tries to reorder patterns when the initial ordering is considered poor /// </summary> /// <param name="gp">Graph Pattern</param> /// <param name="desiredVariables">Variables that are desired</param> /// <param name="start">Point at which to start looking for better matches</param> /// <param name="end">Point at which to move the better match to</param> private void TryReorderPatterns(GraphPattern gp, List<String> desiredVariables, int start, int end) { if (end > start) return; //Find the first pattern which does contain a pre-existing variable for (int i = start; i < gp.TriplePatterns.Count; i++) { if (gp.TriplePatterns[i].Variables.Any(v => desiredVariables.Contains(v))) { int newEnd = i; desiredVariables.AddRange(gp.TriplePatterns[i].Variables.Where(v => desiredVariables.Contains(v))); while (i > end) { //Swap Patterns around gp.SwapTriplePatterns(i - 1, i); i--; } end = newEnd; } } }