static void Main(string[] args)
        {
            Console.WriteLine("Hello Left Join");
            Console.WriteLine("");

            Hashtables tableOne = new Hashtables();

            tableOne.Add("abc", "enamored");
            tableOne.Add("abcd", "anger");
            tableOne.Add("qwerty", "employed");
            tableOne.Add("outfit", "garb");
            tableOne.Add("guide", "usher");
            tableOne.Add("extremetomax", "end");

            Hashtables tableTwo = new Hashtables();

            tableTwo.Add("abc", "averse");
            tableTwo.Add("abcd", "delight");
            tableTwo.Add("qwerty", "idle");
            tableTwo.Add("empty", "gone");
            tableTwo.Add("nope", "never");
            tableTwo.Add("extremetomax", "jam");

            List <string> result = LeftJoin(tableOne, tableTwo);

            Console.WriteLine($"[{string.Join(",", result)}]");

            Console.ReadLine();
        }
        public static List <int> TreeIntersection(BinaryTree one, BinaryTree two)
        {
            //Final output as List instead of int array.
            List <int> output = new List <int>();

            Hashtables hashTables = new Hashtables();

            //Pass Binary trees into List<>
            List <int> treeOneList = one.PreOrder(one.Root);
            List <int> treeTwoList = two.PreOrder(two.Root);

            //Add all of tree one into hashtable
            foreach (var item in treeOneList)
            {
                hashTables.Add(item.ToString(), item);
            }

            //compare tree two if buckets in hashtable are already occupied.
            //If collision occurs add that number to the List output.
            foreach (var item in treeTwoList)
            {
                if (hashTables.Contains(item.ToString()))
                {
                    output.Add(item);
                }
            }

            /*
             * foreach (var item in output)
             * {
             *  Console.WriteLine(item);
             * }*/

            return(output);
        }
Beispiel #3
0
        public void GetValue(string key, object value)
        {
            Hashtables hashTables = new Hashtables();

            hashTables.Add(key, value);

            Assert.Equal(value, hashTables.GetValue(key));
        }
Beispiel #4
0
        public void GetTrue(string key, object value)
        {
            Hashtables hashTables = new Hashtables();

            hashTables.Add(key, value);

            Assert.True(hashTables.Contains(key));
        }
Beispiel #5
0
        public void GetCollision1()
        {
            Hashtables hashTables = new Hashtables();

            hashTables.Add("abc", "Josie");
            hashTables.Add("cba", 22);
            hashTables.Add("acb", true);

            Assert.Equal("Josie", hashTables.GetValue("abc"));
        }
Beispiel #6
0
        public void GetNull3()
        {
            Hashtables hashTables = new Hashtables();

            hashTables.Add("abc", "Josie");
            hashTables.Add("Dog", "Woof");
            hashTables.Add("333", "ponies");
            hashTables.Add("moons", "44");

            Assert.Null(hashTables.GetValue("three"));
        }
Beispiel #7
0
        public void GetFalse3()
        {
            Hashtables hashTables = new Hashtables();

            hashTables.Add("abc", "Josie");
            hashTables.Add("Dog", "Woof");
            hashTables.Add("333", "ponies");
            hashTables.Add("moons", "44");

            Assert.False(hashTables.Contains("three"));
        }
Beispiel #8
0
        public static void displayHashes()
        {
            Hashtables hashTables = new Hashtables();

            hashTables.Add("abc", "Josie");
            hashTables.Add("Dog", "Woof");
            hashTables.Add("333", "ponies");
            hashTables.Add("moons", "44");
            hashTables.Add("cba", "Doctor"); //Collision abc same as cba
            Console.WriteLine($"Should return as 'True' for contains:  {hashTables.Contains("moons")}");
            Console.WriteLine($"Should return as 'False' for contains: {hashTables.Contains("planet")}");
            Console.WriteLine($"Should return the value 'Woof' from key:  {hashTables.GetValue("Dog")}");
            Console.WriteLine($"Should return the value 'Doctor' from collision: {hashTables.GetValue("cba")}");
        }
        public static List <string> LeftJoin(Hashtables tableOne, Hashtables tableTwo)
        {
            List <string> listTableOne = new List <string>();
            List <string> listTableTwo = new List <string>();
            List <string> output       = new List <string>();

            for (int i = 0; i < tableOne.Bucket.Length; i++)
            {
                if (tableOne.Bucket[i] != null)
                {
                    listTableOne.Add(tableOne.Bucket[i].Head.Key.ToString());
                    listTableOne.Add(tableOne.Bucket[i].Head.Value.ToString());
                }
            }

            for (int i = 0; i < tableTwo.Bucket.Length; i++)
            {
                if (tableTwo.Bucket[i] != null)
                {
                    listTableTwo.Add(tableTwo.Bucket[i].Head.Key.ToString());
                    listTableTwo.Add(tableTwo.Bucket[i].Head.Value.ToString());
                }
            }

            string[] tableOneArr = listTableOne.ToArray();
            string[] tableTwoArr = listTableOne.ToArray();

            for (int i = 0; i < tableOneArr.Length; i++)
            {
                for (int m = 0; m < tableTwoArr.Length; m++)
                {
                    if (tableOneArr[i] == tableTwoArr[m])
                    {
                        output.Add(tableOneArr[i]);
                        output.Add(tableOneArr[i + 1]);
                        output.Add(tableTwoArr[m + 1]);
                    }
                }
            }

            return(output);
        }
Beispiel #10
0
        public static string RepeatedWord(string input)
        {
            string[]   listOfWord = input.ToLower().Split(',', ' ', '.');
            Hashtables hashWords  = new Hashtables();

            for (int i = 0; i < listOfWord.Length; i++)
            {
                string temp = listOfWord[i];

                if (hashWords.Contains(temp))
                {
                    return(temp);
                }
                else
                {
                    hashWords.Add(temp, temp);
                }
            }
            return("No repeated word found.");
        }
        public void Test3()
        {
            Hashtables tableOne = new Hashtables();

            tableOne.Add("fond", "enamored");
            tableOne.Add("wrath", "anger");


            Hashtables tableTwo = new Hashtables();

            tableTwo.Add("fond", "averse");
            tableTwo.Add("wrath", "delight");


            List <string> expected = new List <string>()
            {
                "fond", "enamored", "averse", "wrath", "anger", "delight"
            };

            Assert.Equal(expected, Program.LeftJoin(tableOne, tableTwo));
        }
Beispiel #12
0
        public async void InitializeViewModel()
        {
            this.ViewModel.Initialize();

            DialogHelper.MessageDialog = this.MessageDialog;
            DialogHelper.RootDialog    = this.RootDialog;

            try
            {
                await this.ViewModel.UpdateHashtables();
            }
            catch (Exception exception)
            {
                await DialogHelper.ShowMessgeDialog($"Failed to update Hashtables\n{exception}");

                this.ViewModel.Infobar.Reset();
                this.ViewModel.IsGloballyEnabled = true;
            }

            Hashtables.Load();
        }
Beispiel #13
0
        private static Hashtables DBExecuteReader(String SQLCommand, Parameters SQLParams)
        {
            Hashtables lstHashtable;

            DbCommand DbComm = GETDBCommand(DBCore.SQLDBType);

            try
            {
                DbComm.CommandText = SQLCommand;

                GETDBParams(DbComm, SQLParams);

                DbComm.Connection.Open();

                using (DbDataReader dr = DbComm.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    lstHashtable = new Hashtables();

                    while (dr.Read())
                    {
                        Hashtable h = new Hashtable();

                        for (int i = 0; i < dr.FieldCount; i++)
                            h.Add(dr.GetName(i).ToLower(), dr[i]);

                        lstHashtable.Add(h);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (DbComm.Connection.State == ConnectionState.Open)
                    DbComm.Connection.Close();
            }

            return lstHashtable;
        }