Esempio n. 1
0
        /// <summary>
        /// Compiles from strings (see Compile for more details)
        /// </summary>
        /// <param name="func"></param>
        /// <param name="variables"></param>
        /// <returns></returns>
        internal static FastExpression Compile(Entity func, params string[] variables)
        {
            var varNamespace = new Dictionary <string, int>();
            int id           = 0;

            foreach (var varName in variables)
            {
                varNamespace[varName] = id;
                id++;
            }
            func = func.SubstituteConstants();
            var res = new FastExpression(variables.Length, func);

            func.UpdateHash();                 // Count hash for O(N)
            Entity.HashOccurancesUpdate(func); // Update occurances for each node for O(N) instead of O(N^2)
            InnerCompile(func, res, variables, varNamespace);
            res.Seal();                        // Creates stack
            return(res);
        }