本文整理汇总了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;
}
示例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;
}
示例3: IsStraight
private bool IsStraight(IReadOnlyCollection<int> list)
{
return list.Count == 5 && list.Distinct().Count() == 5 && list.First() == _start && list.Last() == _end;
}