Esempio n. 1
0
 public static IntervalDictionary <K, VR> Mix <K, V1, V2, VR>(this IntervalDictionary <K, V1> me, IntervalDictionary <K, V2> other, Func <Interval <K>, IntervalValue <V1>, IntervalValue <V2>, IntervalValue <VR> > mixer)
     where K : struct, IComparable <K>, IEquatable <K>
 {
     Interval <K>[] keys = me.Intervals.Concat(other.Intervals).SelectMany(a => a.Elements()).Distinct().OrderBy().BiSelect((min, max) => new Interval <K>(min, max)).ToArray();
     return(new IntervalDictionary <K, VR>(keys
                                           .Select(k => new { Intervalo = k, Valor = mixer(k, me.TryGetValue(k.Min), other.TryGetValue(k.Min)) })
                                           .Where(a => a.Valor.HasInterval).Select(a => KVP.Create(a.Intervalo, a.Valor.Value))));
 }
Esempio n. 2
0
        public static IntervalDictionary <K, VR> Mix <K, V1, V2, VR>(this IntervalDictionary <K, V1> me, IntervalDictionary <K, V2> other, Func <Interval <K>, IntervalValue <V1>, IntervalValue <V2>, IntervalValue <VR> > mixer)
            where K : struct, IComparable <K>, IEquatable <K>
        {
#pragma warning disable CS8629 // Nullable value type may be null. CSBUG
            Interval <K>[] keys = me.Intervals.Concat(other.Intervals).SelectMany(a => a.Elements()).Distinct().OrderBy().BiSelectS((min, max) => new Interval <K>(min.Value, max.Value)).ToArray();
#pragma warning restore CS8629 // Nullable value type may be null.
            return(new IntervalDictionary <K, VR>(keys
                                                  .Select(k => new { Intervalo = k, Valor = mixer(k, me.TryGetValue(k.Min), other.TryGetValue(k.Min)) })
                                                  .Where(a => a.Valor.HasInterval).Select(a => KeyValuePair.Create(a.Intervalo, a.Valor.Value))));
        }
        public SquareDictionary(IEnumerable <Tuple <Square <K1, K2>, V> > dictionary)
        {
            IEnumerable <Square <K1, K2> > squares = dictionary.Select(p => p.Item1);

            xDimension = squares.ToIndexIntervalDictinary(s => s.XInterval.Elements());
            yDimension = squares.ToIndexIntervalDictinary(s => s.YInterval.Elements());

            values = new V[xDimension.Count, yDimension.Count];
            used   = new bool[xDimension.Count, yDimension.Count];

            foreach (var item in dictionary)
            {
                Add(item.Item1, item.Item2);
            }
        }
Esempio n. 4
0
        public static IntervalDictionary <K, VR> Filter <K, V, VR>(this IntervalDictionary <K, V> me, Interval <K> filter, Func <Interval <K>, V, VR> mapper)
            where K : struct, IComparable <K>, IEquatable <K>
        {
            IntervalDictionary <K, VR> result = new IntervalDictionary <K, VR>();

            foreach (var item in me)
            {
                var intersection = item.Key.Intersection(filter);
                if (intersection != null)
                {
                    result.Add(intersection.Value, mapper(intersection.Value, item.Value));
                }
            }
            return(result);
        }
Esempio n. 5
0
        internal static IntervalDictionary <K, int> ToIndexIntervalDictinary <Q, K>(this IEnumerable <Q> squares, Func <Q, IEnumerable <K> > func)
            where K : struct, IComparable <K>, IEquatable <K>
        {
            List <K> list = squares.SelectMany(func).Distinct().ToList();

            list.Sort();

            IntervalDictionary <K, int> result = new IntervalDictionary <K, int>();

            for (int i = 0; i < list.Count - 1; i++)
            {
                result.Add(new Interval <K>(list[i], list[i + 1]), i);
            }

            return(result);
        }
Esempio n. 6
0
        public CubeDictionary(IEnumerable <Tuple <Cube <K1, K2, K3>, V> > dic)
        {
            IEnumerable <Cube <K1, K2, K3> > cubes = dic.Select(p => p.Item1);

            xDimension = cubes.ToIndexIntervalDictinary(c => c.XInterval.Elements());
            yDimension = cubes.ToIndexIntervalDictinary(c => c.YInterval.Elements());
            zDimension = cubes.ToIndexIntervalDictinary(c => c.ZInterval.Elements());

            values = new V[xDimension.Count, yDimension.Count, zDimension.Count];
            used   = new bool[xDimension.Count, yDimension.Count, zDimension.Count];


            foreach (var item in dic)
            {
                Add(item.Item1, item.Item2);
            }
        }