Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace HashDictionary
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- var location = new GeoLocation();
- var city = new City();
- Console.WriteLine("Choose what you want to do:\n1. Run test on hashtable.\n2. Search for a city.");
- switch (Console.ReadKey(false).Key)
- {
- case ConsoleKey.D1:
- HashDictionary<int, int> d = new HashDictionary<int, int>(10000);
- HashtableTester.TestDriver.Instance.Run(d, 10000);
- Console.ReadKey();
- break;
- case ConsoleKey.D2:
- HashDictionary<GeoLocation, City> e = new HashDictionary<GeoLocation, City>(10000);
- const string f = "cities100000.txt";
- using (StreamReader r = new StreamReader(f))
- {
- var lines = File.ReadAllLines(f);
- foreach (var line in lines)
- {
- var words = line.Split('\t');
- var cityHolder = city.Add(words[0], words[3]);
- var locationHolder = location.Add(words[1], words[2]);
- e.Add(locationHolder, cityHolder);
- }
- }
- Console.WriteLine("\nEnter a latitude:");
- string latitude = Console.ReadLine();
- Console.WriteLine("Enter a longitude:");
- string longitude = Console.ReadLine();
- var RequestedKey = location.Add(latitude, longitude);
- if (e.ContainsKey(RequestedKey))
- {
- City RequestedCity;
- e.TryGetValue(RequestedKey, out RequestedCity);
- Console.WriteLine(RequestedCity.Name);
- Console.WriteLine(RequestedCity.Population);
- Console.ReadLine();
- }
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement