/// <summary> /// Find the index of value containing blue key /// using Binary Search. /// </summary> /// <param name="blue"></param> /// <returns></returns> private int BinSearchBlue(double blueKey) { int low = 0; int high = subTreesBlue.Count - 1; while (low <= high) { int mid = low + high >> 1; BlueTree midVal = subTreesBlue[mid]; if (midVal.Intensity < blueKey) { low = mid + 1; } else if (midVal.Intensity > blueKey) { high = mid - 1; } else { return(mid); } } return(-1); }
private void PopulateTree(double blue, double green, double red, int frequency) { if (subTreesBlue.Exists(bt => bt.Intensity == blue)) { int indexBlue = subTreesBlue.FindIndex(bt => bt.Intensity == blue); // next find if the specific green exists in a subtree of blue // such that Gn | Bn if (subTreesBlue[indexBlue].subTreesGreen. Exists(gt => gt.Intensity == green)) { int indexGreen = subTreesBlue[indexBlue].subTreesGreen.FindIndex(gt => gt.Intensity == green); RedFIP pairRedFI = new RedFIP(); pairRedFI.Intensity = red; pairRedFI.Frequency = frequency; subTreesBlue[indexBlue].subTreesGreen[indexGreen].redNodes.Add(pairRedFI); } else { GreenTree gt = new GreenTree(); gt.Intensity = green; RedFIP pairRedFI = new RedFIP(); pairRedFI.Intensity = red; pairRedFI.Frequency = frequency; gt.redNodes.Add(pairRedFI); subTreesBlue[indexBlue].subTreesGreen.Add(gt); } } else { BlueTree bt = new BlueTree(); GreenTree gt = new GreenTree(); RedFIP pairRedFI = new RedFIP(); pairRedFI.Intensity = red; pairRedFI.Frequency = frequency; gt.Intensity = green; bt.Intensity = blue; gt.redNodes.Add(pairRedFI); bt.subTreesGreen.Add(gt); subTreesBlue.Add(bt); } }