Exemplo n.º 1
0
    public static Dictionary <T, List <U> > ToDictionary <T, U> (List <V> list, MapFunc <V, T> mapFunc1, MapFunc <V, T> mapFunc2)
    {
        Dictionary <T, List <U> > tmpDic = new Dictionary <T, List <U> >();

        /* Parcourir tous les elements de list */
        foreach (V keyval in list)
        {
            List <U> values;
            /* si le dictionnaire contient déjà la clé */
            if (tmpDic.ContainsKey(mapFunc1(keyval)))
            {
                tmpDic.TryGetValue(mapFunc1(keyval), out values); /* récupérer la liste des valeurs déjà existantes du dictionnaire */
                values.Add(mapFunc2(keyval));                     /* y ajouter la nouvelle valeur */
                tmpDic[mapFunc1(keyval)] = values;                /* mettre a jour la liste des valeurs */
            }
            else
            {
                values = new List <U>();              /* créer une nouvelle liste des valeurs */
                values.Add(mapFunc2(keyval));         /* y ajouter la valeur */
                tmpDic.Add(mapFunc1(keyval), values); /* ajouter au dictionnaire */
            }
        }

        return(tmpDic);
    }
Exemplo n.º 2
0
 public int SetMaxLength(List <T> data)
 {
     MaxLength = data.Select(x => MapFunc.Invoke(x).Length).Max();
     if (Header.Length > MaxLength)
     {
         MaxLength = Header.Length;
     }
     return(MaxLength);
 }
 static Ret[] Map <Input, Ret>(MapFunc <Input, Ret> fn, Input[] a)
 {
     Ret[] list = new Ret[a.Length];
     for (int i = 0; i < a.Length; ++i)
     {
         list[i] = fn(a[i]);
     }
     return(list);
 }
Exemplo n.º 4
0
 public static void AddMapped <FromType, ToType>(
     this ICollection <ToType> toC,
     ICollection <FromType> fromC,
     MapFunc <FromType, ToType> m)
 {
     foreach (var o in fromC)
     {
         toC.Add(m(o));
     }
 }
Exemplo n.º 5
0
    public static List <TOut> Map <TIn, TOut>(List <TIn> list, MapFunc <TOut, TIn> func)
    {
        List <TOut> newList = new List <TOut>(list.Count);

        for (int i = 0; i < list.Count; i++)
        {
            newList.Add(func(list[i]));
        }

        return(newList);
    }
Exemplo n.º 6
0
    /* fonction Map  */
    public static List <TOut> Map <T, TOut> (List <T> list, MapFunc <T, TOut> mapFunc)
    {
        List <TOut> tmpList = new List <TOut>();

        foreach (T i in list)
        {
            tmpList.Add(mapFunc(i));
        }

        return(tmpList);
    }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            TimeFunc <Vector> f  = (t, y) => new Vector(6 * t, (float)Math.Exp(t));
            MapFunc <Vector>  df = v => new Vector(6, v.Y);

            var plot = new Plot(0, 20, 50, -2, 18, 50, 20);

            plot.DrawVectorField(df, Color.Aqua);
            plot.DrawCurve(f, Vector.Zero, 0, 3, 0.1f, Color.Black);
            plot.DrawErrorMargin(f, Vector.Zero, t => 0.1f * t * t, 0, 3, 0.01f, Color.FromArgb(40, 255, 0, 0));
            plot.Save("test.png");
            Process.Start("test.png");
        }
Exemplo n.º 8
0
        public static ToType[] Map <FromType, ToType>(this FromType[] a, MapFunc <FromType, ToType> mapFunc)
        {
            if (a == null)
            {
                return(null);
            }
            var result = new ToType[a.Length];

            for (var i = 0; i < a.Length; i++)
            {
                result[i] = mapFunc(a[i]);
            }
            return(result);
        }
Exemplo n.º 9
0
        public Future <T> Recover(MapFunc <Exception, T> recoverFunc)
        {
            var f = new FutureImpl <T>();

            OnComplete(obj => {
                if (obj.Success)
                {
                    f.SetResult(result);
                }
                else
                {
                    f.SetResult(recoverFunc(error));
                }
            });
            return(f);
        }
Exemplo n.º 10
0
        public Future <To> Map <To> (MapFunc <T, To> mapFunc)
        {
            var f = new FutureImpl <To>();

            OnComplete(obj => {
                if (obj.Success)
                {
                    f.SetResult(mapFunc(result));
                }
                else
                {
                    f.SetError(error);
                }
            });
            return(f);
        }
Exemplo n.º 11
0
        public ILispNode Map(MapFunc map, CallStack callStack, params object [] args)
        {
            var rgMapped = this.Select(x => map(x, callStack, args));

            var missing = rgMapped.Aggregate(
                new LispMissing(),
                (r, x) => (x is LispMissing)
                    ? r.Merge(x as LispMissing)
                    : r);

            if (missing.Count() > 0)
            {
                return(missing);
            }

            return(new LispList(null, rgMapped));
        }
Exemplo n.º 12
0
        public static void DrawVectorField(this Plot plot, MapFunc <Vector> func, Color color)
        {
            int xMin = (int)Math.Ceiling(plot.XMin);
            int xMax = (int)Math.Floor(plot.XMax);
            int yMin = (int)Math.Ceiling(plot.YMin);
            int yMax = (int)Math.Floor(plot.YMax);

            for (int x = xMin; x <= xMax; x++)
            {
                for (int y = yMin; y <= yMax; y++)
                {
                    var p = new Vector(x, y);
                    var v = func(p) / 10;
                    plot.PlotCurve(new PointF[] { p, p + v }, color);
                }
            }
        }
Exemplo n.º 13
0
        public static ToType[] MapToArray <FromType, ToType>(
            this IEnumerable <FromType> a,
            MapFunc <FromType, ToType> mapFunc)
        {
            if (a == null)
            {
                return(null);
            }
            var c      = a as ICollection <FromType>;
            var result = new ToType[c != null ? c.Count : a.Count()];
            var i      = 0;

            foreach (var x in a)
            {
                result[i] = mapFunc(x);
                i++;
            }
            return(result);
        }
Exemplo n.º 14
0
    //-------------------------------------------------------------------------
    // 玩家请求
    public Task <MethodData> c2sRequest(MethodData method_data)
    {
        Func <MethodData, Task <MethodData> > func = null;

        MapFunc.TryGetValue(method_data.method_id, out func);
        if (func != null)
        {
            return(func(method_data));
        }
        else
        {
            // log error
            string error_msg = string.Format("CellPlayer.s2sPlayerRequest() EtGuid={0} Not Found MethodId={1}",
                                             Entity.Guid, method_data.method_id.ToString());
            EbLog.Error(error_msg);

            MethodData result = new MethodData();
            result.method_id = MethodType.None;
            return(Task.FromResult(result));
        }
    }
Exemplo n.º 15
0
 public Function(MapFunc <float> func_a, MapFunc <float2> func_b, MapFunc <float3> func_c)
 {
     this.func_a = func_a;
     this.func_b = func_b;
     this.func_c = func_c;
 }
Exemplo n.º 16
0
 public void AddMapping <TFrom, TTo>(MapFunc <TFrom, TTo> func)
 {
     AddMappingOneOf <TFrom, TTo>(func);
 }