Example #1
0
        private int BinSearchGreen(int blueIndex, double greenKey)
        {
            int low  = 0;
            int high = subTreesBlue[blueIndex].subTreesGreen.Count - 1;

            while (low <= high)
            {
                int       mid    = low + high >> 1;
                GreenTree midVal = subTreesBlue[blueIndex].
                                   subTreesGreen[mid];

                if (midVal.Intensity < greenKey)
                {
                    low = mid + 1;
                }
                else if (midVal.Intensity > greenKey)
                {
                    high = mid - 1;
                }
                else
                {
                    return(mid);
                }
            }
            return(-1);
        }
Example #2
0
        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);
            }
        }