/// <exclude />
        public static string EncodeUrlInvalidCharacters(string value)
        {
            const char separator        = '|';
            const char spaceReplacement = '-';

            var symbolsToEncode = new Hashset <char>(new[] { '<', '>', '*', '%', '&', '\\', '?', '/' });

            symbolsToEncode.Add(separator);
            symbolsToEncode.Add(spaceReplacement);

            var sb = new StringBuilder(value.Length);

            foreach (var ch in value)
            {
                if (!symbolsToEncode.Contains(ch))
                {
                    sb.Append(ch);
                    continue;
                }

                int code = (int)ch;
                Verify.That(code <= 256, "1 byte ASCII code expected");

                sb.Append(separator).Append(code.ToString("X2"));
            }

            return(sb.Replace(' ', spaceReplacement).ToString());
        }
        public void Method1()
        {
            var names = new HashSet <string>();

            names.Add("abhi");
            names.Add("swathi");
            names.Add("nish");
            names.Add("ashu");

            names.Remove("nish");

            //creating another hash set
            Hashset <string> names2 = new Hashset <string>();

            names2.Add("abc");
            names2.Add("swathi");
            names2.Add("ashu");
            names2.Add("def");
            names2.Add("ghi");

            names1.UnionWith(names2);
            //names1.IntersectWith(names2);
            // names1.ExceptWith(names2);
            foreach (var name in names)
            {
                Console.WriteLine(name);
            }
        }
Exemple #3
0
 public void Test_Fine_ShouldKeyWhenContained()
 {
     data = new Hashset<int>(4);
     data.Add(key1);
     data.Add(key2);
     data.Add(key3);
     var keyFound = data.Find(key2);
     Assert.AreEqual(key2, keyFound, "Hashset Find should return key.");
 }
Exemple #4
0
 public void Test_Containes_ShouldReturnTrueWhenContained()
 {
     data = new Hashset<int>(4);
     data.Add(key1);
     data.Add(key2);
     data.Add(key3);
     var isContained = data.Containes(key2);
     Assert.IsTrue(isContained, "Hashset Containes should true when contained.");
 }
Exemple #5
0
        public void Test_Containes_ShouldReturnTrueWhenContained()
        {
            data = new Hashset <int>(4);
            data.Add(key1);
            data.Add(key2);
            data.Add(key3);
            var isContained = data.Containes(key2);

            Assert.IsTrue(isContained, "Hashset Containes should true when contained.");
        }
Exemple #6
0
        public void Test_Fine_ShouldKeyWhenContained()
        {
            data = new Hashset <int>(4);
            data.Add(key1);
            data.Add(key2);
            data.Add(key3);
            var keyFound = data.Find(key2);

            Assert.AreEqual(key2, keyFound, "Hashset Find should return key.");
        }
Exemple #7
0
 public void Test_Add_ShouldIncreaseCapacityWhenRangeIsMet()
 {
     data = new Hashset<int>(4);
     data.Add(key1);
     data.Add(key2);
     data.Add(key3);
     data.Add(key4);
     var expectedCapacity = 8;
     var actualCapacity = data.Capacity;
     Assert.AreEqual(expectedCapacity, actualCapacity, "Hashset should increase capacity when range is met!");
 }
Exemple #8
0
        public void Test_Add_ShouldIncreaseCapacityWhenRangeIsMet()
        {
            data = new Hashset <int>(4);
            data.Add(key1);
            data.Add(key2);
            data.Add(key3);
            data.Add(key4);
            var expectedCapacity = 8;
            var actualCapacity   = data.Capacity;

            Assert.AreEqual(expectedCapacity, actualCapacity, "Hashset should increase capacity when range is met!");
        }
Exemple #9
0
        public void Test_Remove_ShouldRemoveAndDecreaseCount()
        {
            data = new Hashset <int>(4);
            data.Add(key1);
            data.Add(key2);
            data.Add(key3);
            data.Remove(key2);
            var expectedCount = 2;
            var actualCount   = data.Count;

            Assert.AreEqual(expectedCount, actualCount, "Hashset should decrease count when removed!");
        }
 public bool Add(T item)
 {
     _lock.EnterWriteLock();
     try
     {
         return(hashset.Add(item));
     }
     finally
     {
         if (_lock.IsWriteLockHeld)
         {
             _lock.ExitWriteLock();
         }
     }
 }
        /// <summary>
        /// FindIntersection - Finds nodes common between two binary trees. Uses Breadth-First traversal.
        /// </summary>
        /// <param name="rootOne"> Node - Root of first binary tree </param>
        /// <param name="rootTwo"> Node - Root of second binary tree </param>
        /// <returns> integer array conataining the values of all common nodes </returns>
        public static int[] FindIntersection(Node rootOne, Node rootTwo)
        {
            Hashset    hs  = new Hashset();
            List <int> ans = new List <int>();

            Queue <Node> breadth = new Queue <Node>();

            breadth.Enqueue(rootOne);
            breadth.Enqueue(rootTwo);

            while (breadth.TryPeek(out rootOne))
            {
                Node front = breadth.Dequeue();

                if (!hs.Add(front))
                {
                    ans.Add(front.Value);
                }

                if (front.LeftChild != null)
                {
                    breadth.Enqueue(front.LeftChild);
                }

                if (front.RightChild != null)
                {
                    breadth.Enqueue(front.RightChild);
                }
            }

            return(ans.ToArray());
        }
Exemple #12
0
        public void Test_Intersect_ShouldAddOnlyKeysContainedInBothSets()
        {
            data = new Hashset <int>(4);
            data.Add(key1);
            data.Add(key2);
            var secondHashSet = new Hashset <int>();

            secondHashSet.Add(key2);
            secondHashSet.Add(key3);
            var intersectSet  = data.Intersect(secondHashSet);
            var expectedCount = 1;
            var actualCount   = intersectSet.Count;

            Assert.IsTrue(
                expectedCount == actualCount &&
                intersectSet.Containes(key2),
                "Hashset intersect should add only keys contained in both hasjsets.");
        }
Exemple #13
0
 public void Test_Clear_ShouldEmptyAndSetCountToZero()
 {
     data = new Hashset<int>(4);
     data.Add(key1);
     data.Clear();
     var expectedCount = 0;
     var actualCount = data.Count;
     Assert.AreEqual(expectedCount, actualCount, "Hashset should increase capacity when range is met!");
 }
Exemple #14
0
        public void Test_Clear_ShouldEmptyAndSetCountToZero()
        {
            data = new Hashset <int>(4);
            data.Add(key1);
            data.Clear();
            var expectedCount = 0;
            var actualCount   = data.Count;

            Assert.AreEqual(expectedCount, actualCount, "Hashset should increase capacity when range is met!");
        }
Exemple #15
0
        public void Test_Union_ShouldHaveUniqueKeys()
        {
            data = new Hashset <int>(4);
            data.Add(key1);
            data.Add(key2);

            var secondHashSet = new Hashset <int>();

            secondHashSet.Add(key2);
            secondHashSet.Add(key3);
            var unionSet      = data.Union(secondHashSet);
            var expectedCount = 3;
            var actualCount   = unionSet.Count;

            Assert.IsTrue(
                expectedCount == actualCount &&
                unionSet.Containes(key1) &&
                unionSet.Containes(key2) &&
                unionSet.Containes(key3),
                "Hashset union should have uniqie keys and correct count.");
        }
        public static string RepeatedWord(string input)
        {
            string[] allwords = input.ToLower().Split(" ");
            Hashset  wordSet  = new Hashset();

            foreach (string word in allwords)
            {
                if (!wordSet.Add(word))
                {
                    return(word);
                }
            }

            return("no duplicates");
        }
        private static void EnsureSubscribtion(Type type)
        {
            if (!_subscribedTo.Contains(type))
            {
                lock (_subscribedTo)
                {
                    if (!_subscribedTo.Contains(type))
                    {
                        _subscribedTo.Add(type);

                        DataEventSystemFacade.SubscribeToStoreChanged(type, (sender, storeEventArgs) => IncreaseTableVersion(type, DataScopeIdentifier.FromPublicationScope(storeEventArgs.PublicationScope), storeEventArgs.Locale), false);
                    }
                }
            }
        }
Exemple #18
0
        /// <exclude />
        public static string EncodeUrlInvalidCharacters(string value)
        {
            const char separator = '|';
            const char spaceReplacement = '-';

            var symbolsToEncode = new Hashset<char>(new[] { '<', '>', '*', '%', '&', '\\', '?' });

            symbolsToEncode.Add(separator);
            symbolsToEncode.Add(spaceReplacement);

            var sb = new StringBuilder(value.Length);

            foreach (var ch in value)
            {
                if (!symbolsToEncode.Contains(ch))
                {
                    sb.Append(ch);
                    continue;
                }

                int code = (int)ch;
                Verify.That(code <= 256, "1 byte ASCII code expected");

                sb.Append(separator).Append(code.ToString("X2"));
            }

            return sb.Replace(' ', spaceReplacement).ToString();
        }
Exemple #19
0
 public void Test_Intersect_ShouldAddOnlyKeysContainedInBothSets()
 {
     data = new Hashset<int>(4);
     data.Add(key1);
     data.Add(key2);
     var secondHashSet = new Hashset<int>();
     secondHashSet.Add(key2);
     secondHashSet.Add(key3);
     var intersectSet = data.Intersect(secondHashSet);
     var expectedCount = 1;
     var actualCount = intersectSet.Count;
     Assert.IsTrue(
         expectedCount == actualCount &&
         intersectSet.Containes(key2),
         "Hashset intersect should add only keys contained in both hasjsets.");
 }
Exemple #20
0
        public static void Main(string[] args)
        {
            LinkedList<KeyValuePair<string, int>> list = new LinkedList<KeyValuePair<string, int>>();
            Person person1 = new Person("Pesho", "Peshov", 21);
            Person person2 = new Person("Gosho", "Peshov", 22);
            Person person3 = new Person("Tosho", "Peshov", 23);

            // Console.WriteLine(person1.GetHashCode());
            // Console.WriteLine(person2.GetHashCode());
            // Console.WriteLine(person3.GetHashCode());
            // Console.WriteLine(person1.CompareTo(person2));
            // Console.WriteLine(person1.CompareTo(person3));
            var hashTable = new HashTable<Person, int>();
            hashTable.Add(person1, 1);
            hashTable.Add(person2, 1);
            hashTable.Add(person3, 2);
            foreach (KeyValuePair<Person, int> person in hashTable)
            {
                Console.WriteLine("Key\n{0}Value: {1}", person.Key, person.Value);
                Console.WriteLine();
            }

            Console.WriteLine("=====FIND=====");
            Console.WriteLine(hashTable.Find(person1));

            Console.WriteLine("=====REMOVE=====");
            Console.WriteLine(hashTable.Remove(person1));
            Console.WriteLine(hashTable.Remove(person1));

            Console.WriteLine("=====FIND=====");
            Console.WriteLine(hashTable.Find(person1));

            var keys = hashTable.Keys();
            foreach (var item in keys)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("=====INDEXER=====");
            Person person4 = new Person("Rosho", "Peshov", 55);

            // set
            hashTable[person4] = 777;

            // get
            Console.WriteLine(hashTable[person4]);

            Console.WriteLine("=====CLEAR=====");
            hashTable.Clear();
            Person person5 = new Person("Josh", "Goshov", 33);
            hashTable.Add(person5, 1234);
            Person person6 = new Person("Losh", "Goshov", 66);
            hashTable.Add(person6, 126);
            foreach (KeyValuePair<Person, int> person in hashTable)
            {
                Console.WriteLine("Key\n{0}Value: {1}", person.Key, person.Value);
                Console.WriteLine();
            }

            Console.WriteLine(hashTable.ContainesKey(person6));
            Console.WriteLine("=================================================");

            Console.WriteLine("=====HashSet=====");
            Hashset<Person> hashSet = new Hashset<Person>();
            hashSet.Add(person1);
            hashSet.Add(person2);
            Console.WriteLine(hashSet.Find(person1));
            Console.WriteLine(hashSet.Remove(person1));
            Console.WriteLine(hashSet.Find(person1));
            Console.WriteLine(hashSet.Find(person2));
            Console.WriteLine(hashSet.Remove(person2));

            Console.WriteLine("=====FOREACH=====");
            hashSet.Clear();
            hashSet.Add(person1);
            hashSet.Add(person2);
            foreach (var item in hashSet)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("=====UNION=====");
            var secondHashSet = new Hashset<Person>();
            secondHashSet.Add(person2);
            secondHashSet.Add(person3);
            var unionHashset = hashSet.Union(secondHashSet);
            foreach (var item in unionHashset)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("=====INTERSECT ====");
            var intersectionHashset = hashSet.Intersect(secondHashSet);
            foreach (var item in intersectionHashset)
            {
                Console.WriteLine(item);
            }
        }
Exemple #21
0
        public void Test_Union_ShouldHaveUniqueKeys()
        {
            data = new Hashset<int>(4);
            data.Add(key1);
            data.Add(key2);

            var secondHashSet = new Hashset<int>();
            secondHashSet.Add(key2);
            secondHashSet.Add(key3);
            var unionSet = data.Union(secondHashSet);
            var expectedCount = 3;
            var actualCount = unionSet.Count;
            Assert.IsTrue(
                expectedCount == actualCount &&
                unionSet.Containes(key1) &&
                unionSet.Containes(key2) &&
                unionSet.Containes(key3),
                "Hashset union should have uniqie keys and correct count.");
        }
Exemple #22
0
 public void AddTag(String tag)
 {
     tags.Add(tag);
 }
Exemple #23
0
 public void Test_Remove_ShouldRemoveAndDecreaseCount()
 {
     data = new Hashset<int>(4);
     data.Add(key1);
     data.Add(key2);
     data.Add(key3);
     data.Remove(key2);
     var expectedCount = 2;
     var actualCount = data.Count;
     Assert.AreEqual(expectedCount, actualCount, "Hashset should decrease count when removed!");
 }