我应该使用哪个数据类型和方法?

编程入门 行业动态 更新时间:2024-10-27 06:24:13
本文介绍了我应该使用哪个数据类型和方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想写一种简单的搜索引擎。我有与特定的关键字相关的主要科目的确定数量。这样做的目的是要认识到从输入部分关键词主体。我想使用的:词典<字符串列表<串GT;> 。我会在本词典搜索和查找,例如,所有关键字开始用3个字符字符串和相关联的主体。

I am trying to write a kind of simple search engine. I have a determined number of main subjects that are associated with specific keywords. The aim is to recognize the main subject from an input partial keyword. I am thinking of using a : Dictionary<string, List<string>>. I'll have to search in this dictionary and find, e.g., all keywords beginning with a 3 characters string and their main subject which is associated.

是我的解决方案最好的?而且我怎么能有效地通过这些数据看,无需手动检查每列表,字符串按字符串。

Is my solution the best one ? And how can I efficiently look through those data without having to check manually every List, string by string.

让我知道,如果我'不明确。

Let my know if I'am not clear.

推荐答案

您正在寻找特里数据结构,它是这样做的推荐的方式开始与搜索。这里是一个博客帖子谈论它。你可以在这里找到的来源。

You're looking for Trie data structure, it is the recommended way of doing starts with search. Here is a blog post talking about it. You can find the source here.

下面是如何使用上面的实现,从上述文章中的代码。

Here's how use the above implementation, code from the above article.

//Create trie Trie < string > trie = new Trie < string > (); //Add some key-value pairs to the trie trie.Put("James", "112"); trie.Put("Jake", "222"); trie.Put("Fred", "326"); //Search the trie trie.Matcher.NextMatch('J'); //Prefix thus far: "J" trie.Matcher.GetPrefixMatches(); //[112, 222] trie.Matcher.IsExactMatch(); //false trie.Matcher.NextMatch('a'); trie.Matcher.NextMatch('m'); //Prefix thus far: "Jam" trie.Matcher.GetPrefixMatches(); //[112] trie.Matcher.NextMatch('e'); trie.Matcher.NextMatch('s'); //Prefix thus far: "James" trie.Matcher.IsExactMatch(); //true trie.Matcher.GetExactMatch(); //112 //Remove a string-value pair trie.Remove("James");

更多推荐

我应该使用哪个数据类型和方法?

本文发布于:2023-11-09 05:17:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571484.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据类型   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!