本文整理汇总了C#中MultiDictionary.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# MultiDictionary.ContainsKey方法的具体用法?C# MultiDictionary.ContainsKey怎么用?C# MultiDictionary.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MultiDictionary
的用法示例。
在下文中一共展示了MultiDictionary.ContainsKey方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMatches
private static void GetMatches(string name, HashSet<PhonebookEntry> entries, MultiDictionary<string, PhonebookEntry> dict)
{
if (dict.ContainsKey(name))
{
foreach (var entry in dict[name])
{
if (!entries.Contains(entry))
{
entries.Add(entry);
}
}
}
}
示例2: GetDistinctRecords
private static void GetDistinctRecords(string name, HashSet<Record> foundRecords, MultiDictionary<string, Record> data)
{
//add to the foundRecords only distinct records to avoid
//adding one person with two same names twice
if (data.ContainsKey(name))
{
foreach (var record in data[name])
{
if (!foundRecords.Contains(record))
{
foundRecords.Add(record);
}
}
}
}
示例3: FillPhoneBook
private static MultiDictionary<string, MultiDictionary<string, string>> FillPhoneBook()
{
const string PhonesPath = "phones.txt";
StreamReader phonesReader = new StreamReader(PhonesPath);
var phoneBook = new MultiDictionary<string, MultiDictionary<string, string>>(true);
using (phonesReader)
{
string line = phonesReader.ReadLine();
while (line != null)
{
var splittedEntry = line.Split('|');
string name = splittedEntry[0].Trim();
string town = splittedEntry[1].Trim();
string phoneNumber = splittedEntry[2].Trim();
if (phoneBook.ContainsKey(name))
{
var nameInPhoneBook = phoneBook[name].First();
if (nameInPhoneBook.ContainsKey(town))
{
nameInPhoneBook[town].Add(phoneNumber);
}
else
{
nameInPhoneBook.Add(town, phoneNumber);
}
}
else
{
phoneBook.Add(name, new MultiDictionary<string, string>(true));
var nameInPhoneBook = phoneBook[name].First();
nameInPhoneBook.Add(town, phoneNumber);
}
line = phonesReader.ReadLine();
}
return phoneBook;
}
}
示例4: ReconnectTerminals
private void ReconnectTerminals(Graph workingSolution, Graph problemInstance, Graph problemInstanceDistance)
{
Stopwatch reconnectStopwatch = new Stopwatch();
reconnectStopwatch.Start();
var components = workingSolution.CreateComponentTable();
var componentsToConnect =
components.Where(x => problemInstance.Terminals.Contains(x.Key))
.Select(x => x.Value)
.Distinct()
.ToList();
if (componentsToConnect.Count <= 1) return;
MultiDictionary<int, Tuple<Vertex, Vertex>> componentConnectingPathDictionary = new MultiDictionary<int, Tuple<Vertex, Vertex>>();
List<Vertex> componentGraphVertices = new List<Vertex>();
foreach (var i in componentsToConnect)
componentGraphVertices.Add(new Vertex(i));
Graph componentGraph = new Graph(componentGraphVertices);
for (int i = 0; i < componentsToConnect.Count; i++)
{
int fromComponent = componentsToConnect[i];
for (int j = i + 1; j < componentsToConnect.Count; j++)
{
int toComponent = componentsToConnect[j];
int minDistance = int.MaxValue;
foreach (var fromVertex in components.Where(x => x.Value == fromComponent)
.Select(x => x.Key))
{
var distanceEdges = problemInstanceDistance.GetEdgesForVertex(fromVertex);
foreach (var toVertexEdge in distanceEdges)
{
var toVertex = toVertexEdge.Other(fromVertex);
if (components[toVertex] != toComponent)
continue;
int distance = toVertexEdge.Cost;
if (!componentConnectingPathDictionary.ContainsKey(fromComponent, toComponent))
{
componentConnectingPathDictionary.Add(fromComponent, toComponent, new Tuple<Vertex, Vertex>(fromVertex, toVertex));
componentGraph.AddEdge(new Edge(componentGraphVertices[i], componentGraphVertices[j], minDistance));
}
if (distance < minDistance)
{
minDistance = distance;
componentConnectingPathDictionary[fromComponent, toComponent] = new Tuple<Vertex, Vertex>(fromVertex, toVertex);
componentGraph.GetEdgesForVertex(componentGraphVertices[i])
.Single(x => x.Other(componentGraphVertices[i]) == componentGraphVertices[j])
.Cost = minDistance;
}
}
}
}
}
componentGraph = Algorithms.Kruskal(componentGraph);
foreach (var edge in componentGraph.Edges)
{
var v1 = edge.Either();
var v2 = edge.Other(v1);
var vertices = componentConnectingPathDictionary[v1.VertexName, v2.VertexName];
var path = Algorithms.DijkstraPath(vertices.Item1, vertices.Item2, problemInstance);
foreach (var pathEdge in path.Edges)
workingSolution.AddEdge(pathEdge);
}
reconnectStopwatch.Stop();
}
示例5: AddTypeParameters
private static void AddTypeParameters(GenericNameSyntax genericNameSyntax, MultiDictionary<string, TypeParameterSymbol> map)
{
// NOTE: Dev11 does not warn about duplication, it just matches parameter types to the
// *last* type parameter with the same name. That's why we're iterating backwards and
// skipping subsequent symbols with the same name. This can result in some surprising
// behavior. For example, both 'T's in "A<T>.B<T>" bind to the second implicitly
// declared type parameter.
SeparatedSyntaxList<TypeSyntax> typeArguments = genericNameSyntax.TypeArgumentList.Arguments;
for (int i = typeArguments.Count - 1; i >= 0; i--)
{
// Other types (non-identifiers) are allowed in error scenarios, but they do not introduce new
// cref type parameters.
if (typeArguments[i].Kind() == SyntaxKind.IdentifierName)
{
IdentifierNameSyntax typeParameterSyntax = (IdentifierNameSyntax)typeArguments[i];
Debug.Assert(typeParameterSyntax != null, "Syntactic requirement of crefs");
string name = typeParameterSyntax.Identifier.ValueText;
if (SyntaxFacts.IsValidIdentifier(name) && !map.ContainsKey(name))
{
TypeParameterSymbol typeParameterSymbol = new CrefTypeParameterSymbol(name, i, typeParameterSyntax);
map.Add(name, typeParameterSymbol);
}
}
}
}
示例6: Main
public static void Main(string[] args)
{
StreamReader phones = new StreamReader("..\\..\\phones.txt");
var phonebook = new MultiDictionary<string, MultiDictionary<string, string>>(false);
using (phones)
{
while (!phones.EndOfStream)
{
string entry = phones.ReadLine();
string[] entryInfo = entry.Split('|');
string name = entryInfo[0].Trim();
string location = entryInfo[1].Trim();
string phoneNumber = entryInfo[2].Trim();
if (phonebook.ContainsKey(name))
{
var nameInPhoneBook = phonebook[name].First();
if (nameInPhoneBook.ContainsKey(location))
{
nameInPhoneBook[location].Add(phoneNumber);
}
else
{
nameInPhoneBook.Add(location, phoneNumber);
}
}
else
{
phonebook.Add(name, new MultiDictionary<string, string>(true));
var nameInPhoneBook = phonebook[name].First();
nameInPhoneBook.Add(location, phoneNumber);
}
}
}
var commands = new StreamReader("..\\..\\commands.txt");
using (commands)
{
while (!commands.EndOfStream)
{
string commandString = commands.ReadLine();
string[] parameters = commandString
.Substring(commandString.IndexOf('(') + 1, commandString.IndexOf(')') - commandString.IndexOf('(') - 1)
.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
string name = parameters[0].Trim();
string location = string.Empty;
if (parameters.Length == 2)
{
location = parameters[1].Trim();
}
Console.WriteLine(commandString);
if (location == string.Empty)
{
var resultsByName = phonebook.Where(x => x.Key == name);
foreach (var nameEntries in resultsByName)
{
foreach (var locationPhoneCollection in nameEntries.Value)
{
foreach (var phonesCollection in locationPhoneCollection)
{
foreach (var phoneNumber in phonesCollection.Value)
{
Console.WriteLine("{0} -> {1} -> {2}",
nameEntries.Key, phonesCollection.Key, phoneNumber);
}
}
}
}
}
else
{
var resultsByName = phonebook.Where(x => x.Key == name);
foreach (var nameEntries in resultsByName)
{
foreach (var locationPhoneCollection in nameEntries.Value)
{
var nameAndLocation = locationPhoneCollection.Where(x => x.Key == location);
foreach (var phonesCollection in nameAndLocation)
{
foreach (var phoneNumber in phonesCollection.Value)
{
Console.WriteLine("{0} -> {1} -> {2}", nameEntries.Key, phonesCollection.Key, phoneNumber);
}
}
}
}
}
}
}
}