Exemplo n.º 1
0
        /// <summary>
        /// Mix two collection
        /// </summary>
        /// <typeparam name="TItem2">Item2 type</typeparam>
        /// <typeparam name="TResult">Return item type</typeparam>
        /// <param name="mixWith">Mix collection</param>
        /// <param name="transform">The Transform</param>
        /// <returns>Mixed collection</returns>
        public WeightedCollection <TResult> Mix <TItem2, TResult>(
            WeightedCollection <TItem2> mixWith, Func <TItem, TItem2, TResult> transform)
        {
            this.Init();
            mixWith.Init();
            var ret = new WeightedCollection <TResult>();

            foreach (var w1 in this.weightList.GroupBy(w => w))
            {
                foreach (var w2 in mixWith.weightList.GroupBy(w => w))
                {
                    ret.Add(transform(this.Items[w1.Key], mixWith.Items[w2.Key]), w1.Count() * w2.Count());
                }
            }

            return(ret);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Union two collections
        /// </summary>
        /// <param name="unionWith">unit collection</param>
        /// <returns>union collection</returns>
        public WeightedCollection <TItem> Union(WeightedCollection <TItem> unionWith)
        {
            this.Init();
            unionWith.Init();
            var ret = new WeightedCollection <TItem>();

            foreach (var w1 in this.weightList.GroupBy(w => w))
            {
                ret.Add(this.Items[w1.Key], w1.Count());
            }

            foreach (var w1 in unionWith.weightList.GroupBy(w => w))
            {
                ret.Add(unionWith.Items[w1.Key], w1.Count());
            }

            return(ret);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Mix two collections
 /// </summary>
 /// <typeparam name="TItem2">Item2 type</typeparam>
 /// <param name="mixWith">mixwith collection</param>
 /// <returns>Mixed collection</returns>
 public WeightedCollection <Tuple <TItem, TItem2> > Mix <TItem2>(WeightedCollection <TItem2> mixWith)
 {
     return(Mix(mixWith, Tuple.Create));
 }