当前位置: 首页>>代码示例>>C#>>正文


C# IReadOnlyCollection.Distinct方法代码示例

本文整理汇总了C#中IReadOnlyCollection.Distinct方法的典型用法代码示例。如果您正苦于以下问题:C# IReadOnlyCollection.Distinct方法的具体用法?C# IReadOnlyCollection.Distinct怎么用?C# IReadOnlyCollection.Distinct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IReadOnlyCollection的用法示例。


在下文中一共展示了IReadOnlyCollection.Distinct方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CountMinSketch

        private static Dictionary<string, int> CountMinSketch(IReadOnlyCollection<string> listOfM, int k, int t)
        {
            var counterMatrix = new Matrix(t, k);
            //map it out first
            var mMap = new Dictionary<string, int>();
            var distinctM = listOfM.Distinct().ToList();
            for (var i = 0; i < distinctM.Count; i++)
            {
                mMap[distinctM[i]] = i;
            }

            var hashFunctions = HashUtil.HashFunctions(t, k, mMap.Keys.Count).ToList();

            for (var i = 0; i < listOfM.Count; i++)
            {
                var mapResult = mMap[listOfM.ElementAt(i)];

                for (var j = 0; j < t; j++)
                {
                    var hashFunctionResult = hashFunctions[j][mapResult];
                    counterMatrix.SetValue(hashFunctionResult, j,
                        counterMatrix.GetValue(hashFunctionResult, j) + 1
                        );
                }
            }

            var resultDictionary = new Dictionary<string, int>();

            foreach(var kvp in mMap)
            {
                var minResult = int.MaxValue;
                for (var i = 0; i < t; i++)
                {
                    var hashMap = hashFunctions[i][kvp.Value];
                    var tempResult = counterMatrix.GetValue(hashMap, i);
                    if (tempResult < minResult)
                    {
                        minResult = tempResult;
                    }
                }
                resultDictionary[kvp.Key] = minResult;
            }
            return resultDictionary;
        }
开发者ID:roylanceMichael,项目名称:cs_6955_datamining_utah,代码行数:44,代码来源:Hw4.cs

示例2: EnsureUserAgentFactsExist

        public static async Task<IDictionary<string, int>> EnsureUserAgentFactsExist(SqlConnection connection, IReadOnlyCollection<string> userAgents)
        {
            var results = new Dictionary<string, int>();
            if (!userAgents.Any())
            {
                return results;
            }

            var parameterValue = UserAgentFactTableType.CreateDataTable(userAgents.Distinct().ToList());

            var command = connection.CreateCommand();
            command.CommandText = "[dbo].[EnsureUserAgentFactsExist]";
            command.CommandTimeout = _defaultCommandTimeout;
            command.CommandType = CommandType.StoredProcedure;

            var parameter = command.Parameters.AddWithValue("useragents", parameterValue);
            parameter.SqlDbType = SqlDbType.Structured;
            parameter.TypeName = "[dbo].[UserAgentFactTableType]";

            using (var dataReader = await command.ExecuteReaderAsync())
            {
                while (await dataReader.ReadAsync())
                {
                    results.Add(dataReader.GetString(1), dataReader.GetInt32(0));
                }
            }

            return results;
        }
开发者ID:joyhui,项目名称:NuGet.Jobs,代码行数:29,代码来源:Warehouse.cs

示例3: IsStraight

 private bool IsStraight(IReadOnlyCollection<int> list)
 {
     return list.Count == 5 && list.Distinct().Count() == 5 && list.First() == _start && list.Last() == _end;
 }
开发者ID:jjvdgeer,项目名称:Yahtzee,代码行数:4,代码来源:StraightCalculator.cs


注:本文中的IReadOnlyCollection.Distinct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。