public List <Entity> MapReduce(Entity entity, int threshold)
        {
            var result = new List <Entity>();
            //Dictionary<Dictionary<int, int>, int> Map2 = new Dictionary<Dictionary<int, int>, int>();
            var map2 = new List <Map2Reduce>();

            foreach (var user in UserProfiles)
            {
                for (int i = 0; i < user.History.Count; i++)
                {
                    for (int j = 0; j < user.History.Count; j++)
                    {
                        if (j != i)
                        {
                            if (!user.PairVideos.Exists(x => x.Key == user.History[i] &&
                                                        x.Value == user.History[j])
                                &&
                                !user.PairVideos.Exists(x => x.Key == user.History[j] &&
                                                        x.Value == user.History[i])
                                )
                            {
                                user.PairVideos.Add(new PairValue
                                {
                                    Key   = user.History[i],
                                    Value = user.History[j]
                                });
                            }
                        }
                    }
                }

                //Map2.Add(user.PairVideos, 1);
                map2.Add(new Map2Reduce
                {
                    PairVideos = user.PairVideos,
                    //Score = 0
                });
            }

            var all_pairs = new List <PairValue>();

            foreach (var map in map2)
            {
                all_pairs.AddRange(map.PairVideos);
            }


            var distinct_pairs = new List <PairValue>();

            foreach (var pair in all_pairs)
            {
                if (!distinct_pairs.Exists(x => x.Key == pair.Key && x.Value == pair.Value)
                    &&
                    !distinct_pairs.Exists(x => x.Value == pair.Key && x.Key == pair.Value))
                {
                    pair.Score = all_pairs.Count(x => x.Key == pair.Key && x.Value == pair.Value ||
                                                 x.Key == pair.Value && x.Value == pair.Key);
                    distinct_pairs.Add(pair);
                }
            }

            var pair_result = distinct_pairs.Where(x => x.Score >= threshold);


            pair_result = pair_result.Where(x => x.Key == entity.RowNumber ||
                                            x.Value == entity.RowNumber
                                            ).ToList();

            foreach (var item in pair_result)
            {
                if (item.Key != entity.RowNumber)
                {
                    result.Add(Films.FirstOrDefault(x => x.RowNumber == item.Key));
                }
                if (item.Value != entity.RowNumber)
                {
                    result.Add(Films.FirstOrDefault(x => x.RowNumber == item.Value));
                }
            }


            return(result);
        }