static void Main() { var dict = new BiDictionary<int, string, int>(); dict.Add(25, "10", 1); dict.Add(25, "5", 2); dict.Add(15, "3", 3); dict.Add(15, "1", 4); dict.Add(15, "2", 5); dict.Add(12, "10", 5); dict.Add(25, "10", 6); dict.Add(12, "10", 7); dict.Add(25, "10", 8); Console.WriteLine("First Dictionary"); Console.WriteLine(dict[5]); Console.WriteLine(dict[25]); Console.WriteLine(dict[15]); Console.WriteLine(dict["10"]); Console.WriteLine("{{{0}}}", string.Join(",", dict[25, "10"])); var dict2 = new BiDictionary<int, int, int>(); dict2.Add(25, 10, 1); dict2.Add(25, 10, 1); dict2.Add(25, 10, 1); dict2.Add(25, 10, 2); dict2.Add(25, 10, 2); Console.WriteLine("Second Dictionary"); //This cannot be called because both keys are ints //Console.WriteLine(dict2[25]); Console.WriteLine("{{{0}}}", string.Join(",", dict2[25, 10])); }
public static void Main() { var biDict = new BiDictionary<string, string, List<int>>(); biDict.Add("Ivan", "DSA", new List<int>() { 100, 20, 30 }); biDict.Add("Pesho", "HQC", new List<int>() { 10, 40, 25 }); biDict.Add("Gosho", "DSA", new List<int>() { 55, 66, 77 }); biDict.Add("Gosho", "HQC", new List<int>() { 5, 6, 7 }); Console.WriteLine("Searching Pesho's scores"); var result1 = biDict.FindByFirstKey("Pesho"); foreach (var item in result1) { Console.WriteLine(string.Join(", ", item)); } Console.WriteLine("--------------------------------"); Console.WriteLine("Searching for all scores in DSA"); var result2 = biDict.FindBySecondKey("DSA"); foreach (var item in result2) { Console.WriteLine(string.Join(", ", item)); } Console.WriteLine("--------------------------------"); Console.WriteLine("Searching for DSA's scores of Gosho"); var result3 = biDict.FindByBothKeys("Gosho", "DSA"); foreach (var item in result3) { Console.WriteLine(string.Join(", ", item)); } }
static void Main(string[] args) { BiDictionary<string, string, string> dictionary = new BiDictionary<string, string, string>(); dictionary.Add("Ivko", "mivko", "Ivko Mivko"); dictionary.Add("Telerik", "Academy", "Telerik aka"); dictionary.Add("Telerik", "asdf", "Peter Petrov"); dictionary.Add("asdf", "Academy", "Dancho Danchev"); var fromSofia = dictionary.FindByFistKey("Ivko"); foreach (var item in fromSofia) { Console.WriteLine(item); } var manGender = dictionary.FindBySecondKey("asdf"); foreach (var item in manGender) { Console.WriteLine(item); } var manFromPlovdiv = dictionary.FindByBothKeys("Telerik", "Academy"); foreach (var item in manFromPlovdiv) { Console.WriteLine(item); } }
public static void Main() { var biDictionary = new BiDictionary<bool, int, string>(); biDictionary.Add(true, 18, "Ivan Petrov"); biDictionary.Add(false, 18, "Gergana Mihova"); biDictionary.Add(true, 30, "Petkan Iliev"); biDictionary.Add(false, 25, "Ani Petrova"); biDictionary.Add(true, 45, "Georgi Ivanov"); biDictionary.Add(true, 45, "Pesho Goshov"); biDictionary.Add(true, 45, "Miho Mihov"); biDictionary.Add(false, 28, "Petranka Petrova"); biDictionary.Add(false, 28, "Ivanka Ivanova"); biDictionary.Add(false, 28, "Pepa Petrova"); // all men Console.WriteLine(biDictionary.FindByFirstKey(true)); // all 45 years old Console.WriteLine(biDictionary.FindBySecondKey(45)); // all women 28 years old Console.WriteLine(biDictionary.FindByBothKeys(false, 28)); // all 50 years old men Console.WriteLine(biDictionary.FindByBothKeys(true, 50)); // empty collection !!! }
static void Main(string[] args) { try { const int NumberOfItems = 10; BiDictionary<string, string, int> collection = new BiDictionary<string, string, int>(); for (int i = 0; i < NumberOfItems; i++) { collection.Add("K1" + i, "K2" + i, i); } for (int i = 0; i < NumberOfItems; i++) { collection.Add("K1" + i, "K2" + i, i * 7); } Console.WriteLine(collection.Find("K29").Count()); Console.WriteLine(collection.Find("K19", "K29").Count()); Console.WriteLine(collection.Find("K199").Count()); } catch (InvalidOperationException iex) { Console.WriteLine(iex.Message); } }
public static void Main() { var dictionary = new BiDictionary<int, char, string>(); dictionary.Add(1, 'a', "pesho"); dictionary.Add(2, 'b', "gosho"); dictionary.Add(1, 'c', "ivancho"); dictionary.Add(3, 'c', "mariika"); // searching by first key var firstKey = 1; var resultsByFirstKey = dictionary.Search(firstKey); Console.WriteLine("All values with first key: {0}", firstKey); foreach (var value in resultsByFirstKey) { Console.WriteLine(value); } // searching by second key var secondKey = 'c'; var resultsBySecondKey = dictionary.Search(secondKey); Console.WriteLine("All values with second key: {0}", secondKey); foreach (var value in resultsBySecondKey) { Console.WriteLine(value); } // searching by both keys var resultsByBothKeys = dictionary.Search(firstKey, secondKey); Console.WriteLine("All values with first key {0} and second key {1}", firstKey, secondKey); foreach (var value in resultsByBothKeys) { Console.WriteLine(value); } }
static void Main(string[] args) { BiDictionary<string, string, string> dictionary = new BiDictionary<string, string, string>(); dictionary.Add("Lovech", "man", "Georgi Georgiev"); dictionary.Add("Lovech", "woman", "Nina Todorova"); dictionary.Add("Lovech", "woman", "Martina Nikolova"); dictionary.Add("Sofia", "woman", "Elizabet Sokolova"); dictionary.Add("Lovech", "man", "Tosho Kyltyrista"); Console.WriteLine("People from Lovech:"); foreach (var item in dictionary.FindByFistKey("Lovech")) { Console.WriteLine(item); } Console.WriteLine(); Console.WriteLine("Girls:"); var girls = dictionary.FindBySecondKey("woman"); foreach (var girl in girls) { Console.WriteLine(girl); } Console.WriteLine(); Console.WriteLine("Me and Tosho"); foreach (var person in dictionary.FindByBothKeys("Lovech", "man")) { Console.WriteLine(person); } }
static void Main(string[] args) { BiDictionary<string, string, string> dictionary = new BiDictionary<string, string, string>(); dictionary.Add("Sofia", "man", "Ivo Ivanov"); dictionary.Add("Sofia", "woman", "Maria Ivanova"); dictionary.Add("Plovdiv", "man", "Peter Petrov"); dictionary.Add("Plovdiv", "woman", "Lili Georgieva"); Console.WriteLine("\nAll from Sofia"); var fromSofia = dictionary.FindByFistKey("Sofia"); foreach (var item in fromSofia) { Console.WriteLine(item); } Console.WriteLine("\nAll man"); var manGender = dictionary.FindBySecondKey("man"); foreach (var item in manGender) { Console.WriteLine(item); } Console.WriteLine("\nAll Plovdiv and man"); var manFromPlovdiv = dictionary.FindByBothKeys("Plovdiv", "man"); foreach (var item in manFromPlovdiv) { Console.WriteLine(item); } }
public static void Main() { var multi = new BiDictionary<int, string, string>(); multi.Add(1, "one", "firstElement"); multi.Add(1, "two", "mixed"); multi.Add(2, "two", "secondElement"); Console.WriteLine("first key :"); var result1 = multi.FindByFirstKey(1); foreach (var item in result1) { Console.WriteLine(item); } Console.WriteLine("second key :"); var result2 = multi.FindBySecondKey("two"); foreach (var item in result2) { Console.WriteLine(item); } Console.WriteLine("both keys :"); var result3 = multi.FindByBothKeys(1, "two"); foreach (var item in result3) { Console.WriteLine(item); } }
public void BiDictionaryClear_Test() { var dictionary = new BiDictionary<object, object>(); dictionary.Add("test", "test"); dictionary.Add("test2", "test2"); dictionary.Clear(); Assert.Empty(dictionary); }
public static void Main() { BiDictionary<int, int, string> biDict = new BiDictionary<int, int, string>(); biDict.Add(1, 1, "First"); biDict.Add(1, 2, "Second"); biDict.Add(2, 1, "Third"); Console.WriteLine(); }
public static void Main() { BiDictionary<string, string, Student> students = new BiDictionary<string, string, Student>(); List<string> firstKeysTest = new List<string>(); List<string> secondKeysTest = new List<string>(); List<string> bothKeysTest = new List<string>(); Random random = new Random(); for (int i = 0; i < 10; i++) { var lengthFirstName = random.Next(2, 20); string firstName = GetRandomString(lengthFirstName, random); var lengthLastName = random.Next(2, 20); string lastName = GetRandomString(lengthLastName, random); Student student1 = new Student(firstName, lastName); students.Add(student1.FirstName, student1.LastName, student1); firstKeysTest.Add(student1.FirstName); secondKeysTest.Add(student1.LastName); bothKeysTest.Add(student1.FirstName + student1.LastName); if (i % 2 == 0) { Student student2 = new Student(firstName, lastName); students.Add(student2.FirstName, student2.LastName, student2); firstKeysTest.Add(student2.FirstName); secondKeysTest.Add(student2.LastName); bothKeysTest.Add(student2.FirstName + student2.LastName); } } for (int i = 0; i < 10; i++) { var searchedFirstNameIndex = random.Next(0, firstKeysTest.Count); var studentsByFirstName = students.FindByFirstKey(firstKeysTest[searchedFirstNameIndex]); Console.WriteLine("New Search"); Console.WriteLine("Students searched by first name:"); foreach (var st in studentsByFirstName) { Console.WriteLine("Student:" + st.FirstName + " " + st.LastName); } var searchedLastNameIndex = random.Next(0, secondKeysTest.Count); var studentsByLastName = students.FindBySecondKey(secondKeysTest[searchedLastNameIndex]); Console.WriteLine("Students searched by last name:"); foreach (var st in studentsByLastName) { Console.WriteLine("Student:" + st.FirstName + " " + st.LastName); } var studentsByBothNames = students.FindByBothKeys(firstKeysTest[i], secondKeysTest[i]); Console.WriteLine("Students searched by both names:"); foreach (var st in studentsByBothNames) { Console.WriteLine("Student: " + st.FirstName + " " + st.LastName); } Console.WriteLine(); } }
protected override void OnCreate(Bundle bundle) { RequestWindowFeature(WindowFeatures.ActionBar); base.OnCreate(bundle); SetContentView(Resource.Layout.WikiPracticeActivity); modeLayouts = new Dictionary<ServerData.TaskType, LinearLayout>(); modeNames = new BiDictionary<ServerData.TaskType, string>(); wikiText = FindViewById<TextView>(Resource.Id.wiki_text); wikiImage = FindViewById<ImageView>(Resource.Id.wiki_image); startBtn = FindViewById<Button>(Resource.Id.wiki_startBtn); startBtn.Click += startBtn_Click; // Pacing layout metronBpmText = FindViewById<TextView>(Resource.Id.wiki_bpm); metronDownBtn = FindViewById<Button>(Resource.Id.wiki_downBtn); metronDownBtn.Click += downBtn_Click; metronUpBtn = FindViewById<Button>(Resource.Id.wiki_upBtn); metronUpBtn.Click += upBtn_Click; metronControlsLayout = FindViewById<LinearLayout>(Resource.Id.wiki_speedControls); modeLayouts.Add(ServerData.TaskType.Pacing, metronControlsLayout); modeNames.Add(ServerData.TaskType.Pacing, "Speech Pacing"); // Loudness layout loudVolText = FindViewById<TextView>(Resource.Id.wiki_volume); loudTargetText = FindViewById<TextView>(Resource.Id.wiki_Targetvolume); loudTargetButton = FindViewById<Button>(Resource.Id.wiki_measureVolBtn); loudTargetButton.Click += loud_targetButton_Click; loudControlsLayout = FindViewById<LinearLayout>(Resource.Id.wiki_volControls); modeLayouts.Add(ServerData.TaskType.Loudness, loudControlsLayout); modeNames.Add(ServerData.TaskType.Loudness, "Loudness of Speech"); names = new List<string>(); foreach ( KeyValuePair<ServerData.TaskType, string> entry in (Dictionary<ServerData.TaskType, string>)modeNames.firstToSecond) { names.Add(entry.Value); } currentMode = ServerData.TaskType.None; pacingModeButton = FindViewById<Button>(Resource.Id.wiki_pacingModeBtn); pacingModeButton.Click += pacingModeSwitch; loudnessModeButton = FindViewById<Button>(Resource.Id.wiki_loudnessModeBtn); loudnessModeButton.Click += loudnessModeSwitch; SetupRecorder(); LoadWikiInfo(); CheckForFirstTime(); }
public static void Main() { var biDictionary = new BiDictionary<int, string, string>(); biDictionary.Add(5, "da", "Value as value"); biDictionary.Add(3, "ne", "Another value"); biDictionary.Add(3, "da", "HAHAHAHA"); Console.WriteLine(biDictionary.Find(3)); Console.WriteLine(biDictionary.Find("da")); biDictionary.Find(3, "ne").ToList().ForEach(Console.WriteLine); }
public static void Main() { var dictionary = new BiDictionary<int, string, string>(true); dictionary.Add(1, "1", "value 1"); dictionary.Add(2, "2", "value 2"); dictionary.Add(3, "3", "value 3"); dictionary.Add(3, "3", "value 3.1"); Console.WriteLine(string.Join(", ", dictionary.FindByFirstKey(1))); Console.WriteLine(string.Join(", ", dictionary.FindBySecondKey("2"))); Console.WriteLine(string.Join(", ", dictionary.FindByBothKeys(3, "3"))); }
static void Main() { var collection = new BiDictionary<int, double, string>(); collection.Add(0, 0, "test"); collection.Add(2, 1.5, "test1"); collection.Add(1, 1, "test2"); Console.WriteLine(collection.Find(1)); Console.WriteLine(collection.Find(1.5)); Console.WriteLine(collection.Find(1)); Console.ReadKey(); }
/* Task 3: * Implement a class BiDictionary<K1,K2,T> that allows adding triples {key1, key2, value} and * fast search by key1, key2 or by both key1 and key2. Note: multiple values can be stored for given key. */ //Note: since removing of keys is not requested I have not implemented it. static void Main(string[] args) { var biDictionary = new BiDictionary<string, int, int>(); biDictionary.Add("Pesho", 4); biDictionary.Add("Pesho", 5); biDictionary.Add("Pesho", 3); biDictionary.Add(23, 6); biDictionary.Add("Maria", 13, 5); biDictionary.Add("Maria", 13, 2); biDictionary.Add("Maria", 13, 4); biDictionary.Add("Maria", 13, 6); foreach (var item in biDictionary.GetValueByFirstKey("Pesho")) { Console.WriteLine(item); } foreach (var item in biDictionary.GetValueBySecondKey(23)) { Console.WriteLine(item); } foreach (var item in biDictionary.GetValueByBothKeys("Maria", 13)) { Console.WriteLine(item); } }
static void Main(string[] args) { var biDictionary = new BiDictionary<string, string, string>(); Console.WriteLine(biDictionary.Add("one", "edno", "0000001")); Console.WriteLine(biDictionary.Add("two", "dve", "0000010")); Console.WriteLine(biDictionary.Add("three", "tri", "0000100")); Console.WriteLine(biDictionary.Contains("one")); Console.WriteLine(biDictionary.Contains("edno")); Console.WriteLine(biDictionary.GetValue("dve")); Console.WriteLine(biDictionary.GetValue("two")); }
static void Main() { BiDictionary<int, string, string> dictionary = new BiDictionary<int, string, string>(); dictionary.Add(0, "Zero"); dictionary.Associate("0000", 0); dictionary.Add(3, "0011", "Three"); string value = dictionary["0000"]; // value will be "Zero" Console.WriteLine(value); value = dictionary[0]; // val will be "Zero" Console.WriteLine(value); }
public static void Main(string[] args) { var dict = new BiDictionary<int, int, string>(); dict.Add(1, 1, "Pesho"); dict.Add(1, 21, "Gosho"); dict.Add(2, 1, "Stamat"); dict.Add(1, 3, "Mariika"); Console.WriteLine(dict[1, 3]); Console.WriteLine(dict[1, 1]); var collectionByKey2 = dict.GetByKey2(1); Console.WriteLine(string.Join(", ", collectionByKey2)); }
public static void Main() { string decorationLine = new string('-', Console.WindowWidth); Console.Write(decorationLine); Console.WriteLine("***Presenting the functionality of the data structure 'BiDictionary' - allows"); Console.WriteLine("adding values by two keys, searching by a single key or by both keys and"); Console.WriteLine("removing values by both keys***"); Console.Write(decorationLine); BiDictionary<string, string, Person> peopleDictionary = new BiDictionary<string, string, Person>(); Console.WriteLine("---Test add operation---"); foreach (Person person in people) { peopleDictionary.Add(person.FirstName, person.LastName, person); } Console.WriteLine("Count after addition: {0}", peopleDictionary.Count); Console.WriteLine(); Console.WriteLine("---Test get values by first key---"); string firstName = "Gosho"; Console.WriteLine("All people with first name '{0}' are:", firstName); PrintPeopleOnConsole(peopleDictionary.GetByFirstKey(firstName)); Console.WriteLine(); Console.WriteLine("---Test get values by second key---"); string lastName = "Peshov"; Console.WriteLine("All people with last name '{0}' are:", lastName); PrintPeopleOnConsole(peopleDictionary.GetBySecondKey(lastName)); Console.WriteLine(); Console.WriteLine("---Test get values by first key and second key---"); string firstKey = "Gosho"; string secondKey = "Goshov"; Console.WriteLine("All people with first name '{0}' and last name '{1}' are:", firstKey, secondKey); PrintPeopleOnConsole(peopleDictionary.GetByBothKeys(firstKey, secondKey)); Console.WriteLine(); Console.WriteLine("---Test remove operation---"); Console.WriteLine("Removing all people with first key '{0}' and second key '{1}'", firstKey, secondKey); peopleDictionary.Remove(firstKey, secondKey); Console.WriteLine("Count of people after removal: {0}", peopleDictionary.Count); Console.WriteLine("Count of people with first name '{0}' after removal: {1}", firstKey, peopleDictionary.GetByFirstKey(firstKey).Count); Console.WriteLine("Count of people with last name '{0}' after removal: {1}", secondKey, peopleDictionary.GetBySecondKey(secondKey).Count); Console.WriteLine(); Console.WriteLine("---Test clear operation---"); peopleDictionary.Clear(); Console.WriteLine("Count of people after clearing the dictionary: {0}", peopleDictionary.Count); }
public static void Main() { BiDictionary<string, int, string> biDictionary = new BiDictionary<string, int, string>(allowDuplicateValues: true); Random rand = new Random(); for (int i = 0; i < 1000; i++) { biDictionary.Add("Item" + rand.Next(1, 30), rand.Next(10, 1000), "SecondItem" + rand.Next(40, 100)); } Console.WriteLine("Test GET: "); Console.WriteLine(string.Join(" ", biDictionary.GetByFirstKey("Item3"))); Console.WriteLine(string.Join(" ", biDictionary.GetBySecondKey(100))); Console.WriteLine(string.Join(" ", biDictionary.GetByFirstAndSecondKey("Item50", 300))); Console.Write("Dictionary Count: "); Console.WriteLine(biDictionary.Count); biDictionary.RemoveByFirstKey("Item10"); Console.Write("Dictionary Count: "); Console.WriteLine(biDictionary.Count); biDictionary.RemoveBySecondKey(500); Console.Write("Dictionary Count: "); Console.WriteLine(biDictionary.Count); biDictionary.RemoveByFirstAndSecondKey("Item20", 200); Console.Write("Dictionary Count: "); Console.WriteLine(biDictionary.Count); }
public static void Main() { var bdict = new BiDictionary<string, int, Person>(); var people = new[] { new Person() { Name = "Peter", Age = 20, Town = "Sofia" }, new Person() { Name = "Peter", Age = 20, Town = "Varna" }, new Person() { Name = "Peter", Age = 25, Town = "Varna" }, new Person() { Name = "Billy", Age = 20, Town = "Sofia" }, }; // Add people to dictionary foreach (var person in people) { // key1 (name), key2 (age), value (person) bdict.Add(person.Name, person.Age, person); } // Print all people from dictionary Console.WriteLine("All people in the BiDictionary:"); foreach (var triple in bdict) { Console.WriteLine(string.Join(Environment.NewLine, triple.Item3)); } // Test the dictionary by searching by key1 (name), key2 (age) and both key1 and key2 Console.WriteLine("All people named Peter: {0}", string.Join(", ", bdict.GetByK1("Peter"))); Console.WriteLine("All people at age 20: {0}", string.Join(", ", bdict.GetByK2(20))); Console.WriteLine("All people at age 20, named Peter: {0}", string.Join(", ", bdict.GetByBoth("Peter", 20))); }
public void BiDictionaryRemove_Test() { var dictionary = new BiDictionary<object, object>(); dictionary.Add("test", "test"); dictionary.Remove("test"); Assert.Empty(dictionary); }
static void Main(string[] args) { var biDict = new BiDictionary<int, string, string>(); for (int i = 0; i < 20; i++) { var name = "Pesho" + i; var result = "Result" + i; biDict.Add(i, name, result); } var firstTry = biDict.FindByFirstKey(1); foreach (var item in firstTry) { Console.WriteLine(item); } Console.WriteLine("----------"); var secondTry = biDict.FindBySecondKey("Pesho2"); foreach (var item in secondTry) { Console.WriteLine(item); } Console.WriteLine("----------"); var thirdTry = biDict.FindByTwoKeys(2, "Pesho2"); foreach (var item in thirdTry) { Console.WriteLine(item); } }
public static void Main(string[] args) { BiDictionary<int, string, string> dictionary = new BiDictionary<int, string, string>(); var key1 = 1; var key2 = "2"; dictionary.Add(key1, key2, "valid keys 1"); dictionary.Add(key1, key2, "valid keys 2"); Console.WriteLine("==========Find(key1)=========="); Console.WriteLine(dictionary.Find(key1)); Console.WriteLine("==========Find(key2)=========="); Console.WriteLine(dictionary.Find(key2)); Console.WriteLine("==========Find(key1, key2)=========="); Console.WriteLine(dictionary.Find(key1, key2)); var key3 = 1; var key4 = "4"; dictionary.Add(key3, key4, "default value INVALID"); }
public static void Main() { var tuple = new BiDictionary<string, string, string>(); tuple.Add("Pesho", "Peshov", "*****@*****.**"); tuple.Add("Gosho", "Goshov", "*****@*****.**"); tuple.Add("Tosho", "Toshov", "*****@*****.**"); var pesho = tuple.FindByKey1("Pesho"); Console.WriteLine(pesho); var gosho = tuple.FindByKey2("Goshov"); Console.WriteLine(gosho); var tosho = tuple.FindByTwoKeys("Tosho", "Toshov"); Console.WriteLine(tosho); }
public static void Main() { BiDictionary<string, string, int> myBiDictionary = new BiDictionary<string, string, int>(); myBiDictionary.Add("Petyr", "Petrov", 30); Console.WriteLine(string.Join(", ", myBiDictionary.GetValueByFirstKey("Petyr"))); Console.WriteLine(string.Join(", ", myBiDictionary.GetValueBySecondKey("Petrov"))); Console.WriteLine(string.Join(", ", myBiDictionary.GetValueByBothKeys("Petyr", "Petrov"))); }
static void Main(string[] args) { var distances = new BiDictionary<string, string, int>(); distances.Add("Sofia", "Varna", 443); distances.Add("Sofia", "Varna", 468); distances.Add("Sofia", "Varna", 490); distances.Add("Sofia", "Plovdiv", 145); distances.Add("Sofia", "Bourgas", 383); distances.Add("Plovdiv", "Bourgas", 253); distances.Add("Plovdiv", "Bourgas", 292); var distancesFromSofia = distances.FindByKey1("Sofia"); // [443, 468, 490, 145, 383] Print(distancesFromSofia); var distancesToBourgas = distances.FindByKey2("Bourgas"); // [383, 253, 292] Print(distancesToBourgas); var distancesPlovdivBourgas = distances.Find("Plovdiv", "Bourgas"); // [253, 292] Print(distancesPlovdivBourgas); var distancesRousseVarna = distances.Find("Rousse", "Varna"); // [] Print(distancesRousseVarna); var distancesSofiaVarna = distances.Find("Sofia", "Varna"); // [443, 468, 490] Print(distancesSofiaVarna); distances.Remove("Sofia", "Varna"); // true var distancesFromSofiaAgain = distances.FindByKey1("Sofia"); // [145, 383] Print(distancesFromSofiaAgain); var distancesToVarna = distances.FindByKey2("Varna"); // [] Print(distancesToVarna); var distancesSofiaVarnaAgain = distances.Find("Sofia", "Varna"); // [] Print(distancesSofiaVarnaAgain); }
public static void Main() { var distances = new BiDictionary<string, string, int>(); distances.Add("Sofia", "Varna", 443); distances.Add("Sofia", "Varna", 468); distances.Add("Sofia", "Varna", 490); distances.Add("Sofia", "Plovdiv", 145); distances.Add("Sofia", "Bourgas", 383); distances.Add("Plovdiv", "Bourgas", 253); distances.Add("Plovdiv", "Bourgas", 292); var distancesFromSofia = distances.FindByKey1("Sofia"); var distancesToBourgas = distances.FindByKey2("Bourgas"); var distancesPlovdivBourgas = distances.Find("Plovdiv", "Bourgas"); var distancesRousseVarna = distances.Find("Rousse", "Varna"); var distancesSofiaVarna = distances.Find("Sofia", "Varna"); var isDeletd = distances.Remove("Sofia", "Varna"); var distancesFromSofiaAgain = distances.FindByKey1("Sofia"); var distancesToVarna = distances.FindByKey2("Varna"); var distancesSofiaVarnaAgain = distances.Find("Sofia", "Varna"); Console.WriteLine("[{0}]", string.Join(", ", distancesFromSofia)); Console.WriteLine("[{0}]",string.Join(", ", distancesToBourgas)); Console.WriteLine("[{0}]",string.Join(", ", distancesPlovdivBourgas)); Console.WriteLine("[{0}]", string.Join(", ", distancesRousseVarna)); Console.WriteLine("[{0}]", string.Join(", ", distancesSofiaVarna)); Console.WriteLine(isDeletd); Console.WriteLine("[{0}]", string.Join(", ", distancesFromSofiaAgain)); Console.WriteLine("[{0}]", string.Join(", ", distancesToVarna)); Console.WriteLine("[{0}]", string.Join(", ", distancesSofiaVarnaAgain)); }
public void TestAdd() { _biDictionary.Add(default(int), default(double)); _biDictionary.Add(new KeyValuePair <int, double>(1, 2.0)); _biDictionary.Add(new KeyValuePair <double, int>(3.0, 4)); Assert.AreEqual(6, _biDictionary.Count); Assert.AreEqual(default(double), _biDictionary[default(int)]); }
public void AddCapacity() { var Random = Initialise(); var Records = new BiDictionary <int, int>(1024); foreach (var(Left, Right) in YieldRandom(Random, 1024)) { Records.Add(Left, Right); } Validate(Records); }
public void Find_SouldFindValuesAddedByBothKeys() { // arrange var dic = new BiDictionary <int, string, string>(); // act dic.Add(2, "two", "second"); var actual = dic[2, "two"]; // assert Assert.AreEqual("second", actual); }
public void Find_SouldThrowIfKeysCombinationNotFound() { // arrange var dic = new BiDictionary <int, string, string>(); // act dic.Add(2, "two", "second"); var actual = dic[3, "two"]; // assert Assert.AreEqual(null, actual); }
/// <summary> /// Gets the internal id. /// </summary> /// <param name="id">The id.</param> /// <returns></returns> internal int GetInternalId(string id) { int res; if (_mapId.TryGetValue(id, out res)) { return(res); } _lastId++; _mapId.Add(_lastId, id); return(_lastId); }
public void AddCollide() { var Random = Initialise(); var Records = new BiDictionary <Collider, Collider>(); foreach (var(Left, Right) in YieldRandom(Random, 64)) { Records.Add(Left, Right); } Validate(Records); }
public void AddingKeysShouldWorkWithoutErrors() { var dict = new BiDictionary <string, decimal, int>(); dict.Add("canko", 15.6M, 1) .Add("vanko", -34625M, -5) .Add("damqnko", 0, 0); dict["kycko", 5345] = 10; Assert.AreEqual(4, dict.DistinctCount); }
public void CreateTestDictionary() { this.testDict = new BiDictionary <string, decimal, int>(); testDict.Add("pesho", 15.6M, 1) .Add("petkoo", -34625M, -5) .Add("gosho", 0, 0) .Add("boncho", 15.6M, 2) .Add("ivnacho", 0, 3) .Add("pesho", -34625M, int.MinValue) .Add("bay ivan", 50, 50); }
private static BiDictionary <int, string, decimal> FillBiDictionary() { BiDictionary <int, string, decimal> biDictionary = new BiDictionary <int, string, decimal>(); Random random = new Random(); for (int i = 0; i < 10000; i++) { biDictionary.Add(random.Next(0, 10), "key2:" + random.Next(11, 20), random.Next(0, 100000)); } return(biDictionary); }
protected virtual void Initialize(string input, string output) { input = input.ToUpper(); output = output.ToUpper(); if (input.Length != output.Length) { throw new ArgumentException("The input and output map don't have the same length."); } if (input.Distinct().Count() != input.Length) { throw new ArgumentException("The input map has repeating characters."); } if (output.Distinct().Count() != output.Length) { throw new ArgumentException("The output map has repeating characters."); } if (input.Except(output).Count() > 0) { throw new ArgumentException("The input map contains characters that output map doesn't have."); } if (output.Except(input).Count() > 0) { throw new ArgumentException("The output map contains characters that input map doesn't have."); } _input = input; _output = output; CipherMap = new BiDictionary <char, char>(); for (int i = 0; i < input.Length; i++) { CipherMap.Add(char.ToLower(input[i]), char.ToLower(output[i])); CipherMap.Add(input[i], output[i]); } }
static void Main() { var bidictionary = new BiDictionary <string, int, string>(allowDuplicateValues: true); bidictionary.Add("pesho", 1, "JavaScript"); bidictionary.Add("gosho", 2, "Java"); bidictionary.Add("nakov", 3, "C#"); bidictionary.Add("nakov", 3, "C#"); bidictionary.Add("gosho", 3, "Coffee"); bidictionary.Add("nakov", 1, "Python"); Console.WriteLine(string.Join(" ", bidictionary.GetByFirstKey("nakov"))); Console.WriteLine(string.Join(" ", bidictionary.GetBySecondKey(3))); Console.WriteLine(string.Join(" ", bidictionary.GetByFirstAndSecondKey("nakov", 3))); Console.WriteLine(bidictionary.Count); bidictionary.RemoveByFirstKey("gosho"); Console.WriteLine(bidictionary.Count); bidictionary.RemoveBySecondKey(3); Console.WriteLine(bidictionary.Count); bidictionary.RemoveByFirstAndSecondKey("nakov", 1); Console.WriteLine(bidictionary.Count); }
[Test()] //, Repeat(2)] public void AddRemoveAllAdd() { var Random = Initialise(); var Records = new BiDictionary <int, int>(); foreach (var(Left, Right) in YieldRandom(Random, 1024)) { Records.Add(Left, Right); } while (Records.Count > 0) { var Key = Records.Get(Random.Next(0, Records.Count)).Key; Records.Remove(Key); } foreach (var(Left, Right) in YieldRandom(Random, 1024)) { Records.Add(Left, Right); } }
private static void Register(Type t) { if (RegisterCount > ushort.MaxValue) { throw new System.Exception(string.Format("Cannot register more than {0} types of data.", ushort.MaxValue + 1)); } if (RegisteredData.ContainsKey(t)) { return; } RegisteredData.Add(t, RegisterCount++); }
private static void ConfigureContainer( string connectionString, IExecutionContextAccessor executionContextAccessor, ILogger logger, IEventsBus eventsBus) { var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule(new LoggingModule(logger)); var loggerFactory = new SerilogLoggerFactory(logger); containerBuilder.RegisterModule(new DataAccessModule(connectionString, loggerFactory)); containerBuilder.RegisterModule(new ProcessingModule()); containerBuilder.RegisterModule(new EventsBusModule(eventsBus)); containerBuilder.RegisterModule(new MediatorModule()); containerBuilder.RegisterModule(new AuthenticationModule()); var domainNotificationsMap = new BiDictionary <string, Type>(); domainNotificationsMap.Add("MeetingGroupProposalAcceptedNotification", typeof(MeetingGroupProposalAcceptedNotification)); containerBuilder.RegisterModule(new OutboxModule(domainNotificationsMap)); BiDictionary <string, Type> internalCommandsMap = new BiDictionary <string, Type>(); internalCommandsMap.Add("CreateMember", typeof(CreateMemberCommand)); internalCommandsMap.Add("RequestMeetingGroupProposalVerification", typeof(RequestMeetingGroupProposalVerificationCommand)); containerBuilder.RegisterModule(new InternalCommandsModule(internalCommandsMap)); containerBuilder.RegisterModule(new QuartzModule()); containerBuilder.RegisterInstance(executionContextAccessor); _container = containerBuilder.Build(); AdministrationCompositionRoot.SetContainer(_container); }
/// <summary> /// Convert Method information to string representation. /// </summary> /// <param name="method"></param> /// <returns></returns> public static string SerializeMethodBaseToString(MethodBase method, bool useCache) { string result = null; if (useCache) { lock (_methodSerializationCache) { if (_methodSerializationCache.TryGetByValue(method, ref result)) { return(result); } } } StringBuilder valueBuilder = new StringBuilder(); valueBuilder.Append(method.DeclaringType.AssemblyQualifiedName); valueBuilder.Append(MethodSerializationSeparator); valueBuilder.Append(method.Name); foreach (ParameterInfo parameter in method.GetParameters()) {// Add parameters types. valueBuilder.Append(MethodSerializationSeparator); valueBuilder.Append(parameter.ParameterType.AssemblyQualifiedName); } result = valueBuilder.ToString(); if (useCache) { lock (_methodSerializationCache) {// Possible multiple entry, but not a problem, also faster. _methodSerializationCache.Add(result, method); } } return(result); }
public void ReplaceCollide() { //**************************************** var MyRecords = new BiDictionary <Collider, int>(); //**************************************** MyRecords.Add(9, 1); MyRecords.Add(12, 2); MyRecords.Add(10, 3); MyRecords.Add(11, 4); //**************************************** try { MyRecords[10] = 4; Assert.Fail("Did not fail"); } catch (ArgumentException) { } }
public void AddConnection(int playerId, ClientConnection connection) { if (_playerSocketDictionary.ContainsByFirst(playerId)) { _playerSocketDictionary.RemoveByFirst(playerId); } _playerSocketDictionary.Add(playerId, connection.Id); if (!_sockets.ContainsKey(connection.Id)) { _sockets.Add(connection.Id, connection); } }
private void ProtoClass(Tree tree) { List <Tree> children = tree.Children; string Base = tree.Kind == Kind.Struct ? null : children.Count > 1 && children[1].Content == ":" ? children[2].Content : "System.object"; _byteCodeMapper.OpenClass(Base, children[0].Content); if (!_summary.Contain(_byteCodeMapper.CurrentClass)) { _summary.Add(_byteCodeMapper.CurrentClass, children[0].Parent); } _byteCodeMapper.CloseClass(); }
public void Clear() { var Random = Initialise(); var Records = new BiDictionary <int, int>(); foreach (var(Left, Right) in YieldRandom(Random, 1024)) { Records.Add(Left, Right); } Records.Clear(); Assert.AreEqual(0, Records.Count); }
private static void ConfigureCompositionRoot( string connectionString, IExecutionContextAccessor executionContextAccessor, ILogger logger, EmailsConfiguration emailsConfiguration, string textEncryptionKey, IEmailSender emailSender) { var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule(new LoggingModule(logger.ForContext("Module", "UserAccess"))); var loggerFactory = new SerilogLoggerFactory(logger); containerBuilder.RegisterModule(new DataAccessModule(connectionString, loggerFactory)); containerBuilder.RegisterModule(new DomainModule()); containerBuilder.RegisterModule(new ProcessingModule()); containerBuilder.RegisterModule(new EventsBusModule()); containerBuilder.RegisterModule(new MediatorModule()); var domainNotificationsMap = new BiDictionary <string, Type>(); domainNotificationsMap.Add("NewUserRegisteredNotification", typeof(NewUserRegisteredNotification)); domainNotificationsMap.Add("UserRegistrationConfirmedNotification", typeof(UserRegistrationConfirmedNotification)); containerBuilder.RegisterModule(new OutboxModule(domainNotificationsMap)); containerBuilder.RegisterModule(new QuartzModule()); containerBuilder.RegisterModule(new EmailModule(emailsConfiguration, emailSender)); containerBuilder.RegisterModule(new SecurityModule(textEncryptionKey)); containerBuilder.RegisterInstance(executionContextAccessor); _container = containerBuilder.Build(); UserAccessCompositionRoot.SetContainer(_container); }
public void AddRangePrePopulatedCollide() { var Random = Initialise(); var Records = new BiDictionary <Collider, Collider>(); var Input = YieldRandom(Random, 1024).Select(ToColliderPair).ToArray(); for (var Index = 0; Index < 512; Index++) { Records.Add(Input[Index]); } Records.AddRange(Input.Skip(512)); Validate(Records); }
private static bool LoadUFDictionariesInto(Dictionary <Type, BiDictionary <string, int> > dicts, Assembly asm, ClientVersionBuild build) { Type[] enumTypes = { typeof(ObjectField), typeof(ItemField), typeof(ContainerField), typeof(UnitField), typeof(PlayerField), typeof(GameObjectField), typeof(DynamicObjectField), typeof(CorpseField), typeof(AreaTriggerField), typeof(SceneObjectField), typeof(ConversationField), typeof(ObjectDynamicField), typeof(ItemDynamicField), typeof(ContainerDynamicField), typeof(UnitDynamicField), typeof(PlayerDynamicField), typeof(GameObjectDynamicField), typeof(DynamicObjectDynamicField), typeof(CorpseDynamicField), typeof(AreaTriggerDynamicField), typeof(SceneObjectDynamicField), typeof(ConversationDynamicField) }; bool loaded = false; foreach (Type enumType in enumTypes) { string vTypeString = $"WowPacketParserModule.{GetUpdateFieldDictionaryBuildName(build)}.Enums.{enumType.Name}"; Type vEnumType = asm.GetType(vTypeString); if (vEnumType == null) { vTypeString = $"WowPacketParser.Enums.Version.{GetUpdateFieldDictionaryBuildName(build)}.{enumType.Name}"; vEnumType = Assembly.GetExecutingAssembly().GetType(vTypeString); if (vEnumType == null) { continue; // versions prior to 4.3.0 do not have AreaTriggerField } } Array vValues = Enum.GetValues(vEnumType); var vNames = Enum.GetNames(vEnumType); var result = new BiDictionary <string, int>(); for (int i = 0; i < vValues.Length; ++i) { result.Add(vNames[i], (int)vValues.GetValue(i)); } dicts.Add(enumType, result); loaded = true; } return(loaded); }
static void Main() { BiDictionary <string, string, string> dict = new BiDictionary <string, string, string>(); dict.Add("gosho", "goshov", "jabata"); dict.Add("gosho", "peshov", "konq"); dict.Add("gosho", "nedkov", "babata"); dict.Add("tosho", "goshov", "lopatata"); dict.Add("toncho", "goshov", "malkiq"); dict.Add("ceco", "peshov", "komara"); var search = dict.SearchMultiKeys("gosho", "goshov"); }
// Assign country code based on letterCode. Same letterCode returns the same countryCode. // The country codes will be 1, 2, 3 ..., or DefaultCode if letterCode is empty string. // public int GetCountryCode(string letterCode) { if (letterCode == "") { return(DefaultCode); } if (_countryCodeLookup.TryGetBySecond(letterCode, out var code)) { return(code); } do { countryCode++; } while (countryCode == DefaultCode); _countryCodeLookup.Add(countryCode, letterCode); return(countryCode); }
private static void ConfigureCompositionRoot( string connectionString, IExecutionContextAccessor executionContextAccessor, ILogger logger, EmailsConfiguration emailsConfiguration, IEventsBus eventsBus) { var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule(new LoggingModule(logger.ForContext("Module", "Meetings"))); var loggerFactory = new SerilogLoggerFactory(logger); containerBuilder.RegisterModule(new DataAccessModule(connectionString, loggerFactory)); containerBuilder.RegisterModule(new ProcessingModule()); containerBuilder.RegisterModule(new EventsBusModule(eventsBus)); containerBuilder.RegisterModule(new MediatorModule()); containerBuilder.RegisterModule(new AuthenticationModule()); var domainNotificationsMap = new BiDictionary <string, Type>(); domainNotificationsMap.Add("MeetingGroupProposalAcceptedNotification", typeof(MeetingGroupProposalAcceptedNotification)); domainNotificationsMap.Add("MeetingGroupProposedNotification", typeof(MeetingGroupProposedNotification)); domainNotificationsMap.Add("MeetingGroupCreatedNotification", typeof(MeetingGroupCreatedNotification)); domainNotificationsMap.Add("MeetingAttendeeAddedNotification", typeof(MeetingAttendeeAddedNotification)); domainNotificationsMap.Add("MemberCreatedNotification", typeof(MemberCreatedNotification)); domainNotificationsMap.Add("MemberSubscriptionExpirationDateChangedNotification", typeof(MemberSubscriptionExpirationDateChangedNotification)); domainNotificationsMap.Add("MeetingCommentLikedNotification", typeof(MeetingCommentLikedNotification)); domainNotificationsMap.Add("MeetingCommentUnlikedNotification", typeof(MeetingCommentUnlikedNotification)); containerBuilder.RegisterModule(new OutboxModule(domainNotificationsMap)); containerBuilder.RegisterModule(new EmailModule(emailsConfiguration)); containerBuilder.RegisterModule(new QuartzModule()); containerBuilder.RegisterInstance(executionContextAccessor); _container = containerBuilder.Build(); MeetingsCompositionRoot.SetContainer(_container); }
public static void Setup() { IInputDataProvider provider; //TODO: Implement this pattern for all database retrieval if (!LSDatabaseManager.TryGetDatabase <IInputDataProvider> (out provider)) { Debug.LogError("IInputDataProvider unavailable."); } InputDataItem[] inputData = provider.InputData; for (int i = inputData.Length - 1; i >= 0; i--) { InputDataItem item = inputData[i]; ushort id = (ushort)(i + 1); string code = inputData[i].Name; InputMap.Add(code, id); InputDataMap.Add(code, item); } Setted = true; }
private static void ConfigureCompositionRoot( string connectionString, IExecutionContextAccessor executionContextAccessor, ILogger logger, EmailsConfiguration emailsConfiguration, IEventsBus eventsBus, bool runQuartz = true) { var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule(new LoggingModule(logger)); var loggerFactory = new SerilogLoggerFactory(logger); containerBuilder.RegisterModule(new DataAccessModule(connectionString, loggerFactory)); containerBuilder.RegisterModule(new ProcessingModule()); containerBuilder.RegisterModule(new EmailModule(emailsConfiguration)); containerBuilder.RegisterModule(new EventsBusModule(eventsBus)); containerBuilder.RegisterModule(new MediatorModule()); containerBuilder.RegisterModule(new AuthenticationModule()); BiDictionary <string, Type> domainNotificationsMap = new BiDictionary <string, Type>(); domainNotificationsMap.Add("MeetingFeePaidNotification", typeof(MeetingFeePaidNotification)); domainNotificationsMap.Add("MeetingFeePaymentPaidNotification", typeof(MeetingFeePaymentPaidNotification)); domainNotificationsMap.Add("SubscriptionCreatedNotification", typeof(SubscriptionCreatedNotification)); domainNotificationsMap.Add("SubscriptionPaymentPaidNotification", typeof(SubscriptionPaymentPaidNotification)); domainNotificationsMap.Add("SubscriptionRenewalPaymentPaidNotification", typeof(SubscriptionRenewalPaymentPaidNotification)); domainNotificationsMap.Add("SubscriptionRenewedNotification", typeof(SubscriptionRenewedNotification)); containerBuilder.RegisterModule(new OutboxModule(domainNotificationsMap)); if (runQuartz) { containerBuilder.RegisterModule(new QuartzModule()); } containerBuilder.RegisterInstance(executionContextAccessor); _container = containerBuilder.Build(); PaymentsCompositionRoot.SetContainer(_container); RunEventsProjectors(); }
public void BiDictionaryTest() { BiDictionary <int, string, double> test1 = new BiDictionary <int, string, double>() { { 1, "first", 1.0 }, { 2, "second", 2.0 }, { 3, "third", 3.0 } }; test1.Add(4, "fourth", 4.0); Assert.AreEqual(test1.ByKey1[1], 1.0); Assert.AreEqual(test1.ByKey2["first"], 1.0); Assert.IsTrue(test1.ContainsKey(1)); Assert.IsTrue(test1.ContainsKey("first")); Assert.IsTrue(test1.ContainsKey(2)); Assert.IsTrue(test1.ContainsKey(3)); Assert.IsTrue(test1.ContainsKey(4)); Assert.IsTrue(test1.ContainsValue(4.0)); }
public static void Main(string[] args) { var myBiDictionary = new BiDictionary <int, int, string>(); myBiDictionary.Add(11, 21, "1"); myBiDictionary.Add(11, 22, "2"); myBiDictionary.Add(11, 23, "3"); myBiDictionary.Add(12, 21, "4"); myBiDictionary.Add(13, 21, "5"); myBiDictionary.Add(14, 21, "6"); myBiDictionary.Add(15, 21, "7"); // find all key11 values for first key var res1 = myBiDictionary.Find(key1: 11); // find all key21 values for second key var res2 = myBiDictionary.Find(key2: 21); // find all key11 and key21 values for both keys var res3 = myBiDictionary.Find(11, 21); }
private static void LoadUFDictionariesInto(Dictionary <Type, BiDictionary <string, int> > dicts, Assembly asm, ClientVersionBuild build) { Type[] enumTypes = { typeof(ObjectField), typeof(ItemField), typeof(ContainerField), typeof(UnitField), typeof(PlayerField), typeof(GameObjectField), typeof(DynamicObjectField), typeof(CorpseField), typeof(AreaTriggerField), typeof(SceneObjectField) }; foreach (var enumType in enumTypes) { var vTypeString = string.Format("WowPacketParserModule.{0}.Enums.{1}", GetUpdateFieldDictionaryBuildName(build), enumType.Name); var vEnumType = asm.GetType(vTypeString); if (vEnumType == null) { vTypeString = string.Format("WowPacketParser.Enums.Version.{0}.{1}", GetUpdateFieldDictionaryBuildName(build), enumType.Name); vEnumType = Assembly.GetExecutingAssembly().GetType(vTypeString); if (vEnumType == null) { continue; // versions prior to 4.3.0 do not have AreaTriggerField } } var vValues = Enum.GetValues(vEnumType); var vNames = Enum.GetNames(vEnumType); var result = new BiDictionary <string, int>(); for (var i = 0; i < vValues.Length; ++i) { result.Add(vNames[i], (int)vValues.GetValue(i)); } dicts.Add(enumType, result); } }