/// <summary> /// Find the index of value containing blue key /// using Binary Search. /// </summary> /// <param name="blue"></param> /// <returns></returns> private int BinSearchHue(double hueKey) { int low = 0; int high = subTreesHue.Count - 1; while (low <= high) { int mid = low + high >> 1; HueTree midVal = subTreesHue[mid]; if (midVal.Magnitude < hueKey) { low = mid + 1; } else if (midVal.Magnitude > hueKey) { high = mid - 1; } else { return(mid); } } return(-1); }
private void PopulateTree(double hue, double saturation, double value, int frequency) { if (subTreesHue.Exists(bt => bt.Magnitude == hue)) { int indexHue = subTreesHue.FindIndex(bt => bt.Magnitude == hue); // next find if the specific green exists in a subtree of blue // such that Gn | Bn if (subTreesHue[indexHue].subTreesSaturation. Exists(gt => gt.Magnitude == saturation)) { int indexSat = subTreesHue[indexHue].subTreesSaturation.FindIndex(gt => gt.Magnitude == saturation); ValueFIP valueFIP = new ValueFIP(); valueFIP.Magnitude = value; valueFIP.Frequency = frequency; subTreesHue[indexHue].subTreesSaturation[indexSat].valueNodes.Add(valueFIP); } else { SatTree st = new SatTree(); st.Magnitude = saturation; ValueFIP valueFIP = new ValueFIP(); valueFIP.Magnitude = value; valueFIP.Frequency = frequency; st.valueNodes.Add(valueFIP); subTreesHue[indexHue].subTreesSaturation.Add(st); } } else { HueTree ht = new HueTree(); SatTree st = new SatTree(); ValueFIP valueFIP = new ValueFIP(); valueFIP.Magnitude = value; valueFIP.Frequency = frequency; st.Magnitude = saturation; ht.Magnitude = hue; st.valueNodes.Add(valueFIP); ht.subTreesSaturation.Add(st); subTreesHue.Add(ht); } }