Exemplo n.º 1
0
        public static List <GenericUserSimilarity.UserUserSimilarity> GetTopUserUserSimilarities(
            int howMany, IEnumerator <GenericUserSimilarity.UserUserSimilarity> allSimilarities)
        {
            var topSimilarities
                = new SortedSet <GenericUserSimilarity.UserUserSimilarity>();
            bool   full           = false;
            double lowestTopValue = Double.NegativeInfinity;

            while (allSimilarities.MoveNext())
            {
                GenericUserSimilarity.UserUserSimilarity similarity = allSimilarities.Current;
                double value = similarity.getValue();
                if (!Double.IsNaN(value) && (!full || value > lowestTopValue))
                {
                    topSimilarities.Add(similarity);
                    if (full)
                    {
                        topSimilarities.Remove(topSimilarities.Max);// topSimilarities.poll();
                    }
                    else if (topSimilarities.Count > howMany)
                    {
                        full = true;
                        topSimilarities.Remove(topSimilarities.Max);//topSimilarities.poll();
                    }
                    lowestTopValue = topSimilarities.Max.getValue();
                }
            }
            int size   = topSimilarities.Count;
            var result = new List <GenericUserSimilarity.UserUserSimilarity>(size);

            result.AddRange(topSimilarities);
            return(result);
        }
Exemplo n.º 2
0
        public static List <GenericUserSimilarity.UserUserSimilarity> getTopUserUserSimilarities(int howMany, IEnumerator <GenericUserSimilarity.UserUserSimilarity> allSimilarities)
        {
            SortedSet <GenericUserSimilarity.UserUserSimilarity> collection = new SortedSet <GenericUserSimilarity.UserUserSimilarity>();
            bool   flag             = false;
            double negativeInfinity = double.NegativeInfinity;

            while (allSimilarities.MoveNext())
            {
                GenericUserSimilarity.UserUserSimilarity current = allSimilarities.Current;
                double d = current.getValue();
                if (!double.IsNaN(d) && (!flag || (d > negativeInfinity)))
                {
                    collection.Add(current);
                    if (flag)
                    {
                        collection.Remove(collection.Max);
                    }
                    else if (collection.Count > howMany)
                    {
                        flag = true;
                        collection.Remove(collection.Max);
                    }
                    negativeInfinity = collection.Max.getValue();
                }
            }
            List <GenericUserSimilarity.UserUserSimilarity> list = new List <GenericUserSimilarity.UserUserSimilarity>(collection.Count);

            list.AddRange(collection);
            return(list);
        }