示例#1
0
        /// <summary>
        /// 获取匹配的数据集合
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param name="isValue">数据匹配器,禁止锁操作</param>
        /// <returns>数据集合</returns>
        public valueType[] GetFindArrayNoOrderLock(keyType key, func <valueType, bool> isValue)
        {
            group values;
            int   version = keyVersion;

            if (groups.TryGetValue(key, out values) && values.Key.Equals(key))
            {
                Monitor.Enter(cache.SqlTool.Lock);
                try
                {
                    return(values.List.GetFindArray(isValue));
                }
                finally { Monitor.Exit(cache.SqlTool.Lock); }
            }
            else if (version != keyVersion)
            {
                Monitor.Enter(cache.SqlTool.Lock);
                try
                {
                    if (groups.TryGetValue(key, out values))
                    {
                        return(values.List.GetFindArray(isValue));
                    }
                }
                finally { Monitor.Exit(cache.SqlTool.Lock); }
            }
            return(nullValue <valueType> .Array);
        }
示例#2
0
        /// <summary>
        /// 数组范围排序
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="values">待排序数组</param>
        /// <param name="startIndex">起始位置</param>
        /// <param name="count">排序范围数据数量</param>
        /// <param name="getKey">排序键值获取器</param>
        /// <param name="skipCount">跳过数据数量</param>
        /// <param name="getCount">排序数据数量</param>
        /// <param name="fixedIndex">索引位置</param>
        /// <returns>排序后的数组</returns>
        private unsafe static valueType[] getRangeSort/*Compare[0]*//*Compare[0]*/ <valueType>
            (valueType[] values, int startIndex, int count, func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int skipCount, int getCount
            , /*Type[2]*/ ulongSortIndex /*Type[2]*/ *fixedIndex)
        {
            /*Type[2]*/
            ulongSortIndex /*Type[2]*/ *writeIndex = fixedIndex;

            for (int index = startIndex, endIndex = startIndex + count; index != endIndex; ++index)
            {
                *writeIndex++ = new /*Type[2]*/ ulongSortIndex /*Type[2]*/ {
                    Value = getKey(values[index]), Index = index
                };
            }
            new /*Type[3]*/ ulongRangeIndexSorter/*Type[3]*//*Compare[0]*//*Compare[0]*/
            {
                SkipCount   = fixedIndex + skipCount,
                GetEndIndex = fixedIndex + skipCount + getCount - 1
            }.Sort(fixedIndex, fixedIndex + count - 1);
            valueType[] newValues = new valueType[getCount];
            writeIndex = fixedIndex + skipCount;
            for (int index = 0; index != newValues.Length; ++index)
            {
                newValues[index] = values[(*writeIndex++).Index];
            }
            return(newValues);
        }
示例#3
0
        /// <summary>
        /// 排序去除Top N
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="values">待排序数组</param>
        /// <param name="getKey">排序键值获取器</param>
        /// <param name="count">排序数据数量</param>
        /// <returns>排序后的数据</returns>
        private unsafe static valueType[] getRemoveTop/*Compare[0]*//*Compare[0]*/ <valueType>
            (valueType[] values, func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int count)
        {
            valueType[] newValues = new valueType[count];
            count = values.Length - count;
            uint sqrtMod;
            int  length = Math.Min(Math.Max(count << 2, count + (int)number.sqrt((uint)values.Length, out sqrtMod)), values.Length);

            if (length > (config.pub.Default.StreamBufferLength >> 4))
            {
                /*Type[2]*/
                ulongSortIndex /*Type[2]*/[] removeValues = new /*Type[2]*/ ulongSortIndex /*Type[2]*/[length];
                fixed(/*Type[2]*/ ulongSortIndex /*Type[2]*/ *removeFixed = removeValues)
                {
                    removeTop/*Compare[0]*//*Compare[0]*/ (values, getKey, count, newValues, length, removeFixed);
                }
            }
            else
            {
                /*Type[2]*/
                ulongSortIndex /*Type[2]*/ *removeFixed = stackalloc /*Type[2]*/ ulongSortIndex /*Type[2]*/[length];
                removeTop/*Compare[0]*//*Compare[0]*/ (values, getKey, count, newValues, length, removeFixed);
            }
            return(newValues);
        }
示例#4
0
        /// <summary>
        /// 查找第一个匹配的数据
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param name="isValue">数据匹配器,禁止锁操作</param>
        /// <returns>第一个匹配的数据,失败返回null</returns>
        public valueType FirstOrDefaultLock(keyType key, func <valueType, bool> isValue)
        {
            group values;
            int   version = keyVersion;

            if (groups.TryGetValue(key, out values) && values.Key.Equals(key))
            {
                Monitor.Enter(cache.SqlTool.Lock);
                try
                {
                    return(values.List.FirstOrDefault(isValue));
                }
                finally { Monitor.Exit(cache.SqlTool.Lock); }
            }
            else if (version != keyVersion)
            {
                Monitor.Enter(cache.SqlTool.Lock);
                try
                {
                    if (groups.TryGetValue(key, out values))
                    {
                        return(values.List.FirstOrDefault(isValue));
                    }
                }
                finally { Monitor.Exit(cache.SqlTool.Lock); }
            }
            return(null);
        }
示例#5
0
        /// <summary>
        /// 查找符合条件的记录集合
        /// </summary>
        /// <param name="values">值集合</param>
        /// <param name="isValue">判断记录是否符合条件的委托</param>
        /// <returns>符合条件的记录集合</returns>
        public unsafe static list </*Type[0]*/ ulong /*Type[0]*/> getFind
            (this System.Collections.ICollection values, func </*Type[0]*/ ulong /*Type[0]*/, bool> isValue)
        {
            if (values != null)
            {
                if (isValue == null)
                {
                    log.Default.Throw(log.exceptionType.Null);
                }
                /*Type[0]*/
                ulong /*Type[0]*/[] newValues = new /*Type[0]*/ ulong /*Type[0]*/[values.Count];
                fixed(/*Type[0]*/ ulong /*Type[0]*/ *newValueFixed = newValues)
                {
                    /*Type[0]*/
                    ulong /*Type[0]*/ *write = newValueFixed;

                    foreach (/*Type[0]*/ ulong /*Type[0]*/ value in values)
                    {
                        if (isValue(value))
                        {
                            *write++ = value;
                        }
                    }
                    return(new list </*Type[0]*/ ulong /*Type[0]*/>(newValues, 0, (int)(write - newValueFixed), true));
                }
            }
            return(null);
        }
示例#6
0
        public Object[] Exec(func f, output output, Object[] p_j, int nth)
        {
            _f = f;
            _output = output;
            _nth = nth;
            _job = new SJobQueue();
            _job.p_j = p_j;
            _job.nj = p_j.Length;
            _job.submitted_j = new bool[_job.nj];
            _job.completed_j = new bool[_job.nj];
            _job.outputted_j = new bool[_job.nj];
            _job.th_j = new int[_job.nj];
            _job.ret_j = new Object[_job.nj];
            for (int j = 0; j < _job.nj; j++) _job.submitted_j[j] = false;
            for (int j = 0; j < _job.nj; j++) _job.completed_j[j] = false;
            for (int j = 0; j < _job.nj; j++) _job.outputted_j[j] = false;

            System.Threading.Thread[] thread_th = new System.Threading.Thread[nth];

            for (int th = 0; th < nth; th++)
            {
                thread_th[th] = new System.Threading.Thread(Iterate);
                thread_th[th].Name = "CJobQueue Worker Thread " + th;
                thread_th[th].Start();
                System.Threading.Thread.Sleep(10);
            }

            Output();
            for (int th = 0; th < nth; th++)
            {
                thread_th[th].Join();
            }
            return _job.ret_j;
        }
示例#7
0
文件: ImportWebSO.cs 项目: Fun33/code
        private void BtnSearch_Click(object sender, EventArgs e)
        {
            BtnSearch.Enabled = false;
            try
            {
                Search();

                appl.StatusBar("開始載入EXCEL檔案...", MessageType.None);

                //載入DGV
                string strOrderCmd = " order by " + SOColName;//getOrderCmd();
                func   ff          = new func();

                oDT           = loadGridFromExcel(s, strOrderCmd);
                GV.DataSource = oDT;

                appl.StatusBar("EXCEL載入完成!!", MessageType.Success);

                if (Chk())
                {
                    BtnOK.Enabled = true;
                }
                else
                {
                    BtnOK.Enabled = false;
                }
                appl.StatusBar("檢查完成!!", MessageType.None);
            }
            catch (Exception ex)
            {
                appl.SetSystemLog(ex.ToString());
            }
            BtnSearch.Enabled = true;
        }
示例#8
0
        public static double Solve(double left, double right, double epsilon, func func)
        {
            int    iteration = 0;
            double c         = 0;

            while (true)
            {
                double cPrev = c;
                Tools.PrintIteration(++iteration);
                Console.WriteLine($"a: {left}");
                Console.WriteLine($"b: {right}");
                c = left - (func(left) * (right - left)) / (func(right) - func(left));
                Console.WriteLine($"c: {c}");
                Console.WriteLine("Ck-1: {0}", cPrev);
                if (func(right) * func(c) < 0)
                {
                    left = c;
                }
                else
                {
                    right = c;
                }
                if (Tools.SimpleStopCriteria(c, cPrev, epsilon))
                {
                    return(c);
                }
            }
        }
示例#9
0
        /// <summary>
        /// 根据集合内容返回数组
        /// </summary>
        /// <typeparam name="valueType">枚举值类型</typeparam>
        /// <param name="values">值集合</param>
        /// <param name="getValue">获取数组值的委托</param>
        /// <returns>数组</returns>
        public unsafe static /*Type[0]*/ ulong /*Type[0]*/[] getArray <valueType>
            (this System.Collections.Generic.ICollection <valueType> values, func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getValue)
        {
            if (values.count() != 0)
            {
                if (getValue == null)
                {
                    log.Default.Throw(log.exceptionType.Null);
                }
                /*Type[0]*/
                ulong /*Type[0]*/[] newValues = new /*Type[0]*/ ulong /*Type[0]*/[values.Count];
                fixed(/*Type[0]*/ ulong /*Type[0]*/ *newValueFixed = newValues)
                {
                    /*Type[0]*/
                    ulong /*Type[0]*/ *write = newValueFixed;

                    foreach (valueType value in values)
                    {
                        *write++ = getValue(value);
                    }
                }

                return(newValues);
            }
            return(nullValue </*Type[0]*/ ulong /*Type[0]*/> .Array);
        }
示例#10
0
 /// <summary>
 /// Constructor which inits the TranslationFunction and RotationFunction attributes.
 /// </summary>
 public Sensor()
 {
     //m_Rotation.Sensor = this;
     //m_Translation.Sensor = this;
     m_TranslationFunction = set_Function(functions.none);
     m_RotationFunction    = set_Function(functions.none);
 }
示例#11
0
        public ActionResult loginAdmin(string acc, string pass)
        {
            if (func.LoginAdmin(acc, pass))
            {
                func     f  = new func();
                Customer cs = func.GetCustomer(acc);
                if (cs.idUser == 2)
                {
                    return(Content("AdminLogin"));
                }
                if (cs != null)
                {
                    Session["customers"] = cs;
                    if (cs.idCusAuthe == 1)
                    {
                        return(Content("AdminLogin"));
                    }
                    else
                    {
                        return(Content("RegisterForm"));
                    }
                }
                else
                {
                    return(Content("RegisterForm"));
                }
            }

            else
            {
                return(Content("RegisterForm"));
            }
        }
示例#12
0
 /// <summary>
 /// 分组求和
 /// </summary>
 /// <typeparam name="valueType">数据类型</typeparam>
 /// <typeparam name="keyType">分组键值类型</typeparam>
 /// <param name="values">数据集合</param>
 /// <param name="getKey">键值获取器</param>
 /// <param name="getValue">数据获取器</param>
 /// <returns>分组求和</returns>
 public static System.Collections.Generic.Dictionary <keyType, /*Type[0]*/ ulong /*Type[0]*/> groupSum <valueType, keyType>
     (this System.Collections.Generic.IEnumerable <valueType> values, func <valueType, keyType> getKey
     , func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getValue)
 {
     if (values != null)
     {
         if (getKey == null || getValue == null)
         {
             log.Default.Throw(log.exceptionType.Null);
         }
         /*Type[0]*/
         ulong /*Type[0]*/ sum;
         System.Collections.Generic.Dictionary <keyType, /*Type[0]*/ ulong /*Type[0]*/> sums
             = new System.Collections.Generic.Dictionary <keyType, /*Type[0]*/ ulong /*Type[0]*/>();
         foreach (valueType value in values)
         {
             keyType key = getKey(value);
             if (sums.TryGetValue(key, out sum))
             {
                 sums[key] = (/*Type[0]*/ ulong /*Type[0]*/)(sum + getValue(value));
             }
             else
             {
                 sums.Add(key, getValue(value));
             }
         }
         return(sums);
     }
     return(null);
 }
示例#13
0
        /// <summary>
        /// 转换表达式
        /// </summary>
        /// <param name="converter">表达式转换器</param>
        /// <param name="expression">表达式</param>
        private void convertInSet(sql.expression.converter converter, Expression expression)
        {
            charStream       stream           = converter.Stream;
            BinaryExpression binaryExpression = (BinaryExpression)expression;
            Expression       left             = binaryExpression.Left;

            converters[(int)left.NodeType](converter, left);
            stream.Write(" In(");
            func <object, string> toString = null;
            int index = -1;

            foreach (object value in (IEnumerable)((ConstantExpression)binaryExpression.Right).Value)
            {
                if (++index == 0)
                {
                    toString = constantConverter.Default[value.GetType()];
                }
                else
                {
                    stream.Write(',');
                }
                stream.Write(toString != null ? toString(value) : constantConverter.convertConstantStringMssql(value.ToString()));
            }
            stream.Write(')');
        }
示例#14
0
        // Численно вычисляет матрицу Гессе(матрицу двойных производных)
        public static decimal[,] ComputeHessian(func f, List <decimal> x, decimal step)
        {
            var matrix   = new decimal[x.Count, x.Count];
            var varCount = x.Count;
            var fPlus    = new decimal[varCount];
            var args     = new decimal[varCount];

            x.CopyTo(args);
            var curFValue = f(args); //значение функции в текущей точке

            for (int i = 0; i < varCount; i++)
            {
                x.CopyTo(args);
                args[i] += step;
                fPlus[i] = f(args);
            }

            for (int i = 0; i < varCount; i++)
            {
                for (int j = 0; j < varCount; j++)
                {
                    x.CopyTo(args);
                    args[i] += step;
                    args[j] += step;
                    decimal value = f(args);
                    matrix[i, j] = (value - fPlus[i] - fPlus[j] + curFValue) / (step * step);
                }
            }


            return(matrix);
        }
示例#15
0
 public static bool SpellImmuneTargetAll(func f)
 {
     if (Game.GetOpponentMinions().Any(i => !i.CantTarget && !i.Stealth && f(i)))
     {
         return(true);
     }
     else
     {
         if (!Game.Opponent.Stealth && f(Game.Opponent.Hero))
         {
             return(true);
         }
         else
         {
             if (Game.GetUserMinions().Any(i => !i.CantTarget && f(i)))
             {
                 return(true);
             }
             else
             {
                 if (f(Game.User.Hero))
                 {
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             }
         }
     }
 }
示例#16
0
        public static void Init(int width, int height, func init, func mainLoop, func final, bool isShowInfo = true)
        {
            ChangeWindowMode(TRUE);
            SetGraphMode(width, height, 32);
            DxLib_Init();
            SetDrawScreen(DX_SCREEN_BACK);

            init();

            MATRIX matrix = MGetIdent();

            while (ScreenFlip() == 0 && ClearDrawScreen() == 0 && ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0)
            {
                Input.Update();
                Time.Update();
                TaskManager.Update();
                Obj.UpdateAll();
                mainLoop();
                if (isShowInfo)
                {
                    SetTransformTo2D(out matrix);
                    DrawString(0, 0, string.Format("FPS:{0:f1},オブジェ:{1},タスク:{2}", Time.GetCurrentFps(), Obj.Count, TaskManager.Count), GetColor(255, 255, 255));
                }
            }

            final();

            DxLib_End();
        }
示例#17
0
 public static same_func bind <P1, T1>(func <P1> handler, T1 p1)
 {
     return(delegate(object[] args)
     {
         handler((P1)(functional._ == (object)p1 ? args[0] : p1));
     });
 }
        public IntersectionPeriod(DateTime start, DateTime end, func function, DataPoint d1, DataPoint d2)
        {
            //find start and end of the overlap
            this.start = start;
            this.end   = end;

            //calculate new value
            switch (function)
            {
            case func.plus:
            {
                value = d1.getValue() + d2.getValue();
                break;
            }

            case func.minus:
            {
                value = d1.getValue() - d2.getValue();
                break;
            }

            case func.mult:
            {
                value = d1.getValue() * d2.getValue();
                break;
            }

            case func.div:
            {
                value = d1.getValue() / d2.getValue();
                break;
            }
            }
        }
示例#19
0
    private void RunStart()
    {
        done = false;
        if (caves)
        {
            surfaceFunc = TerrainCave;
        }
        else
        {
            surfaceFunc = TerrainPlane;
        }
        List <Thread> threadsList = new List <Thread> ();

        Vector2 [] Keys = new Vector2[generated.Count];;
        generated.Keys.CopyTo(Keys, 0);
        foreach (Vector2 pos in Keys)
        {
            bool check = false;
            lock (lock_obj){
                check = (bool)generated[pos];
            }
            if (!check)
            {
                Thread t = new Thread(Generate);
                threadsList.Add(t);
                t.Start(pos);
            }
        }
        //foreach (Thread t in threadsList) t.Join ();
    }
示例#20
0
 public static void getConformation(func function)
 {
     ConformationWindow.function = function;
     Kernel.disalble();
     win.enabled = true;
     machine.goTo(ConformationStateMachine.confirm.yes);
 }
示例#21
0
 /// <summary>
 /// 获取最小值记录
 /// </summary>
 /// <typeparam name="valueType">值类型</typeparam>
 /// <param name="values">值集合</param>
 /// <param name="getKey">获取排序键的委托</param>
 /// <param name="key">最小值</param>
 /// <returns>是否存在最小值</returns>
 public static bool minKey <valueType>
     (this System.Collections.Generic.ICollection <valueType> values, func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey
     , out /*Type[0]*/ ulong /*Type[0]*/ key)
 {
     if (values.count() != 0)
     {
         if (getKey == null)
         {
             log.Default.Throw(log.exceptionType.Null);
         }
         valueType value = default(valueType);
         int       count = -1;
         key = /*Type[0]*/ ulong /*Type[0]*/.MaxValue;
         foreach (valueType nextValue in values)
         {
             if (++count == 0)
             {
                 key = getKey(value = nextValue);
             }
             else
             {
                 /*Type[0]*/
                 ulong /*Type[0]*/ nextKey = getKey(nextValue);
                 if (nextKey < key)
                 {
                     value = nextValue;
                     key   = nextKey;
                 }
             }
         }
         return(true);
     }
     key = default(/*Type[0]*/ ulong /*Type[0]*/);
     return(false);
 }
示例#22
0
 public Trie(Alphabet alphabet)
 {
     _charToIndex = alphabet._charToIndex;
     _indexToChar = alphabet._indexToChar;
     R = alphabet.R;
     root = new TrieNode();
 }
        public static double integrate(func f, System.Collections.Generic.IReadOnlyList <double> init_ticks, double eps1)
        {
            var points = new System.Collections.Generic.Stack <Point>();
            var areas  = new System.Collections.Generic.List <double>();

            foreach (var x in init_ticks)
            {
                points.Push(new Point(x, f(x)));
            }

            var    full_width = init_ticks.Last() - init_ticks.First();
            Point  right;
            double eps = eps1 * 4.0 / full_width;

            while (points.Count > 1)
            {
                //Console.WriteLine(points.Count);
                right = points.Pop();
                var left = points.Peek();
                var mid  = Integration.midpoint(ref left, ref right, f);
                if (Math.Abs(left.f + right.f - mid.f * 2.0) <= eps)
                {
                    areas.Add((left.f + right.f + mid.f * 2.0) * (right.x - left.x) / 4.0);
                }
                else
                {
                    points.Push(mid);
                    points.Push(right);
                }
            }
            areas.Sort(delegate(double x, double y){
                return(Math.Abs(x).CompareTo(Math.Abs(y)));
            });
            return(areas.Sum());
        }
示例#24
0
        public void Add(RelationType relationType, bool usePercent)
        {
            if (relationType == RelationType.Size)
            {
                Add(RelationType.Width, usePercent);
                Add(RelationType.Height, usePercent);
                return;
            }

            func f = SIDE_FUNCTIONS[(int)relationType];

            foreach (RelationDef def in _defs)
            {
                if (def.setFunction == f)
                {
                    return;
                }
            }

            RelationDef info = new RelationDef();

            info.affectBySelfSizeChanged = relationType >= RelationType.Center_Center && relationType <= RelationType.Right_Right ||
                                           relationType >= RelationType.Middle_Middle && relationType <= RelationType.Bottom_Bottom;
            info.percent     = usePercent;
            info.setFunction = f;
            _defs.Add(info);
        }
示例#25
0
 private void package_combo()
 {
     if (package.Items.Count == 0)
     {
         try
         {
             string        querry = "Select Description,Price from Container_Package ";
             SqlCommand    cmd    = new SqlCommand(querry);
             SqlConnection con    = new func().con();
             cmd.Connection = con;
             try
             {
                 con.Open();
                 SqlDataReader rdr = cmd.ExecuteReader();
                 while (rdr.Read())
                 {
                     package.Items.Add(rdr[0].ToString());
                 }
             }
             catch (Exception c)
             {
             }
             finally
             {
                 con.Close();
             }
         }
         catch (Exception)
         {
         }
     }
 }
示例#26
0
        /// <summary>
        /// 获取匹配数据集合
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param name="isValue">数据匹配器,禁止锁操作</param>
        /// <returns>匹配数据集合</returns>
        public list <valueType> GetFindLock(keyType key, func <valueType, bool> isValue)
        {
            keyValue <keyType, list <valueType> > list;
            int version = keyVersion;

            if (groups.TryGetValue(key, out list) && list.Key.Equals(key))
            {
                Monitor.Enter(cache.SqlTool.Lock);
                try
                {
                    return(list.Value.GetFind(isValue));
                }
                finally { Monitor.Exit(cache.SqlTool.Lock); }
            }
            else if (version != keyVersion)
            {
                Monitor.Enter(cache.SqlTool.Lock);
                try
                {
                    if (groups.TryGetValue(key, out list))
                    {
                        return(list.Value.GetFind(isValue));
                    }
                }
                finally { Monitor.Exit(cache.SqlTool.Lock); }
            }
            return(null);
        }
示例#27
0
        static public double[] descent_method(func f, double[] vars, double eps, int max_steps_count)
        {
            double B = f(vars), A = 0;
            double delta = 0.0;

            for (int i = 0; i < max_steps_count; i++)
            {
                A = B;

                for (int var_index = 0; var_index < vars.Length; var_index++)
                {
                    vars[var_index] = golden_section(f, vars, var_index, eps, -0.75, 0.75, max_steps_count);
                }

                B = f(vars);

                delta = Math.Abs(A - B);

                if (delta <= eps)
                {
                    break;
                }
            }
            return(vars);
        }
        public static double newtonDecent(func func, dfunc dfunc)
        {
            double x0    = 0;
            double x1    = x0 + 1;
            double step  = 0.0002;
            int    i     = 0;
            bool   first = true;

            while (Math.Abs(func.Invoke(x1) - func.Invoke(x0)) > 0.00000001)
            {
                if (!first)
                {
                    x0    = x1;
                    first = false;
                }
                x1 = x0 + step * dfunc.Invoke(x1);
                if (func.Invoke(x1) < func.Invoke(x0))
                {
                    step /= 2;
                }
                else
                {
                    step *= 2;
                }
                i++;
            }
            return(func.Invoke(x1));
        }
示例#29
0
 /// <summary>
 /// 数组范围排序
 /// </summary>
 /// <typeparam name="valueType">数据类型</typeparam>
 /// <param name="values">待排序数组</param>
 /// <param name="startIndex">起始位置</param>
 /// <param name="count">排序范围数据数量</param>
 /// <param name="getKey">排序键值获取器</param>
 /// <param name="skipCount">跳过数据数量</param>
 /// <param name="getCount">排序数据数量</param>
 /// <returns>排序后的数组</returns>
 public unsafe static valueType[] GetRangeSort/*Compare[0]*//*Compare[0]*/ <valueType>
     (valueType[] values, int startIndex, int count, func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int skipCount, int getCount)
 {
     array.range range = new array.range(values.length(), startIndex, count);
     if ((count = range.GetCount) != 0)
     {
         array.range getRange = new array.range(count, skipCount, getCount);
         if ((getCount = getRange.GetCount) != 0)
         {
             if (getKey == null)
             {
                 log.Default.Throw(log.exceptionType.Null);
             }
             if (values.Length > (config.pub.Default.StreamBufferLength >> 4))
             {
                 /*Type[2]*/
                 ulongSortIndex /*Type[2]*/[] indexs = new /*Type[2]*/ ulongSortIndex /*Type[2]*/[count];
                 fixed(/*Type[2]*/ ulongSortIndex /*Type[2]*/ *fixedIndex = indexs)
                 {
                     return(getRangeSort/*Compare[0]*//*Compare[0]*/
                                (values, range.SkipCount, count, getKey, getRange.SkipCount, getCount, fixedIndex));
                 }
             }
             else
             {
                 /*Type[2]*/
                 ulongSortIndex /*Type[2]*/ *fixedIndex = stackalloc /*Type[2]*/ ulongSortIndex /*Type[2]*/[count];
                 return(getRangeSort/*Compare[0]*//*Compare[0]*/
                            (values, range.SkipCount, count, getKey, getRange.SkipCount, getCount, fixedIndex));
             }
         }
     }
     return(nullValue <valueType> .Array);
 }
示例#30
0
        /// <summary>
        /// 获取匹配分页集合
        /// </summary>
        /// <param name="pageSize">分页长度</param>
        /// <param name="currentPage">当前页号</param>
        /// <param name="isValue">数据匹配器</param>
        /// <param name="count">匹配数据总数</param>
        /// <returns>匹配分页集合</returns>
        internal list <valueType> GetArrayPage(int pageSize, int currentPage, func <valueType, bool> isValue, out int count)
        {
            int valueCount = 0;

            array.page page            = new array.page(Array.Length, pageSize, currentPage);
            int        currentPageSize = page.CurrentPageSize;

            list <valueType> .unsafer values = new list <valueType>(page.CurrentPageSize).Unsafer;
            int skipCount = page.SkipCount;

            currentPageSize += skipCount;
            foreach (valueType value in Array)
            {
                if (isValue(value))
                {
                    if (valueCount >= skipCount && valueCount < currentPageSize)
                    {
                        values.Add(value);
                    }
                    ++valueCount;
                }
            }
            count = valueCount;
            return(values.List);
        }
示例#31
0
        /// <summary>
        /// 数组排序
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="values">待排序数组</param>
        /// <param name="getKey">排序键值获取器</param>
        /// <param name="startIndex">起始位置</param>
        /// <param name="count">排序数据数量</param>
        /// <param name="fixedIndex">索引位置</param>
        /// <returns>排序后的数组</returns>
        private unsafe static valueType[] getSort/*Compare[0]*//*Compare[0]*/ <valueType>
            (valueType[] values, func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int startIndex, int count
            , /*Type[1]*/ ulongSortIndex /*Type[1]*/ *fixedIndex)
        {
            /*Type[1]*/
            ulongSortIndex /*Type[1]*/ *writeIndex = fixedIndex;

            if (count > 1)
            {
                if (getKey == null)
                {
                    log.Default.Throw(log.exceptionType.Null);
                }
                for (int index = startIndex, endIndex = startIndex + count; index != endIndex; ++index)
                {
                    *writeIndex++ = new /*Type[1]*/ ulongSortIndex /*Type[1]*/ {
                        Value = getKey(values[index]), Index = index
                    };
                }
                sort/*Compare[0]*//*Compare[0]*/ (writeIndex = fixedIndex, fixedIndex + count - 1);
            }
            else
            {
                *fixedIndex = new /*Type[1]*/ ulongSortIndex /*Type[1]*/ {
                    Index = startIndex
                }
            };
            valueType[] newValues = new valueType[count];
            for (int index = 0; index != newValues.Length; ++index)
            {
                newValues[index] = values[(*writeIndex++).Index];
            }
            return(newValues);
        }
    }
        public bool Run(out string output)
        {
            if (IsFunction)
            {
                if (paras.Count < fe.numberparasmin)
                {
                    output = "Too few parameters";
                }
                else
                {
                    System.Reflection.MethodInfo mi = GetType().GetMethod(fe.fname, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    func fptr = (func)Delegate.CreateDelegate(typeof(func), this, mi);      // need a delegate which is attached to this instance..
                    bool res  = fptr(out output);
                    return(res);
                }
            }
            else if (paras.Count != 1)
            {
                output = "Missing variable name between brackets";
            }
            else if (vars.Exists(paras[0].Value))
            {
                output = vars[paras[0].Value];
                return(true);
            }
            else
            {
                output = "Variable '" + paras[0].Value + "' does not exist";
            }

            return(false);
        }
示例#33
0
        /// <summary>
        /// 移除匹配值
        /// </summary>
        /// <param name="list">单向动态数组</param>
        /// <param name="isValue">数据匹配器</param>
        /// <returns>单向动态数组</returns>
        public unsafe static list </*Type[0]*/ ulong /*Type[0]*/> remove
            (this list </*Type[0]*/ ulong /*Type[0]*/> list, func </*Type[0]*/ ulong /*Type[0]*/, bool> isValue)
        {
            int count = list.count();

            if (count != 0)
            {
                if (isValue == null)
                {
                    log.Default.Throw(log.exceptionType.Null);
                    fixed(/*Type[0]*/ ulong /*Type[0]*/ *valueFixed = list.Unsafer.Array)
                    {
                        /*Type[0]*/
                        ulong /*Type[0]*/ *start = valueFixed, end = valueFixed + count;

                        while (start != end && !isValue(*start))
                        {
                            ++start;
                        }
                        /*Type[0]*/
                        ulong /*Type[0]*/ *write = start;

                        while (start != end)
                        {
                            if (!isValue(*start))
                            {
                                *write++ = *start;
                            }
                            ++start;
                        }
                        list.Unsafer.AddLength((int)(write - valueFixed) - count);
                    }
            }
            return(list);
        }
示例#34
0
 public double GetGlobalError(List<double> inputs, List<double> expected, func f)
 {
     List<double> outputs = (from x in f(inputs, 1).Split(new char[] { ';' }) select Convert.ToDouble(x)).ToList<double>();
     GE = 0;
     for(int i=0; i<outputs.Count(); i++)
         GE += Math.Abs(outputs[i]-expected[i]);
     return GE;
 }
示例#35
0
 public static void Euler(func f, float y, int n, float h)
 {
     for(float x=0; x<=n; x+=h)
     {
         Console.WriteLine("\t" + x + "\t" + y);
         y += h * f(y);
     }
 }
示例#36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MyTimer"/> class.
 /// </summary>
 /// <param name="delay">The delay.</param>
 /// <param name="newFunc">The new function.</param>
 /// <param name="param">The parameters.</param>
 public MyTimer(int delay, func newFunc, object param)
 {
     delayAmount = delay;
     myFunc = newFunc;
     this.param = param;
     //start timer now
     start();
 }
示例#37
0
 public static void Main(string[] args)
 {
     func f = new func(NewtonCooling);
     for(int i=0; i<delta_t.Length; i++)
     {
         Console.WriteLine("delta_t = " + delta_t[i]);
         Euler(f,T0,n,delta_t[i]);
     }
 }
        private void performOnAll(func myFunc)
        {
            this.performOnDict(this.opponent, myFunc);
            foreach (Dictionary<InputState.Move, ButtonAnimation> bundle in this.player.Values) {
                this.performOnDict(bundle, myFunc);
            }

            this.performOnDict(this.fail, myFunc);
        }
示例#39
0
文件: Jeu.cs 项目: Balnian/Battleship
 //private volatile bool gameStarted = false;
 /// <summary>
 /// Constructeur du jeu
 /// applique l'adresse IP et change l'état du jeu a WaitingStart
 /// </summary>
 /// <param name="Ip">Adresse IP</param>
 /// <param name="HandleClient"></param>
 public Jeu(String Ip,func HandleClient)
 {
     ipAdress = Ip;
     Lock.WaitOne();
     State = GameState.WaitingStartGame;
     Lock.ReleaseMutex();
     UpdateAction();
     AddHitSelf = HandleClient;
 }
示例#40
0
文件: Program.cs 项目: Beraliv/Csharp
        // Метод Симпсона для 100 частей на промежутке от a до b
        public static double SimpIntegral(func f, double a, double b)
        {
            double h = (a + b) / 100;
            double value = f(a) + f(b);
            double temp = 0;
            for (int i = 0; i < 100; i++)
                temp += f(a + h / 2 * (2 * i + 1));
            value += 4 * temp;
            temp = 0;
            for (int i = 0; i < 99; i++)
                temp += f(a + (i + 1) * h);
            value += 2 * temp;

            return h / 6 * value;
        }
示例#41
0
文件: Jeu.cs 项目: Balnian/Battleship
        /// <summary>
        /// Jouer son tour
        /// Envoie d'un Hit au serveur
        /// </summary>
        /// <param name="point">point touché</param>
        /// <param name="AjoutHit"></param>
        public void PlayingTurn(Point point, func AjoutHit)
        {
            try
            {
                CommUtility.SerializeAndSend(serveur.GetStream(), new Hit { Etat = Hit.HitState.NoAction, Location = point });

                (new Thread(() => waitHitConfirm(AjoutHit))).Start();
            }
            catch (Exception)
            {

                Lock.WaitOne();
                State = GameState.ServerDC;
                Lock.ReleaseMutex();
            }
        }
示例#42
0
文件: Jeu.cs 项目: Balnian/Battleship
        /// <summary>
        /// Attente de la comfirmation du serveur pour savoir si le Hit
        /// est un Flop ou un Touché
        /// </summary>
        /// <param name="AjoutHit"></param>
        private void waitHitConfirm(func AjoutHit)
        {
            object carry = null;
            try
            {
                carry = CommUtility.ReadAndDeserialize(serveur.GetStream());
                AjoutHit((Hit)carry);

                Lock.WaitOne();
                Thread.Sleep(300);
                State = GameState.WaitingTurn;
                Lock.ReleaseMutex();
                UpdateAction();

            }
            catch(Exception e)
            {
                try
                {
                    if (carry != null)
                    {
                        Result result = (Result)carry;
                        if(result.Etat == Result.ResultState.Victory)//Si la réponse est Victoire
                        {
                            if (result.Touche != null && result.Touche.Etat != Hit.HitState.NoAction)
                                AjoutHit(result.Touche);
                            Lock.WaitOne();
                            State = GameState.Victory;
                            EnemyShips = result.EnemyShips;
                            Lock.ReleaseMutex();
                            UpdateAction();

                        }
                        else//Si la réponse est Perdage
                        {
                            if (result.Touche != null && result.Touche.Etat != Hit.HitState.NoAction)
                                AjoutHit(result.Touche);
                            Lock.WaitOne();
                            State = GameState.Lose;
                            EnemyShips = result.EnemyShips;
                            Lock.ReleaseMutex();
                            UpdateAction();
                        }
                    }
                    else
                        throw;

                }
                catch (Exception)
                {
                    Lock.WaitOne();
                    State = GameState.ServerDC;
                    Lock.ReleaseMutex();
                    UpdateAction();
                }
            }
        }
示例#43
0
 static UnaryExpression()
 {
     getSimpleExpressions = new func<UnaryExpression, Expression>[fastCSharp.Enum.GetMaxValue<ExpressionType>(-1) + 1];
     getSimpleExpressions[(int)ExpressionType.Not] = getSimpleNot;
     //getSimpleExpressions[(int)expressionType.Negate] = getSimpleNegate;
     //getSimpleExpressions[(int)expressionType.NegateChecked] = getSimpleNegate;
     //getSimpleExpressions[(int)expressionType.UnaryPlus] = getSimpleUnaryPlus;
     getSimpleExpressions[(int)ExpressionType.IsTrue] = getSimpleIsTrue;
     getSimpleExpressions[(int)ExpressionType.IsFalse] = getSimpleIsFalse;
     //getSimpleExpressions[(int)expressionType.Convert] = getSimpleConvert;
     //getSimpleExpressions[(int)expressionType.ConvertChecked] = getSimpleConvert;
 }
示例#44
0
 public int exeFunc(int a, int b, func x)
 {
     return x(a, b);
 }
示例#45
0
 static Loger()
 {
     logFile = new FileStream("log.txt", FileMode.OpenOrCreate, FileAccess.Write);
     logWrite = new StreamWriter(logFile);
     message = MessagesSender.nothing;
 }
示例#46
0
 /// <summary>
 /// 删除匹配的子节点
 /// </summary>
 /// <param name="isRemove">删除子节点匹配器</param>
 private void removeChilds(func<htmlNode, bool> isRemove)
 {
     if (children != null)
     {
         int count = children.Count;
         while (--count >= 0 && !isRemove(children[count])) ;
         if (count >= 0)
         {
             list<htmlNode>.unsafer values = new list<htmlNode>(children.Count).Unsafer;
             int index = 0;
             for (; index != count; ++index)
             {
                 if (!isRemove(children[index])) values.Add(children[index]);
             }
             for (count = children.Count; ++index != count; values.Add(children[index])) ;
             children = values.List;
         }
     }
 }
示例#47
0
 /// <summary>
 /// 删除匹配的子孙节点
 /// </summary>
 /// <param name="isRemove">删除节点匹配器</param>
 public void Remove(func<htmlNode, bool> isRemove)
 {
     if (isRemove != null)
     {
         removeChilds(isRemove);
         if (children.count() != 0)
         {
             htmlNode node;
             list<nodeIndex> values = new list<nodeIndex>();
             nodeIndex index = new nodeIndex { Values = children };
             while (true)
             {
                 if (index.Values == null)
                 {
                     if (values.Count == 0) break;
                     else index = values.Pop();
                 }
                 node = index.Values[index.Index];
                 if (node.children != null) node.removeChilds(isRemove);
                 if (node.children.count() == 0)
                 {
                     if (++index.Index == index.Values.Count) index.Values = null;
                 }
                 else
                 {
                     if (++index.Index != index.Values.Count) values.Add(index);
                     index.Values = node.children;
                     index.Index = 0;
                 }
             }
         }
     }
 }
 private void performOnDict(Dictionary<InputState.Move, ButtonAnimation> animations,
         func myFunc)
 {
     foreach (KeyValuePair<InputState.Move, ButtonAnimation> anim in animations) {
         myFunc(anim.Value);
     }
 }
 void OnDestroy()
 {
     OnGestureEnd = idle;
     OnGestureStart = idle;
     foreach (Gesture gest in g)
         gest.OnAddingTouch = idle;
 }
 public GestureController()
 {
     Instance = this;
     _pressed = false;
     g = new List<Gesture>();
     OnGestureEnd = idle;
     OnGestureStart = idle;
 }
 public Gesture()
 {
     Frames = new List<MouseTouch>();
     OnAddingTouch = onaddingtouch;
 }
示例#52
0
 static BinaryExpression()
 {
     getSimpleExpressions = new func<BinaryExpression, Expression>[fastCSharp.Enum.GetMaxValue<ExpressionType>(-1) + 1];
     getSimpleExpressions[(int)ExpressionType.OrElse] = getSimpleOrElse;
     getSimpleExpressions[(int)ExpressionType.AndAlso] = getSimpleAndAlso;
     getSimpleExpressions[(int)ExpressionType.Equal] = getSimpleEqual;
     getSimpleExpressions[(int)ExpressionType.NotEqual] = getSimpleNotEqual;
     getSimpleExpressions[(int)ExpressionType.GreaterThanOrEqual] = getSimpleGreaterThanOrEqual;
     getSimpleExpressions[(int)ExpressionType.GreaterThan] = getSimpleGreaterThan;
     getSimpleExpressions[(int)ExpressionType.LessThan] = getSimpleLessThan;
     getSimpleExpressions[(int)ExpressionType.LessThanOrEqual] = getSimpleLessThanOrEqual;
     //getSimpleExpressions[(int)expressionType.Add] = getSimpleAdd;
     //getSimpleExpressions[(int)expressionType.AddChecked] = getSimpleAdd;
     //getSimpleExpressions[(int)expressionType.Subtract] = getSimpleSubtract;
     //getSimpleExpressions[(int)expressionType.SubtractChecked] = getSimpleSubtract;
     //getSimpleExpressions[(int)expressionType.Multiply] = getSimpleMultiply;
     //getSimpleExpressions[(int)expressionType.MultiplyChecked] = getSimpleMultiply;
     //getSimpleExpressions[(int)expressionType.Divide] = getSimpleDivide;
     //getSimpleExpressions[(int)expressionType.Modulo] = getSimpleModulo;
     //getSimpleExpressions[(int)expressionType.Power] = getSimplePower;
     //getSimpleExpressions[(int)expressionType.Or] = getSimpleOr;
     //getSimpleExpressions[(int)expressionType.And] = getSimpleAnd;
     //getSimpleExpressions[(int)expressionType.ExclusiveOr] = getSimpleExclusiveOr;
     //getSimpleExpressions[(int)expressionType.LeftShift] = getSimpleLeftShift;
     //getSimpleExpressions[(int)expressionType.RightShift] = getSimpleRightShift;
 }
示例#53
0
文件: Sensor.cs 项目: GibeomGu/flow
 /// <summary>
 /// Constructor which inits the TranslationFunction and RotationFunction attributes.
 /// </summary>
 public Sensor()
 {
     //m_Rotation.Sensor = this;
     //m_Translation.Sensor = this;
     m_TranslationFunction = set_Function(functions.none);
     m_RotationFunction = set_Function(functions.none);
 }
示例#54
0
        public static void init(string ini = "init.ini")
        {
            FileStream iniFile = new FileStream(ini, FileMode.Open, FileAccess.Read);

            StreamReader initRead = new StreamReader(iniFile);

            string data = initRead.ReadToEnd();

            string[] macro = data.Split('#');

            for(int i = 1; i < macro.Length; ++i)
            {

               // Console.WriteLine(macro[i]);

                switch (macro[i])
                {

                    case "NUMBER":
                      //  message += MessagesSender.number;
                        Console.WriteLine("NUMBER");
                        break;
                    case "TIME":
                      //  message += MessagesSender.time;
                        Console.WriteLine("TIME");
                        break;
                    case "ERROR":
                     //   message += MessagesSender.error;
                        Console.WriteLine("ERROR");
                        break;
                    case "MESSAGE":
                        message += MessagesSender.message;
                        Console.WriteLine("MESSAGE");
                        break;
                }

               // message += MessagesSender.space;
            }

              //  message += MessagesSender.endl;

            initDone = true;
            initRead.Close();
            iniFile.Close();
        }
示例#55
0
 /// <summary>
 /// 删除匹配的子节点
 /// </summary>
 /// <param name="isRemove">删除子节点匹配器</param>
 public void RemoveChilds(func<htmlNode, bool> isRemove)
 {
     if (isRemove != null) removeChilds(isRemove);
 }
示例#56
0
 /// <summary>
 /// 节点筛选器解析
 /// </summary>
 /// <param name="start">起始字符位置</param>
 /// <param name="end">结束字符位置</param>
 private filter(char* start, char* end)
 {
     filterFixedMap = filterMap.Byte;
     switch (*start)
     {
         case '/':
             filterMethod = filterChild;
             if (++start != end && start != (end = next(start, end)))
             {
                 char* index = end;
                 if (*--index == ']' && (index = unsafer.String.Find(start, index, '[')) != null)
                 {
                     unsafer.String.ToLower(start, index);
                     getValue(start, index);
                     getIndex(++index, --end);
                 }
                 else
                 {
                     unsafer.String.ToLower(start, end);
                     getValues(start, end);
                 }
             }
             break;
         case '.':
             filterMethod = filterClass;
             if (++start != end) getValues(start, end = next(start, end));
             break;
         case '#':
             name = "id";
             filterMethod = filterValue;
             if (++start != end) getValues(start, end = next(start, end));
             break;
         case '*':
             name = "name";
             filterMethod = filterValue;
             if (++start != end)
             {
                 end = next(start, end);
                 unsafer.String.ToLower(start, end);
                 getValues(start, end);
             }
             break;
         case ':':
             name = "type";
             filterMethod = filterValue;
             if (++start != end) getValues(start, end = next(start, end));
             break;
         case '@':
             filterMethod = filterValue;
             if (++start != end)
             {
                 end = next(start, end);
                 char* value = unsafer.String.Find(start, end, '=');
                 if (value != null)
                 {
                     getName(start, value);
                     if (++value == end) this.value = string.Empty;
                     else getValues(value, end);
                 }
                 else getName(start, end);
             }
             break;
         default:
             filterMethod = filterNode;
             if (*start == '\\') ++start;
             if (start != end)
             {
                 end = next(start, end);
                 unsafer.String.ToLower(start, end);
                 getValues(start, end);
             }
             break;
     }
 }
示例#57
0
文件: uri.cs 项目: khaliyo/fastCSharp
 static uri()
 {
     Assembly uriAssembly = typeof(Uri).Assembly;
     uriInfo = fieldGetValue.Creator.Create(typeof(Uri), "m_Info");
     uriFlags = fieldGetSetValue.Creator.Create(typeof(Uri), "m_Flags");
     uriMoreInfo = fieldGetValue.Creator.Create(uriAssembly, "System.Uri+UriInfo", "MoreInfo", false);
     uriAbsolute = fieldSetValue.createFieldSetValue<string>.Default.Create(uriAssembly, "System.Uri+MoreInfo", "AbsoluteUri", false);
     IsUriField = uriInfo != null && uriFlags.Getter != null && uriFlags.Setter != null && uriMoreInfo != null && uriAbsolute != null;
 }
示例#58
0
 public Gesture()
 {
     Frames = new List<MouseTouch>();
     OnGestureStay = onaddingtouch;
 }