Example #1
0
        public static void Main(string[] args)
        {
            HashedSet<string> students = new HashedSet<string>();
            students.Add("Pesho");
            students.Add("Pesho");
            students.Add("Gosho");
            students.Remove("Gosho");
            students.Add("Misho");
            students.Add("Ivan");
            Console.WriteLine("Student count: {0}", students.Count);

            HashedSet<string> users = new HashedSet<string>();
            users.Add("Mariq");
            users.Add("Pesho");
            users.Add("Misho");

            HashedSet<string> intersection = students.Intersect(users);
            Console.WriteLine("Intersection:");
            foreach (var name in intersection)
            {
                Console.WriteLine(name);
            }

            HashedSet<string> union = students.Union(users);
            Console.WriteLine("Union: ");
            foreach (var name in union)
            {
                Console.WriteLine(name);
            }
        }
Example #2
0
        public static void Main()
        {
            var set = new HashedSet<int>();

            for (int i = 1; i < 11; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    set.Add(i);
                }
            }

            System.Console.WriteLine(set);
            System.Console.WriteLine(set.Count);

            var otherSet = new HashedSet<int>();

            for (int i = 5; i < 16; i++)
            {
                otherSet.Add(i);
            }

            System.Console.WriteLine(otherSet);
            System.Console.WriteLine(otherSet.Count);
            System.Console.WriteLine(set.IntersectsWith(otherSet));
            System.Console.WriteLine(set.Union(otherSet));
        }
		/// <summary>
		/// Returns a collection of <see cref="ClassEntry" /> containing
		/// information about all classes in this stream.
		/// </summary>
		/// <param name="document">A validated <see cref="XmlDocument"/> representing
		/// a mapping file.</param>
		public static ICollection GetClassEntries(XmlDocument document)
		{
			XmlNamespaceManager nsmgr = HbmBinder.BuildNamespaceManager(document.NameTable);

			// Since the document is validated, no error checking is done in this method.
			HashedSet classEntries = new HashedSet();

			XmlNode root = document.DocumentElement;

			string assembly = XmlHelper.GetAttributeValue(root, "assembly");
			string @namespace = XmlHelper.GetAttributeValue(root, "namespace");

			XmlNodeList classNodes = document.SelectNodes(
				"//" + HbmConstants.nsClass +
				"|//" + HbmConstants.nsSubclass +
				"|//" + HbmConstants.nsJoinedSubclass +
				"|//" + HbmConstants.nsUnionSubclass,
				nsmgr
				);

			foreach (XmlNode classNode in classNodes)
			{
				string name = XmlHelper.GetAttributeValue(classNode, "name");
				string extends = XmlHelper.GetAttributeValue(classNode, "extends");
				ClassEntry ce = new ClassEntry(extends, name, assembly, @namespace);
				classEntries.Add(ce);
			}

			return classEntries;
		}
		public MappingsQueueEntry(NamedXmlDocument document, IEnumerable<ClassExtractor.ClassEntry> classEntries)
		{
			this.document = document;

			containedClassNames = GetClassNames(classEntries);
			requiredClassNames = GetRequiredClassNames(classEntries, containedClassNames);
		}
Example #5
0
    /* 5 Implement the data structure "set" in a class HashedSet<T> using your class HashTable<K,T>
     * to hold the elements. Implement all standard set operations like Add(T), Find(T), Remove(T),
     * Count, Clear(), union and intersect.
     * */
    static void Main(string[] args)
    {
        var set = new HashedSet<int>();

        Debug.Assert(set.Count == 0);
        Debug.Assert(!set.Find(1));

        set.Add(1);

        Debug.Assert(set.Count == 1);
        Debug.Assert(set.Find(1));

        set.Add(2);

        Debug.Assert(set.Count == 2);
        Debug.Assert(set.Find(2));

        set.Add(1);

        Debug.Assert(set.Count == 2);
        Debug.Assert(set.Find(1));

        set.Remove(1);

        Debug.Assert(set.Count == 1);
        Debug.Assert(!set.Find(1));
        Debug.Assert(set.Find(2));

        var set1 = new HashedSet<int> { 1, 2, 3, 4, 5, 6 }.Intersect(new HashedSet<int> { 2, 4, 6, 8, 10 });
        Debug.Assert(set1.SameContents(new[] { 2, 4, 6 }, i => i));

        var set2 = new HashedSet<int> { 1, 2, 3, 4, 5, 6 }.Union(new HashedSet<int> { 2, 4, 6, 8, 10 });
        Debug.Assert(set2.SameContents(new[] { 1, 2, 3, 4, 5, 6, 8, 10 }, i => i));
    }
Example #6
0
		public void test()
		{
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				Person person = new Person("1");
				person.Name = "John Doe";
				var set = new HashedSet<object>();
				set.Add("555-1234");
				set.Add("555-4321");
				person.Properties.Add("Phones", set);

				s.Save(person);
				tx.Commit();
			}
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				Person person = (Person)s.CreateCriteria(typeof(Person)).UniqueResult();

				Assert.AreEqual("1", person.ID);
				Assert.AreEqual("John Doe", person.Name);
				Assert.AreEqual(1, person.Properties.Count);
				Assert.That(person.Properties["Phones"], Is.InstanceOf<ISet<object>>());
				Assert.IsTrue(((ISet<object>) person.Properties["Phones"]).Contains("555-1234"));
				Assert.IsTrue(((ISet<object>) person.Properties["Phones"]).Contains("555-4321"));
			}
		}
Example #7
0
        static void Main()
        {
            HashedSet<string> myBestFriends = new HashedSet<string>();

            myBestFriends.Add("Ivan");
            myBestFriends.Add("Daniel");
            myBestFriends.Add("Cecilia");

            Console.WriteLine(myBestFriends.Count);

            myBestFriends.Remove("Cecilia");
            Console.WriteLine(myBestFriends.Count);

            HashedSet<string> yourBestFriends = new HashedSet<string>();

            yourBestFriends.Add("Petar");
            yourBestFriends.Add("Daniel");
            yourBestFriends.Add("Monika");

            HashedSet<string> allBestFriends = myBestFriends.Union(yourBestFriends);

            Console.WriteLine("All best friends: ");
            foreach (var item in allBestFriends.setOfData)
            {
                Console.WriteLine("{0}", item.Value);
            }

            HashedSet<string> mutualBestFriends = myBestFriends.Intersect(yourBestFriends);

            Console.WriteLine("Mutual best friends: ");
            foreach (var item in mutualBestFriends.setOfData)
            {
                Console.WriteLine("{0}", item.Value);
            }
        }
Example #8
0
File: Task.cs Project: ArildF/PTB
 public Task()
 {
     CreatedDate = ModifiedDate = DateTimeHelper.Now;
     Id = Guid.NewGuid();
     _title = "";
     Links = new HashedSet<Link>();
 }
 public ProductQuotation(Quotation quotation, string name, string group)
 {
     Quotation = quotation;
     Name = name;
     Group = group;
     Editions = new HashedSet<EditionQuotation>();
 }
Example #10
0
 static void Main(string[] args)
 {
     ISessionFactory sf = CreateSessionFactory();
     using(ISession s = sf.OpenSession()) {
         using(ITransaction t = s.BeginTransaction()) {
             ISet<T3> t3 = new HashedSet<T3>() {
                 new T3() {str="a"},
                 new T3() {str="b"},
                 new T3() {str="c"}
             };
             foreach(T3 tt3 in t3)
                 s.Save(tt3);
             T1 t1 = new T1() {
                 str = "t1",
                 t3 = t3
             };
             T2 t2 = new T2() {
                 str = "t2",
                 t3 = t3
             };
             s.Save(t1);
             s.Save(t2);
             t.Commit();
             //IList<T1> k = s.QueryOver<T1>().List();
             //Console.WriteLine(k[0].id);
             //s.Delete(k[0]);
             //t.Commit();
         }
     }
     Console.ReadKey();
 }
        public void InitializerShouldCreateEmptyHashedSet()
        {
            var set = new HashedSet<int>();
            int expected = 0;

            Assert.AreEqual(expected, set.Count);
        }
        public void TestFindWithInvalidKey()
        {
            var table = new HashedSet<string>();
            table.Add("Pesho");

            var value = table.Find("Peho");
        }
        public void TestFindShouldProperlyWork()
        {
            var table = new HashedSet<string>();
            table.Add("Pesho");

            Assert.AreEqual(true, table.Find("Pesho"));
        }
        public static void Main()
        {
            var firstSet = new HashedSet<string>();
            var secondSet = new HashedSet<string>();

            firstSet.Add("Pesho");
            firstSet.Add("Gosho");
            firstSet.Add("Tosho");

            secondSet.Add("Ivan");
            secondSet.Add("Petkan");
            secondSet.Add("Dragan");

            Console.WriteLine(firstSet);
            Console.WriteLine(secondSet);

            Console.WriteLine(firstSet.Intersect(secondSet));
            Console.WriteLine(secondSet.Intersect(firstSet));

            Console.WriteLine(firstSet.Union(secondSet));
            Console.WriteLine(secondSet.Union(firstSet));

            firstSet.Remove("Pesho");
            firstSet.Remove("Tosho");
            Console.WriteLine(firstSet);

            Console.WriteLine(firstSet.Find("Tosho"));
            Console.WriteLine(firstSet.Find("Gosho"));

            Console.WriteLine(firstSet.Count);
        }
        public void AddShouldNotThrowExceptionWhenTheSameKeyIsAlreadyPresent()
        {
            var hashedset = new HashedSet<string>();

            hashedset.Add("gosho");
            hashedset.Add("gosho");
        }
Example #16
0
		public IEnumerable Distinct(IEnumerable source)
		{
			var s = new HashedSet();
			foreach (object item in source)
				s.Add(item);
			return s;
		}
        static void Main()
        {
            var mySet = new HashedSet<string>();
            mySet.Add("string");
            mySet.Add("str");
            //mySet.Add(null);
            mySet.Add("strength");
            mySet.Add("string");

            //var strength = mySet.Find("strength");
            //Console.WriteLine(strength);

            //var isStringRemoved = mySet.Remove("string");
            //Console.WriteLine(isStringRemoved);

            var mySecondSet = new HashedSet<string>();
            mySecondSet.Add("strength");
            mySecondSet.Add("dexterity");
            mySecondSet.Add("intelligence");

            mySet.Union(mySecondSet);
            //mySet.Intersect(mySecondSet);
            foreach (var item in mySet)
            {
                Console.WriteLine(item);
            }
        }
Example #18
0
        static void Main()
        {
            var set = new HashedSet<int>();

            set.Add(5);
            set.Add(3);
            set.Add(-4);
            set.Add(12);
            set.Add(0);
            set.Add(-50);
            set.Add(10);
            Console.WriteLine("Set contains 12 -> {0}", set.Find(12));
            Console.WriteLine("Set contains 13 -> {0}", set.Find(13));
            set.Remove(10);
            Console.WriteLine("Removed 10\nSet contains 10 -> {0}", set.Find(10));
            Console.WriteLine("Set contains {0} items", set.Count);
            Console.WriteLine("Set 1: {0}", set);

            var anotherSet = new HashedSet<int>();
            anotherSet.Add(-4);
            anotherSet.Add(15);
            anotherSet.Add(0);
            anotherSet.Add(-122);
            anotherSet.Add(35);
            Console.WriteLine("Set 2: {0}", anotherSet);

            set.Union(anotherSet);
            Console.WriteLine("Set after union: {0}", set);

            set.Intersect(anotherSet);
            Console.WriteLine("Set after intersect: {0}", set);

            set.Clear();
            Console.WriteLine("Set contains {0} items after clear", set.Count);
        }
    public static void Main()
    {
        HashedSet<float> firstSet = new HashedSet<float>();
        firstSet.Add(1f);
        firstSet.Add(1.4f);
        firstSet.Add(1.7f);
        firstSet.Add(2f);
        firstSet.Add(2.2f);
        firstSet.Remove(1.7f);
        Console.WriteLine(firstSet.Find(1f));
        Console.WriteLine(firstSet.Count);

        HashedSet<float> secondSet = new HashedSet<float>();
        secondSet.Add(1f);
        secondSet.Add(2f);
        secondSet.Add(3f);
        secondSet.Add(5f);

        HashedSet<float> thirdSet = new HashedSet<float>();
        thirdSet.Add(1f);
        thirdSet.Add(2f);
        thirdSet.Add(3f);
        thirdSet.Add(5f);

        secondSet.Union(firstSet);
        thirdSet.Intersect(firstSet);
        firstSet.Clear();
    }
		public void UpdateReservedWordsInDialect()
		{
			var reservedDb = new HashedSet<string>();
			var configuration = TestConfigurationHelper.GetDefaultConfiguration();
			var dialect = Dialect.Dialect.GetDialect(configuration.Properties);
			var connectionHelper = new ManagedProviderConnectionHelper(configuration.Properties);
			connectionHelper.Prepare();
			try
			{
				var metaData = dialect.GetDataBaseSchema(connectionHelper.Connection);
				foreach (var rw in metaData.GetReservedWords())
				{
					reservedDb.Add(rw.ToLowerInvariant());
				}
			}
			finally
			{
				connectionHelper.Release();
			}

			var sf = (ISessionFactoryImplementor) configuration.BuildSessionFactory();
			SchemaMetadataUpdater.Update(sf);
			var match = reservedDb.Intersect(sf.Dialect.Keywords);
			Assert.That(match, Is.EquivalentTo(reservedDb));
		}
Example #21
0
 public Product()
 {
     Images = new List<Image>();
     Comments = new List<Comment>();
     Recomended = new HashedSet<Product>();
     IsVisible = true;
 }
Example #22
0
        public void Union_Test()
        {
            HashedSet<int> set = new HashedSet<int>();
            HashedSet<int> otherSet = new HashedSet<int>();

            set.Add(1);
            set.Add(2);
            set.Add(3);

            otherSet.Add(3);
            otherSet.Add(4);
            otherSet.Add(5);

            set.Union(otherSet);

            StringBuilder actual = new StringBuilder();
            foreach (var item in set)
            {
                actual.Append(item + " ");
            }

            string expected = "1 2 3 4 5 ";

            Assert.AreEqual(expected, actual.ToString());
        }
Example #23
0
        /// <summary>
        /// Returns a collection of <see cref="ClassEntry" /> containing
        /// information about all classes in this stream.
        /// </summary>
        /// <param name="document">A validated <see cref="XmlDocument"/> representing
        /// a mapping file.</param>
        public static ICollection GetClassEntries(XmlDocument document)
        {
            // TODO this should be extracted into a utility method since there's similar
            // code in Configuration
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable);
            nsmgr.AddNamespace(HbmConstants.nsPrefix, Configuration.MappingSchemaXMLNS);

            // Since the document is validated, no error checking is done in this method.
            HashedSet classEntries = new HashedSet();

            XmlNode root = document.DocumentElement;

            string assembly = XmlHelper.GetAttributeValue(root, "assembly");
            string @namespace = XmlHelper.GetAttributeValue(root, "namespace");

            XmlNodeList classNodes = document.SelectNodes(
                "//" + HbmConstants.nsClass +
                "|//" + HbmConstants.nsSubclass +
                "|//" + HbmConstants.nsJoinedSubclass +
                "|//" + HbmConstants.nsUnionSubclass,
                nsmgr
                );

            foreach (XmlNode classNode in classNodes)
            {
                string name = XmlHelper.GetAttributeValue(classNode, "name");
                string extends = XmlHelper.GetAttributeValue(classNode, "extends");
                ClassEntry ce = new ClassEntry(extends, name, assembly, @namespace);
                classEntries.Add(ce);
            }

            return classEntries;
        }
        /// <summary>
        /// Create an action that will evict collection and entity regions based on queryspaces (table names).  
        /// </summary>
        public BulkOperationCleanupAction(ISessionImplementor session, ISet<string> querySpaces)
        {
            //from H3.2 TODO: cache the autodetected information and pass it in instead.
            this.session = session;

            ISet<string> tmpSpaces = new HashedSet<string>(querySpaces);
            ISessionFactoryImplementor factory = session.Factory;
            IDictionary acmd = factory.GetAllClassMetadata();
            foreach (DictionaryEntry entry in acmd)
            {
                string entityName = ((System.Type) entry.Key).FullName;
                IEntityPersister persister = factory.GetEntityPersister(entityName);
                string[] entitySpaces = persister.QuerySpaces;

                if (AffectedEntity(querySpaces, entitySpaces))
                {
                    if (persister.HasCache)
                    {
                        affectedEntityNames.Add(persister.EntityName);
                    }
                    ISet roles = session.Factory.GetCollectionRolesByEntityParticipant(persister.EntityName);
                    if (roles != null)
                    {
                        affectedCollectionRoles.AddAll(roles);
                    }
                    for (int y = 0; y < entitySpaces.Length; y++)
                    {
                        tmpSpaces.Add(entitySpaces[y]);
                    }
                }
            }
            spaces = new List<string>(tmpSpaces);
        }
		public NativeSQLQuerySpecification(
			string queryString,
			ISQLQueryReturn[] sqlQueryReturns,
			ICollection querySpaces)
		{
			this.queryString = queryString;
			this.sqlQueryReturns = sqlQueryReturns;

			if (querySpaces == null)
			{
				this.querySpaces = new HashedSet();
			}
			else
			{
				ISet tmp = new HashedSet();
				tmp.AddAll(querySpaces);
				// Can't use ImmutableSet here because it doesn't implement GetHashCode properly.
				this.querySpaces = tmp;
			}

			// pre-determine and cache the hashcode
			int hashCode = queryString.GetHashCode();
			unchecked
			{
				hashCode = 29 * hashCode + this.querySpaces.GetHashCode();
				if (this.sqlQueryReturns != null)
				{
					hashCode = 29 * hashCode + sqlQueryReturns.Length;
				}
			}

			this.hashCode = hashCode;
		}
        public void HashedSetUnionTestSameElementsInBoth()
        {
            HashedSet<int> firstSet = new HashedSet<int>();
            int firstSetLength = 5;
            for (int i = 0; i < firstSetLength; i++)
            {
                firstSet.Add(i);
            }

            HashedSet<int> secondSet = new HashedSet<int>();
            int secondSetLength = 5;
            for (int i = 0; i < secondSetLength; i++)
            {
                secondSet.Add(i);
            }

            Assert.AreEqual(firstSetLength, firstSet.Count, "Incorrect set count!");
            Assert.AreEqual(secondSetLength, secondSet.Count, "Incorrect set count!");

            firstSet.Union(secondSet);

            for (int i = 0; i < firstSetLength; i++)
            {
                Assert.IsTrue(firstSet.Contains(i), "Incorrect union!");
            }

            Assert.AreEqual(firstSetLength, firstSet.Count, "Incorrect amount of elements after union");
        }
Example #27
0
 public Blend()
 {
     Name = String.Empty;
     Drinks = new HashedSet<Drink>();
     Acidity = 0;
     Strength = new Strength();
     Upcharge = 0M;
 }
 public void TestAddMethod()
 {
     var hashedSet = new HashedSet<int>();
     Assert.IsTrue(hashedSet.Add(1));
     Assert.IsTrue(hashedSet.Add(2));
     Assert.IsFalse(hashedSet.Add(2));
     Assert.AreEqual(2, hashedSet.Count);
 }
 public void ShouldRemoveElementsCorrectly()
 {
     var set = new HashedSet<int>();
     set.Add(5);
     Assert.AreEqual(1, set.Count);
     set.Remove(5);
     Assert.AreEqual(0, set.Count);
 }
Example #30
0
 /// <summary>
 /// Returns all Edges that connect the two nodes (which are assumed to be different).
 /// </summary>
 /// <param name="node0"></param>
 /// <param name="node1"></param>
 /// <returns></returns>
 public static IList getEdgesBetween(Node node0, Node node1)
 {
     IList edges0 = DirectedEdge.ToEdges(node0.OutEdges.Edges);
     ISet commonEdges = new HashedSet(edges0);
     IList edges1 = DirectedEdge.ToEdges(node1.OutEdges.Edges);
     commonEdges.RetainAll(edges1);
     return new ArrayList(commonEdges);
 }