検索をスピードアップできるかどうかわかりません。 私は多くのUI画面私は作品を持っているが、私はあなたが検索のスピードアップ.net 4.0
を好きなら、私は速いalgoritimを実装していますこれは、インクリメンタル検索のようなものだことを確認する必要があり 1で使用する必要がある機能を構築する必要があります。これは、リスト内を検索し、2つのレコード
"Guinea and Guinea Bissau "
ユーザータイプなど
const string searchFor = "Gu";
const char nextLetter = 'i'
returns
3 results.
検索する単語を返し
ユーザータイプなど
const string searchFor = "Guinea";
const char nextLetter = ' '
検索する単語これは機能ですが、私はそれをスピードアップしたいと思います。 この種の検索のパターンはありますか?
class Program
{
static void Main()
{
//Find all countries that begin with string + a possible letter added to it
//const string searchFor = "Guinea";
//const char nextLetter = ' '; //returns 2 results
const string searchFor = "Gu";
const char nextLetter = 'i';
List<string> result = FindPossibleMatches(searchFor, nextLetter);
result.ForEach(x=>Console.WriteLine(x)); //returns 3 results
Console.Read();
}
/// <summary>
/// Find all possible matches
/// </summary>
/// <param name="searchFor">string to search for</param>
/// <param name="nextLetter">pretend user as just typed a letter</param>
/// <returns></returns>
public static List<string> FindPossibleMatches (string searchFor, char nextLetter)
{
var hashedCountryList = new HashSet<string>(CountriesList());
var result=new List<string>();
IEnumerable<string> tempCountryList = hashedCountryList.Where(x => x.StartsWith(searchFor));
foreach (string item in tempCountryList)
{
string tempSearchItem;
if (nextLetter == ' ')
{
tempSearchItem = searchFor;
}
else
{
tempSearchItem = searchFor + nextLetter;
}
if(item.StartsWith(tempSearchItem))
{
result.Add(item);
}
}
return result;
}
/// <summary>
/// Returns list of countries.
/// </summary>
public static string[] CountriesList()
{
return new[]
{
"Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
"Angola", "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina",
"Armenia", "Aruba", "Australia", "Austria", "Azerbaijan",
"Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus",
"Belgium", "Belize", "Benin", "Bermuda", "Bhutan",
"Bolivia", "Bosnia Hercegovina", "Botswana", "Bouvet Island", "Brazil",
"Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Byelorussian SSR",
"Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands",
"Central African Republic", "Chad", "Chile", "China", "Christmas Island",
"Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Cook Islands",
"Costa Rica", "Cote D'Ivoire", "Croatia", "Cuba", "Cyprus",
"Czech Republic", "Czechoslovakia", "Denmark", "Djibouti", "Dominica",
"Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador",
"England", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia",
"Falkland Islands", "Faroe Islands", "Fiji", "Finland", "France",
"Gabon", "Gambia", "Georgia", "Germany", "Ghana",
"Gibraltar", "Great Britain", "Greece", "Greenland", "Grenada",
"Guadeloupe", "Guam", "Guatemela", "Guernsey", "Guiana",
"Guinea", "Guinea Bissau", "Guyana", "Haiti", "Heard Islands",
"Honduras", "Hong Kong", "Hungary", "Iceland", "India",
"Indonesia", "Iran", "Iraq", "Ireland", "Isle Of Man",
"Israel", "Italy", "Jamaica", "Japan", "Jersey",
"Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, South",
"Korea, North", "Kuwait", "Kyrgyzstan", "Lao People's Dem. Rep.", "Latvia",
"Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein",
"Lithuania", "Luxembourg", "Macau", "Macedonia", "Madagascar",
"Malawi", "Malaysia", "Maldives", "Mali", "Malta",
"Mariana Islands", "Marshall Islands", "Martinique", "Mauritania", "Mauritius",
"Mayotte", "Mexico", "Micronesia", "Moldova", "Monaco",
"Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar",
"Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles",
"Neutral Zone", "New Caledonia", "New Zealand", "Nicaragua", "Niger",
"Nigeria", "Niue", "Norfolk Island", "Northern Ireland", "Norway",
"Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea",
"Paraguay", "Peru", "Philippines", "Pitcairn", "Poland",
"Polynesia", "Portugal", "Puerto Rico", "Qatar", "Reunion",
"Romania", "Russian Federation", "Rwanda", "Saint Helena", "Saint Kitts",
"Saint Lucia", "Saint Pierre", "Saint Vincent", "Samoa", "San Marino",
"Sao Tome and Principe", "Saudi Arabia", "Scotland", "Senegal", "Seychelles",
"Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands",
"Somalia", "South Africa", "South Georgia", "Spain", "Sri Lanka",
"Sudan", "Suriname", "Svalbard", "Swaziland", "Sweden",
"Switzerland", "Syrian Arab Republic", "Taiwan", "Tajikista", "Tanzania",
"Thailand", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago",
"Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu",
"Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States",
"Uruguay", "Uzbekistan", "Vanuatu", "Vatican City State", "Venezuela",
"Vietnam", "Virgin Islands", "Wales", "Western Sahara", "Yemen",
"Yugoslavia", "Zaire", "Zambia", "Zimbabwe"
};
}
}
}
任意の提案ですか? ありがとう
dbでロードして同様のクエリを実行しますか? – WorldIsRound
はメモリ内で行う必要があります自分自身のdbを使用しない – user9969
nextLetterパラメータの論理的な目的は何ですか? – msigman