本文整理汇总了C#中LinkedListNode.Where方法的典型用法代码示例。如果您正苦于以下问题:C# LinkedListNode.Where方法的具体用法?C# LinkedListNode.Where怎么用?C# LinkedListNode.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedListNode
的用法示例。
在下文中一共展示了LinkedListNode.Where方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RetrieveDocuments
public IEnumerable<IndexResult> RetrieveDocuments(params string[] keywords)
{
keywords = keywords.Where(keyword => index.ContainsKey(keyword)).ToArray();
if (keywords.Length == 0)
{
yield break;
}
PostingsList[] keywordEntries = keywords
.Select(keyword => index[keyword])
//.Select(keyword => (index.ContainsKey(keyword) ? index[keyword] : null))
//.Where(x => (x != null))
//.OrderBy(postingList => postingList.Documents.Count)
.ToArray();
//if (keywordEntries.Length == 0)
//{
// return Enumerable.Empty<IndexResult>();
//}
LinkedListNode<Tuple<long, int>>[] currentNodes = new LinkedListNode<Tuple<long, int>>[keywordEntries.Length];
for (int i = 0; i < keywordEntries.Length; i++)
{
currentNodes[i] = keywordEntries[i].Documents.First;
}
while (currentNodes.Any(x => (x != null)))
{
long smallestID = currentNodes.Where(x => (x != null)).OrderBy(node => node.Value.Item1).First().Value.Item1;
IDictionary<string, int> keywordsPresent = new Dictionary<string, int>();
for (int i = 0; i < keywordEntries.Length; i++)
{
if ((currentNodes[i] != null) && (currentNodes[i].Value.Item1 == smallestID))
{
keywordsPresent[keywords[i]] = currentNodes[i].Value.Item2;
currentNodes[i] = currentNodes[i].Next;
}
}
yield return new IndexResult(documentsByID[smallestID].URI, keywordsPresent);
}
//LinkedList<Tuple<long, int>> matchingDocuments = keywordEntries.Select(postingList => postingList.Documents).Aggregate((postingList1, postingList2) =>
// {
// LinkedList<Tuple<long, int>> newList = new LinkedList<Tuple<long, int>>();
// LinkedListNode<Tuple<long, int>> currentNode1 = postingList1.First;
// LinkedListNode<Tuple<long, int>> currentNode2 = postingList2.First;
// while ((currentNode1 != null) && (currentNode2 != null))
// {
// if (currentNode1.Value.Item1 == currentNode2.Value.Item1)
// {
// newList.AddLast(currentNode1.Value);
// currentNode1 = currentNode1.Next;
// currentNode2 = currentNode2.Next;
// }
// else if (currentNode1.Value.Item1 < currentNode2.Value.Item1)
// {
// currentNode1 = currentNode1.Next;
// }
// else
// {
// currentNode2 = currentNode2.Next;
// }
// }
// return newList;
// });
// return matchingDocuments.Select(document => new IndexResult(documentsByID[document.Item1].URI,
// keywords
// .Where(keyword => index.ContainsKey(keyword))
// .ToDictionary(keyword => keyword, keyword => index[keyword].Documents.Single(doc => doc.Item1 == document.Item1).Item2)));
}