本文整理汇总了C#中SortedDictionary.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.ContainsKey方法的具体用法?C# SortedDictionary.ContainsKey怎么用?C# SortedDictionary.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedDictionary
的用法示例。
在下文中一共展示了SortedDictionary.ContainsKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetArtists
private static SortedDictionary<string, int> GetArtists(XmlNode rootNode)
{
var artists = new SortedDictionary<string, int>();
if (rootNode == null)
{
throw new ArgumentNullException("rootNode" + "is empty");
}
foreach (var artistName in from XmlNode node in rootNode.ChildNodes
select node["artist"] into xmlElement
where xmlElement != null
select xmlElement.InnerText)
{
if (artists.ContainsKey(artistName))
{
artists[artistName]++;
}
else
{
artists.Add(artistName, 1);
}
}
return artists;
}
示例2: ReadStudentsInfoFromFile
private static void ReadStudentsInfoFromFile(string filePath, SortedDictionary<string, SortedSet<Student>> courses)
{
using (StreamReader reader = new StreamReader(filePath))
{
string line = reader.ReadLine();
while (line != string.Empty && line != null)
{
string[] data = line.Split('|');
string firstName = data[0].Trim();
string lastName = data[1].Trim();
string courseName = data[2].Trim();
if (courses.ContainsKey(courseName))
{
courses[courseName].Add(new Student(firstName, lastName));
}
else
{
courses[courseName] = new SortedSet<Student>();
courses[courseName].Add(new Student(firstName, lastName));
}
line = reader.ReadLine();
}
}
}
示例3: getRateForDate
public decimal getRateForDate(string date, string currency)
{
decimal rate = 0;
string downloadYear = date.Substring(0, 4);
if (ratesHistory == null || year != downloadYear)
{
ratesHistory = downloadHistoryForYear(downloadYear);
}
if (ratesHistory != null && ratesHistory.Count > 0)
{
SortedDictionary<string, RateModel> sortedRatesHistory = new SortedDictionary<string, RateModel>(ratesHistory);
string minimumDate = sortedRatesHistory.First().Key;
if (sortedRatesHistory.ContainsKey(date))
{
rate = sortedRatesHistory[date].GetRateForCurrency(currency);
}
else
{
DateTime minimumDateTime = Convert.ToDateTime(minimumDate);
DateTime checkDate = Convert.ToDateTime(date);
while (checkDate > minimumDateTime && !sortedRatesHistory.ContainsKey(checkDate.ToString("yyyy-MM-dd")))
{
DateTime oldDate = Convert.ToDateTime(date);
checkDate = checkDate.AddDays(-1);
}
string dat = checkDate.ToString("yyyy-MM-dd");
rate = sortedRatesHistory[dat].GetRateForCurrency(currency);
}
}
return rate;
}
示例4: Init
public static void Init()
{
entries = new SortedDictionary<string, Stream>();
string[] archives = Directory.GetFiles(Directory.GetCurrentDirectory(),"*.big",SearchOption.AllDirectories);
foreach (var archive in archives)
{
var content = Loaders.BigArchive.GetEntries(archive);
foreach (var c in content)
{
if (!entries.ContainsKey(c.Key))
entries.Add(c.Key, c.Value);
}
}
string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*", SearchOption.AllDirectories);
foreach (var f in files)
{
if (Path.GetExtension(f)!=".big")
{
var relPath = f.Replace(Directory.GetCurrentDirectory(), "").TrimStart('\\');
if (!entries.ContainsKey(relPath))
entries.Add(relPath, null);
}
}
}
示例5: GetDataConnections
internal static SortedDictionary<string, string> GetDataConnections()
{
SortedDictionary<string, string> databaseList = new SortedDictionary<string, string>();
using (var conn = new SqlCeConnection(CreateStore()))
{
conn.Open();
using (var cmd = new SqlCeCommand())
{
cmd.Connection = conn;
cmd.CommandText = "SELECT FileName, Source FROM Databases";
var rdr = cmd.ExecuteReader();
while (rdr.Read())
{
string key = System.IO.Path.GetFileName(rdr[0].ToString());
int x = 0;
if (databaseList.ContainsKey(key))
{
while (databaseList.ContainsKey(key))
{
x++;
key = string.Format("{0} ({1})", key, x.ToString());
}
}
databaseList.Add(key, rdr[1].ToString());
}
}
}
return databaseList;
}
示例6: FillData
private static void FillData(
SortedDictionary<int, SortedDictionary<string, int>> distanceByUserAndDateTime,
int numberOfInputs)
{
for (int i = 0; i < numberOfInputs; i++)
{
string[] currentLine = Console.ReadLine().Split(' ');
string dateTimeAsString = currentLine[0];
int month = int.Parse(dateTimeAsString.Substring(dateTimeAsString.IndexOf('/') + 1, 2));
string name = currentLine[1];
int distance = int.Parse(currentLine[2]);
if (!distanceByUserAndDateTime.ContainsKey(month))
{
distanceByUserAndDateTime[month] = new SortedDictionary<string, int>();
distanceByUserAndDateTime[month].Add(name, distance);
}
else if (distanceByUserAndDateTime.ContainsKey(month) && !distanceByUserAndDateTime[month].ContainsKey(name))
{
distanceByUserAndDateTime[month].Add(name, distance);
}
else if (distanceByUserAndDateTime.ContainsKey(month) && distanceByUserAndDateTime[month].ContainsKey(name))
{
distanceByUserAndDateTime[month][name] += distance;
}
}
}
示例7: GetSign
//86385cdc024c0f6c
/* 已经尝试的无效的appkey与appsec:
* f3bb208b3d081dc8
* c1b107428d337928 ea85624dfcf12d7cc7b2b3a94fac1f2c
*/
public static string GetSign(SortedDictionary<string, string> sparam)
{
sparam.Add("_appver", "3040000");
sparam.Add("_tid", "0");
sparam.Add("_p", "1");
sparam.Add("_down", "0");
sparam.Add("platform", "android");
sparam.Add("_device", "android");
sparam.Add("_hwid", "ccbb856c97ccb8d2");
sparam.Add("ts", ((long)((DateTime.Now - new DateTime(1970, 1, 1)).TotalSeconds)).ToString());
if (!sparam.ContainsKey("appkey")) sparam.Add("appkey", appkey);
if (!sparam.ContainsKey("type")) sparam.Add("type", "json");
if (!sparam.ContainsKey("appsec")) sparam.Add("appsec", appsec);
string final_param = "";
foreach (var aparam in sparam)
{
if (aparam.Value == null || aparam.Key == "appsec") continue;
if (final_param != "") final_param += "&";
final_param += aparam.Key + "=" + aparam.Value;
}
using (var md5 = MD5.Create())
{
string hashed = BitConverter.ToString(md5.ComputeHash(Encoding.ASCII.GetBytes(final_param + sparam["appsec"]))).Replace("-", "").ToLower();
final_param += "&sign=" + hashed;
}
return final_param;
}
示例8: Main
static void Main()
{
SortedDictionary<string, string> phonebook = new SortedDictionary<string, string>();
string input = "";
while ((input = Console.ReadLine()) != "END")
{
string[] data = input.Split(' ');
string name = String.Empty;
switch (data[0])
{
case "A":
name = data[1];
string phonenumber = data[2];
if (!phonebook.ContainsKey(name))
phonebook[name] = "";
phonebook[name] = phonenumber;
break;
case "S":
name = data[1];
Console.WriteLine(phonebook.ContainsKey(name)
? string.Join(" -> ", name, phonebook[name])
: $"Contact {name} does not exist.");
break;
case "ListAll":
foreach (var phonebookPair in phonebook)
Console.WriteLine(string.Join(" -> ", phonebookPair.Key, phonebookPair.Value));
break;
}
}
}
示例9: calcSignal
public override MethodResult calcSignal(string signal, int c)
{
if (signal.Length == 1)
{
return new MethodResult(0, 0, 0, 0, 0);
}
IDictionary<int, int> terms = new SortedDictionary<int, int>();
int term00 = 0;
int term11 = 2;
var nowTerm = -1;
for (var i = 0; i < signal.Length; i++)
{
if (signal[i] == '0')
{
if (nowTerm != 0)
{
if (term00 > 0)
{
term11 *= 2;
if (term11 > 0 && !terms.ContainsKey(term11))
{
terms.Add(term11, 0);
}
terms[term11]++;
}
term00 = 0;
nowTerm = 0;
}
term00++;
continue;
}
if (signal[i] == '1')
{
if (nowTerm != 3)
{
if (term00 > 0)
{
term00 *= 2;
if (!terms.ContainsKey(term00))
{
terms.Add(term00, 0);
}
terms[term00]++;
}
term00 = 0;
nowTerm = 3;
}
term11++;
}
}
double bit = 1.0 / c ;
double fa = terms.Sum(term => 1.0 / (term.Key * bit) * term.Value) / terms.Sum(term => term.Value);
double f0 = 1.0 / terms.Keys.Min() / bit;
double fn = 1.0 / terms.Keys.Max() / bit;
double fb = 7.0 * f0;
return new MethodResult(f0, fn, fb, fb - fn, fa);
}
示例10: Main
static void Main()
{
SortedDictionary<int, SortedDictionary<string, List<double>>> database = new SortedDictionary<int, SortedDictionary<string, List<double>>>();
SortedDictionary<int, SortedSet<string>> finals = new SortedDictionary<int, SortedSet<string>>();
int n = int.Parse(Console.ReadLine());
for(int i=0;i<n;i++)
{
string[] input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
int month = DateTime.Parse(input[0]).Month;
string name = input[1];
double distance = double.Parse(input[2]);
//new month
if(!database.ContainsKey(month))
{
SortedDictionary<string, List<double>> users = new SortedDictionary<string, List<double>>();
List<double> distances = new List<double>();
distances.Add(distance);
users.Add(name,distances);
database.Add(month, users);
}
//existing month
else if (database.ContainsKey(month))
{
//new name
if(!database[month].ContainsKey(name))
{
List<double> distances = new List<double>();
distances.Add(distance);
database[month].Add(name,distances);
}
//existing name
else if(database[month].ContainsKey(name))
{
database[month][name].Add(distance);
}
}
}
foreach(var pair1 in database)
{
SortedSet<string> usersInfo = new SortedSet<string>();
foreach(var pair2 in pair1.Value)
{
string userInfo = pair2.Key + "(" + pair2.Value.Aggregate((a, b) => b + a) + ")";
usersInfo.Add(userInfo);
}
finals.Add(pair1.Key, usersInfo);
}
foreach(var pair1 in finals)
{
Console.WriteLine("{0}: {1}",pair1.Key,string.Join(", ",pair1.Value));
}
}
示例11: Main
private static void Main(string[] args)
{
ConsistentHash<string> chash = new ConsistentHash<string>();
Console.WriteLine("Adding 10 servers.");
for (int i = 0; i < 10; i++) {
chash.Add("server"+i);
}
Console.WriteLine("Key distributions:");
var counts = new SortedDictionary<string, int>();
for (int i = 0; i < 1000; i++) {
var key = "key"+i;
var server = chash.GetNext(key);
if (!counts.ContainsKey(server)) {
counts[server] = 0;
}
counts[server]++;
}
foreach (var server in counts.Keys) {
Console.WriteLine("There are {0} keys assigned to {1}", counts[server], server);
}
Console.WriteLine("Adding 1 more server.");
chash.Add("serverX");
Console.WriteLine("New key distributions:");
counts.Clear();
for (int i = 0; i < 1000; i++) {
var key = "key"+i;
var server = chash.GetNext(key);
if (!counts.ContainsKey(server)) {
counts[server] = 0;
}
counts[server]++;
}
foreach (var server in counts.Keys) {
Console.WriteLine("There are {0} keys assigned to {1}", counts[server], server);
}
}
示例12: Pizzas
public static SortedDictionary<int, List<string>> Pizzas(params string[] arr)
{
SortedDictionary<int, List<string>> dictionary = new SortedDictionary<int, List<string>>();
foreach(string pizza in arr)
{
int counter = 0;
int index = 0;
char ch = pizza[index];
while(char.IsDigit(ch))
{
counter++;
index++;
ch = pizza[index];
}
int group = int.Parse(pizza.Substring(0, counter));
string name = pizza.Substring(counter);
if(dictionary.ContainsKey(group))
{
dictionary[group].Add(name);
}
else
{
dictionary[group] = new List<string>();
dictionary[group].Add(name);
}
}
return dictionary;
}
示例13: Main
private static void Main()
{
Queue<string> grad = new Queue<string>();
SortedDictionary<string, string> venueAndEvent = new SortedDictionary<string, string>();
while (true)
{
string[] readLineComand = Console.ReadLine().Split(';').ToArray();
if (readLineComand[0] == "END")
{
for (int i = 0; i < grad.Count; i++)
{
Console.WriteLine(grad.Peek());
foreach (KeyValuePair<string, string> p in venueAndEvent)
{
Console.WriteLine("->{0}: {1}", p.Key, p.Value);
}
}
return;
}
if (venueAndEvent.ContainsKey(readLineComand[1]))
{
string value = venueAndEvent[readLineComand[1]];
venueAndEvent.Remove(readLineComand[1]);
venueAndEvent.Add(readLineComand[1], value + value);
}
else if (true)
{
grad.Enqueue(readLineComand[0]);
venueAndEvent.Add(readLineComand[1], readLineComand[2]);
}
}
}
示例14: CalculateProbabilities
/// <summary>
/// Do the math to populate the probabilities collection
/// </summary>
public SortedDictionary<string, double> CalculateProbabilities(SortedDictionary<string, double> _bad, SortedDictionary<string, double> _good)
{
SortedDictionary<string, double> _prob = new SortedDictionary<string, double>();
_ngood = _good.Count;
_nbad = _bad.Count;
foreach (string token in _good.Keys)
{
Double? pb = CalculateTokenProbability(token, _bad, _good);
if (pb != null)
{
_prob[token] = (double)pb;
}
}
foreach (string token in _bad.Keys)
{
if (!_prob.ContainsKey(token))
{
Double? pb = CalculateTokenProbability(token, _bad, _good);
if (pb != null)
{
_prob[token] = (double)pb;
}
}
}
return _prob;
}
示例15: GetLocales
// Use the standard root node to get a list of locales available.
public static SortedDictionary<string, string> GetLocales()
{
SortedDictionary<string, string> locales = new SortedDictionary<string, string>();
getContentRequest request = new getContentRequest();
ContentService proxy = new ContentService();
getContentResponse response;
request.contentIdentifier = rootContentItem.contentId;
request.locale = "en-US"; // Now required otherwise an exception.
try
{
response = proxy.GetContent(request);
}
catch
{
locales.Add("English (United States)", "en-us");
return locales;
}
foreach (availableVersionAndLocale av in response.availableVersionsAndLocales)
{
// Use the DisplayName as the key instead of the locale because
// that's how we want the collection sorted.
string displayName = new CultureInfo(av.locale).DisplayName;
if (locales.ContainsKey(displayName) == false)
locales.Add(displayName, av.locale.ToLower());
}
return locales;
}