private static CallSiteRule <T> FindCompatibleRuleForTemplate <T>(CallSiteRule <T> from, CallSiteRule <T> to, out List <ConstantExpression> newConstants, out bool tooSpecific) where T : class
        {
            // no templates exist for this rule, just compare the raw trees...
            if (TreeComparer.Compare(to.Binding, from.Binding, out newConstants, out tooSpecific))
            {
                // the rules are not compatbile, don't add template values...
                return(from);
            }

            return(null);
        }
Exemple #2
0
        public void TreeComparer()
        {
            Setup.TimerStart($"==>{Setup.CallerName()} Started");
            BaseType.ResetSdcImport();
            string path  = Path.Combine(".", "Test files", "Adrenal.Bx.Res.129_3.004.001.REL_sdcFDF_test.xml");
            var    FDbad = FormDesignType.DeserializeFromXmlPath(path); //used to compare nodes in another tree
            var    adr   = FDbad.Nodes.Values.ToArray();                //this creates shallow copies with do not retain ParentNode refs, etc.


            var tc = new TreeComparer();
            var n  = Setup.FD.Nodes.Values.ToArray();   //this creates shallow copies with do not retain ParentNode refs, etc.

            Stopwatch.StartNew();
            var a = Stopwatch.GetTimestamp();

            Debug.Print(tc.Compare(n[0], n[1]).ToString());
            Debug.Print(tc.Compare(n[0], n[2]).ToString());
            Debug.Print(tc.Compare(n[0], n[3]).ToString());
            Debug.Print(tc.Compare(n[0], n[10]).ToString());
            Debug.Print(tc.Compare(n[0], n[3]).ToString());
            Debug.Print(tc.Compare(n[0], n[8]).ToString());
            Debug.Print(tc.Compare(n[1], n[8]).ToString());
            Debug.Print("\r\n");
            Debug.Print(tc.Compare(n[1], n[1]).ToString());
            Debug.Print(tc.Compare(n[2], n[2]).ToString());
            Debug.Print(tc.Compare(n[3], n[3]).ToString());
            Debug.Print(tc.Compare(n[10], n[10]).ToString());
            Debug.Print(tc.Compare(n[20], n[20]).ToString());
            Debug.Print(tc.Compare(n[30], n[30]).ToString());
            Debug.Print(tc.Compare(n[50], n[50]).ToString());
            Debug.Print("\r\n expected results: -1, 1, -1, 1, -1, 1, -1 ");
            Debug.Print(tc.Compare(n[1], n[2]).ToString());     // -1
            Debug.Print(tc.Compare(n[2], n[1]).ToString());     // 1
            Debug.Print(tc.Compare(n[33], n[34]).ToString());   // -1
            Debug.Print(tc.Compare(n[20], n[10]).ToString());   // 1
            Debug.Print(tc.Compare(n[199], n[201]).ToString()); // -1
            Debug.Print(tc.Compare(n[201], n[200]).ToString()); // 1
            Debug.Print(tc.Compare(n[29], n[32]).ToString());   // -1
            Debug.Print("\r\n expected results: -1, 1, -1, 1, -1, 1, -1 ");
            Debug.Print(tc.Compare(n[299], n[301]).ToString()); // -1
            Debug.Print(tc.Compare(n[401], n[300]).ToString()); // 1
            Debug.Print(tc.Compare(n[39], n[42]).ToString());   // -1
            Debug.Print(tc.Compare(n[21], n[11]).ToString());   // 1
            Debug.Print(tc.Compare(n[11], n[12]).ToString());   // -1
            Debug.Print(tc.Compare(n[341], n[133]).ToString()); // 1
            Debug.Print(tc.Compare(n[101], n[120]).ToString()); // -1


            Debug.Print("\r\n");
            Debug.Print(tc.Compare(n[2], n[1]).ToString());
            Debug.Print(tc.Compare(n[4], n[0]).ToString());
            Debug.Print(tc.Compare(n[6], n[4]).ToString());
            Debug.Print(tc.Compare(n[20], n[2]).ToString());
            Debug.Print(tc.Compare(n[40], n[0]).ToString());
            Debug.Print(tc.Compare(n[60], n[0]).ToString());
            Debug.Print(tc.Compare(n[100], n[0]).ToString());
            Debug.Print("\r\n");

            try { Debug.Print(tc.Compare(n[100], adr[0]).ToString()); } catch { Debug.Print("error caught"); }
            try { Debug.Print(tc.Compare(adr[0], n[100]).ToString()); } catch { Debug.Print("error caught"); }
            try { Debug.Print(tc.Compare(n[10], adr[12]).ToString()); } catch { Debug.Print("error caught"); }
            try { Debug.Print(tc.Compare(adr[100], adr[100]).ToString()); } catch { Debug.Print("error caught"); }



            Debug.Print(((float)(Stopwatch.GetTimestamp() - a) / ((float)Stopwatch.Frequency)).ToString());


            //Seconds per comparison: @ 0.0006 sec/comparison
            a = Stopwatch.GetTimestamp();
            for (int i = 0; i < 100; i++)
            {
                tc.Compare(n[299], n[301]);
                tc.Compare(n[2101], n[120]);
            }
            Debug.Print(((float)(Stopwatch.GetTimestamp() - a) / ((float)Stopwatch.Frequency) / 200).ToString());
            Setup.TimerPrintSeconds("  seconds: ", $"\r\n<=={Setup.CallerName()} Complete");
        }