예제 #1
0
        public void ShouldReturnDefaultValueAfterElementIsRemoved()
        {
            var table = new CustomHashTable<int, int>();
            table.Add(7, 7);
            int result;

            Assert.IsTrue(table.Find(7, out result));
            table.Remove(7);
            Assert.IsFalse(table.Find(7, out result));
            Assert.AreEqual(default(int), result);
        }
예제 #2
0
        public void ShouldReturnDefaultValueAfterElementIsRemoved()
        {
            var table = new CustomHashTable <int, int>();

            table.Add(7, 7);
            int result;

            Assert.IsTrue(table.Find(7, out result));
            table.Remove(7);
            Assert.IsFalse(table.Find(7, out result));
            Assert.AreEqual(default(int), result);
        }
예제 #3
0
        static void Main(string[] args)
        {
            var hashFunctions = new HashFunctions();
            var hashTable     = new CustomHashTable <string, string>(hashFunctions.HashObject);

            hashTable.Add("12", "Stefan Peev");
            hashTable.Add("abc", "Ivan Gabrovski");

            System.Console.WriteLine(hashTable.Find("12"));
            System.Console.WriteLine(hashTable.Find("abc"));

            foreach (var item in hashTable)
            {
                System.Console.WriteLine($"{item.Key}, {item.Value}");
            }
        }
예제 #4
0
        public void ShouldReturnCorrectValueByKey()
        {
            var table = new CustomHashTable<int, int>();
            table.Add(1, 200);
            var result = 0;
            var found = table.Find(1, out result);

            Assert.AreEqual(200, result);
            Assert.IsTrue(found);
        }
예제 #5
0
        public void ShouldReturnDefaultValueWhenKey()
        {
            var table = new CustomHashTable<int, int>();
            table.Add(1, 200);
            var result = 555;
            var found = table.Find(8, out result);

            Assert.AreEqual(default(int), result);
            Assert.IsFalse(found);
        }
예제 #6
0
        public void ShouldReturnCorrectValueByKey()
        {
            var table = new CustomHashTable <int, int>();

            table.Add(1, 111);
            var result = 0;
            var found  = table.Find(1, out result);

            Assert.AreEqual(111, result);
            Assert.IsTrue(found);
        }
예제 #7
0
 public void TestIfFindThrowsExeptionWhenInvalidKeyIsEntered()
 {
     var table = new CustomHashTable<int, int>(new List<KeyValuePair<int, int>>()
     {
         new KeyValuePair<int, int>(5, 6),
         new KeyValuePair<int, int>(98, 6),
         new KeyValuePair<int, int>(7, 56),
         new KeyValuePair<int, int>(9, 45)
     });
     table.Find(21);
 }
예제 #8
0
        public void ShouldReturnDefaultValueWhenKey()
        {
            var table = new CustomHashTable <int, int>();

            table.Add(1, 111);
            var result = 555;
            var found  = table.Find(8, out result);

            Assert.AreEqual(default(int), result);
            Assert.IsFalse(found);
        }
예제 #9
0
        static void Main(string[] args)
        {
            Random rand = new Random();

            List <Player> players = new List <Player>();

            for (int i = 0; i < 10000; ++i)
            {
                if (rand.Next(0, 2) == 0)
                {
                    continue;
                }

                players.Add(new Player()
                {
                    playerId = i
                });
            }

            List <Salary> salaries = new List <Salary>();

            for (int i = 0; i < 10000; ++i)
            {
                if (rand.Next(0, 2) == 0)
                {
                    continue;
                }

                salaries.Add(new Salary()
                {
                    playerId = i
                });
            }

            // Hash Join -> TEMP HashTable 이용 == List를 순회하면서 hash table에 저장
            // NL과의 차이 : hash table의 생성 여부
            //Dictionary<int, Salary> hash = new Dictionary<int, Salary>();
            CustomHashTable hash = new CustomHashTable();

            foreach (Salary s in salaries)
            {
                hash.Add(s.playerId);
            }

            List <int> result = new List <int>();

            foreach (Player p in players)
            {
                if (hash.Find(p.playerId))
                {
                    result.Add(p.playerId);
                }
            }
        }
예제 #10
0
        public void TestIfFindThrowsExeptionWhenInvalidKeyIsEntered()
        {
            var table = new CustomHashTable <int, int>(new List <KeyValuePair <int, int> >()
            {
                new KeyValuePair <int, int>(5, 6),
                new KeyValuePair <int, int>(98, 6),
                new KeyValuePair <int, int>(7, 56),
                new KeyValuePair <int, int>(9, 45)
            });

            table.Find(21);
        }
예제 #11
0
    static void Main()
    {
        CustomHashTable<int, int> hassTable = new CustomHashTable<int, int>();

        for (int i = 0; i < 20; i++)
        {
            hassTable.Add(i, i + 1);
        }

        Console.WriteLine(hassTable.Find(6)); // should print 7

        Console.WriteLine(hassTable.Count);
    }