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 void TestIntersectMethodToReturnCorrectResultsWithStrings() { string matchedValue1 = "Java"; string matchedValue2 = "CSharp"; HashedSet <string> first = new HashedSet <string>(); first.Add("3"); first.Add(matchedValue2); first.Add(matchedValue1); first.Add("test"); HashedSet <string> second = new HashedSet <string>(); second.Add("testMethod"); second.Add("TestClass"); second.Add(matchedValue1); second.Add("TestData"); second.Add(matchedValue2); second.Add(" "); first.Intersect(second); Assert.AreEqual(2, first.Count); var testResult = first.Find(matchedValue1); Assert.AreEqual(matchedValue1, testResult); testResult = first.Find(matchedValue2); Assert.AreEqual(matchedValue2, testResult); }
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 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); } }
public virtual ISet <IStateObject> GetChildrenObjectStates() { ISet <IStateObject> listRL = new HashedSet <IStateObject>(); if (parentStructure != null) { //all equivalence classes that contains this effect foreach (Element element in parentStructure.Elements) { foreach (EquivalenceClass equivalenceClass in element.EquivalenceClasses) { if (equivalenceClass.Effects.Contains(this)) { listRL.Add(equivalenceClass); } } } // all combinations that contains this effect foreach (Dependency dependency in parentStructure.Dependencies) { foreach (Combination combination in dependency.Combinations) { if (combination.Effects.Contains(this)) { listRL.Add(combination); } } } } return(listRL); }
public void TestIntersectMethodToReturnCorrectResults() { int matchedValue1 = 18; int matchedValue2 = -5; HashedSet <int> first = new HashedSet <int>(); first.Add(3); first.Add(matchedValue2); first.Add(matchedValue1); first.Add(14); HashedSet <int> second = new HashedSet <int>(); second.Add(20); second.Add(22); second.Add(matchedValue1); second.Add(290); second.Add(matchedValue2); second.Add(300); first.Intersect(second); Assert.AreEqual(2, first.Count); var testResult = first.Find(matchedValue1); Assert.AreEqual(matchedValue1, testResult); testResult = first.Find(matchedValue2); Assert.AreEqual(matchedValue2, testResult); }
public ISet <IStateObject> GetChildrenObjectStates() { HashedSet <IStateObject> rlos = new HashedSet <IStateObject>(); if (ParentElement != null) { if (ParentElement.Structure != null) { // all combinations that contains this equivalenceclass foreach (Dependency dependency in ParentElement.Structure.Dependencies) { foreach (Combination combination in dependency.Combinations) { if (combination.EquivalenceClasses.Contains(this)) { rlos.Add(combination); } foreach (TestCase testCase in ParentElement.Structure.TestCases) { if (testCase.EquivalenceClasses.Contains(this)) { rlos.Add(testCase); } } } } } } return(rlos); }
public void Intersect_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.Intersect(otherSet); StringBuilder actual = new StringBuilder(); foreach (var item in set) { actual.Append(item + " "); } string expected = "3 "; Assert.AreEqual(expected, actual.ToString()); }
/// <summary> /// Compute depths for all dirEdges via breadth-first traversal of nodes in graph. /// </summary> /// <param name="startEdge">Edge to start processing with.</param> // <FIX> MD - use iteration & queue rather than recursion, for speed and robustness private void ComputeDepths(DirectedEdge startEdge) { ISet nodesVisited = new HashedSet(); Queue nodeQueue = new Queue(); Node startNode = startEdge.Node; nodeQueue.Enqueue(startNode); nodesVisited.Add(startNode); startEdge.Visited = true; while (nodeQueue.Count != 0) { Node n = (Node)nodeQueue.Dequeue(); nodesVisited.Add(n); // compute depths around node, starting at this edge since it has depths assigned ComputeNodeDepth(n); // add all adjacent nodes to process queue, unless the node has been visited already IEnumerator i = ((DirectedEdgeStar)n.Edges).GetEnumerator(); while (i.MoveNext()) { DirectedEdge de = (DirectedEdge)i.Current; DirectedEdge sym = de.Sym; if (sym.IsVisited) { continue; } Node adjNode = sym.Node; if (!(nodesVisited.Contains(adjNode))) { nodeQueue.Enqueue(adjNode); nodesVisited.Add(adjNode); } } } }
/// <summary> /// <code> function INFER(clause, usable) returns clauses </code> /// </summary> /// <param name="clause"></param> /// <param name="usable"></param> /// <returns></returns> private ISet<Clause> Infer(Clause clause, ISet<Clause> usable) { ISet<Clause> resultingClauses = new HashedSet<Clause>(); // * resolve clause with each member of usable foreach (var c in usable) { ISet<Clause> resolvents = clause.BinaryResolvents(c); foreach (Clause rc in resolvents) { resultingClauses.Add(rc); } // if using paramodulation to handle equality if (this.UseParamodulation) { var paras = paramodulation.Apply(clause, c, true); foreach (var p in paras) { resultingClauses.Add(p); } } } // * return the resulting clauses after applying filter return ClauseFilter.Filter(resultingClauses); }
/* 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)); }
public void AddShouldNotThrowExceptionWhenTheSameKeyIsAlreadyPresent() { var hashedset = new HashedSet <string>(); hashedset.Add("gosho"); hashedset.Add("gosho"); }
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")); } }
public void IntersectShouldWorkCorrectlyOnValidInput() { var set1 = new HashedSet <int>(); set1.Add(1); set1.Add(2); set1.Add(3); var set2 = new HashedSet <int>(); set2.Add(2); set2.Add(3); set2.Add(4); var expectedResultElements = new List <int>() { 2, 3 }; set1.Intersect(set2); foreach (var value in set1) { expectedResultElements.Remove(value); } Assert.AreEqual(0, expectedResultElements.Count); }
public void AddShouldNotThrowExceptionWhenTheSameKeyIsAlreadyPresent() { var hashedset = new HashedSet<string>(); hashedset.Add("gosho"); hashedset.Add("gosho"); }
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 test() { using (ISession s = OpenSession()) using (ITransaction tx = s.BeginTransaction()) { Person person = new Person("1"); person.Name = "John Doe"; HashedSet set = new HashedSet(); 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>()); Assert.IsTrue((person.Properties["Phones"] as ISet).Contains("555-1234")); Assert.IsTrue((person.Properties["Phones"] as ISet).Contains("555-4321")); } }
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); } }
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); } }
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()); }
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 static IndexSearcher BuildSearcher(ISearchFactoryImplementor searchFactory, out ISet <System.Type> classesAndSubclasses, params System.Type[] classes) { IDictionary <System.Type, DocumentBuilder> builders = searchFactory.DocumentBuilders; ISet <IDirectoryProvider> directories = new HashedSet <IDirectoryProvider>(); if (classes == null || classes.Length == 0) { // no class means all classes foreach (DocumentBuilder builder in builders.Values) { foreach (IDirectoryProvider provider in builder.DirectoryProvidersSelectionStrategy.GetDirectoryProvidersForAllShards()) { directories.Add(provider); } } // Give them back an empty set classesAndSubclasses = null; } else { ISet <System.Type> involvedClasses = new HashedSet <System.Type>(); involvedClasses.AddAll(classes); foreach (System.Type clazz in classes) { DocumentBuilder builder; builders.TryGetValue(clazz, out builder); if (builder != null) { involvedClasses.AddAll(builder.MappedSubclasses); } } foreach (System.Type clazz in involvedClasses) { DocumentBuilder builder; builders.TryGetValue(clazz, out builder); // TODO should we rather choose a polymorphic path and allow non mapped entities if (builder == null) { throw new HibernateException("Not a mapped entity: " + clazz); } foreach (IDirectoryProvider provider in builder.DirectoryProvidersSelectionStrategy.GetDirectoryProvidersForAllShards()) { directories.Add(provider); } } classesAndSubclasses = involvedClasses; } IDirectoryProvider[] directoryProviders = new List <IDirectoryProvider>(directories).ToArray(); return(new IndexSearcher(searchFactory.ReaderProvider.OpenReader(directoryProviders))); }
public void IntersectShouldThrowOnInvalidInput() { var set1 = new HashedSet <int>(); set1.Add(5); set1.Add(3); set1.Intersect(null); }
private Set <ShardId> GetShardIdSet() { Set <ShardId> hashedSet = new HashedSet <ShardId>(); hashedSet.Add(new ShardId(1)); hashedSet.Add(new ShardId(2)); hashedSet.Add(new ShardId(3)); return(hashedSet); }
public static IndexSearcher BuildSearcher(ISearchFactoryImplementor searchFactory, out ISet<System.Type> classesAndSubclasses, params System.Type[] classes) { IDictionary<System.Type, DocumentBuilder> builders = searchFactory.DocumentBuilders; ISet<IDirectoryProvider> directories = new HashedSet<IDirectoryProvider>(); if (classes == null || classes.Length == 0) { // no class means all classes foreach (DocumentBuilder builder in builders.Values) { foreach (IDirectoryProvider provider in builder.DirectoryProvidersSelectionStrategy.GetDirectoryProvidersForAllShards()) { directories.Add(provider); } } // Give them back an empty set classesAndSubclasses = null; } else { ISet<System.Type> involvedClasses = new HashedSet<System.Type>(); involvedClasses.AddAll(classes); foreach (System.Type clazz in classes) { DocumentBuilder builder; builders.TryGetValue(clazz, out builder); if (builder != null) { involvedClasses.AddAll(builder.MappedSubclasses); } } foreach (System.Type clazz in involvedClasses) { DocumentBuilder builder; builders.TryGetValue(clazz, out builder); // TODO should we rather choose a polymorphic path and allow non mapped entities if (builder == null) { throw new HibernateException("Not a mapped entity: " + clazz); } foreach (IDirectoryProvider provider in builder.DirectoryProvidersSelectionStrategy.GetDirectoryProvidersForAllShards()) { directories.Add(provider); } } classesAndSubclasses = involvedClasses; } IDirectoryProvider[] directoryProviders = new List<IDirectoryProvider>(directories).ToArray(); return new IndexSearcher(searchFactory.ReaderProvider.OpenReader(directoryProviders)); }
public void UnionShouldThrowOnInvalidInput() { var set1 = new HashedSet <int>(); set1.Add(5); set1.Add(3); set1.Union(null); }
public void IntersectShouldReturnCollectionWithRepeatValues() { HashedSet<string> set = new HashedSet<string>(); set.Add("value 1"); set.Add("Pesho"); var resultSet = hashedSet.Intersect(set); Assert.AreEqual(1, resultSet.Count()); }
public void ShouldNotAddDuplicateValues() { var set = new HashedSet <int>(); set.Add(1); set.Add(1); set.Add(1); Assert.AreEqual(1, set.Count); }
public void ShouldCorrectlyAddAllValues() { var set = new HashedSet <int>(); set.Add(1); set.Add(3); set.Add(9); Assert.AreEqual(3, set.Count); }
public void AddingExistingElementShouldDoNothing() { testSet = new HashedSet <string>(); testSet.Add("Pesho"); testSet.Add("Pesho"); testSet.Add("Pesho"); testSet.Add("Pesho"); Assert.AreEqual(1, testSet.Count); }
public void ClearShouldEmptyCollection() { testSet = new HashedSet <string>(); testSet.Add("Pesho"); testSet.Add("Gosho"); testSet.Clear(); int countAfterClearing = testSet.Count; Assert.AreEqual(0, countAfterClearing); }
public void ShouldCorrectlyAddAllValues() { var set = new HashedSet<int>(); set.Add(1); set.Add(3); set.Add(5); set.Add(7); set.Add(9); Assert.AreEqual(5, set.Count); }
public void ShouldNotAddDuplicateValues() { var set = new HashedSet<int>(); set.Add(1); set.Add(1); set.Add(1); set.Add(1); set.Add(1); Assert.AreEqual(1, set.Count); }
public void ShouldReturnCorrectUnion() { var set = new HashedSet<int>(); set.Add(1); set.Add(2); var otherSet = new HashedSet<int>(); otherSet.Add(2); otherSet.Add(3); CollectionAssert.AreEqual(new[] { 1, 2, 3 }, set.Union(otherSet)); }
public void ShouldReturnCorrectIntersection() { var set = new HashedSet<int>(); set.Add(1); set.Add(2); var otherSet = new HashedSet<int>(); otherSet.Add(2); otherSet.Add(3); CollectionAssert.AreEqual(new[] { 2 }, set.IntersectsWith(otherSet)); }
static void Main() { HashedSet <int> set = new HashedSet <int>(); set.Add(5); set.Add(5); set.Add(6); set.Add(1); set.Add(3); set.Add(3); set.Add(8); set.Remove(6); Console.WriteLine("First set contains 6 - {0}", set.Contains(6)); Console.WriteLine("First set contains 8 - {0}", set.Contains(8)); Console.WriteLine("First set"); foreach (var item in set) { Console.Write("{0} ", item); } Console.WriteLine(); Console.WriteLine("Second set"); HashedSet <int> set2 = new HashedSet <int>(); set2.Add(13); set2.Add(3); set2.Add(1); foreach (var item in set2) { Console.Write("{0} ", item); } Console.WriteLine(); HashedSet <int> union = set.UnionWith(set2); Console.WriteLine("Union: "); foreach (var item in union) { Console.Write("{0} ", item); } Console.WriteLine(); HashedSet <int> intersection = set.IntersectWith(set2); Console.WriteLine("Intersection: "); foreach (var item in intersection) { Console.Write("{0} ", item); } Console.WriteLine(); }
public void test_addLjava_lang_Object() { // Test for method boolean java.util.HashSet.add(java.lang.Object) int size = hs.Count; hs.Add(8); Assertion.Assert("Added element already contained by set", hs.Count == size); hs.Add(-9); Assertion.Assert("Failed to increment set size after add", hs.Count == size + 1); Assertion.Assert("Failed to add element to set", hs.Contains(-9)); }
public void TestClearMethodToClearAllElements() { HashedSet <string> first = new HashedSet <string>(); first.Add("TestIntro"); first.Add("PHP"); first.Add("Java"); first.Clear(); Assert.AreEqual(0, first.Count); }
public DynamicMapInstantiator(PersistentClass mappingInfo) { entityName = mappingInfo.EntityName; isInstanceEntityNames.Add(entityName); if (mappingInfo.HasSubclasses) { foreach (PersistentClass subclassInfo in mappingInfo.SubclassClosureIterator) { isInstanceEntityNames.Add(subclassInfo.EntityName); } } }
protected void Page_Load(object sender, EventArgs e) { Response.Write(User.Identity.IsAuthenticated); TestController tc = new TestController("~/WebNHibernate.config"); //IList lstA = tc.TestHqlFullText("2"); //Response.Write(lstA.Count); //Random r = new Random(); //for (int i = 0; i < 20; i++) //{ // Test t = new Test(); // t.TestProperty = r.Next().ToString(); // tc.Save(t); //} List <Test> lstTest = tc.GetAll() as List <Test>; Test t = new Test(); t.TestProperty = lstTest[0].TestProperty; Test t1 = new Test(); t1.TestProperty = lstTest[0].TestProperty; HashedSet <Test> lstOld = new HashedSet <Test>(); lstOld.Add(lstTest[0]); lstOld.Add(t); lstOld.Add(t1); Response.Write(lstOld.Count); //Response.Write(contains); //foreach (Test t in lstOld) // t.TestProperty = "2"; //IList<Test> lst = tc.GetAll(); //Response.Write(lst[0].Version + lst[0].TimeStamp.ModifiedOn.ToString()); //// Creates a conflict //lstOld[0].TestProperty = "3"; //tc.Save(lstOld[0]); //Response.Write(lst[0].Version); //foreach(Test t in tc.GetAll()) //{ // //Response.Write(t.TimeStamp); // t.TestProperty = r.Next().ToString(); //} }
public Set <TurkceHarf> olasiBaslangicHarfleri(List <EkUretimBileseni> bilesenler) { Set <TurkceHarf> kume = new HashedSet <TurkceHarf>();//TOREMEMBER 4 for (int i = 0; i < bilesenler.Count; i++) { EkUretimBileseni bilesen = bilesenler[i]; TurkceHarf harf = bilesen.harf(); switch (bilesen.kural()) { case UretimKurali.HARF: kume.Add(harf); return(kume); case UretimKurali.KAYNASTIR: kume.Add(harf); break; case UretimKurali.SERTLESTIR: kume.Add(harf); kume.Add(harf.sertDonusum()); return(kume); case UretimKurali.SESLI_AE: kume.Add(HARF_a); kume.Add(HARF_e); if (i > 0) { return(kume); } else { break; } case UretimKurali.SESLI_IU: kume.Add(HARF_i); kume.Add(HARF_u); kume.Add(HARF_ii); kume.Add(HARF_uu); if (i > 0) { return(kume); } else { break; } } } return(kume); }
public void ShouldReturnCorrectIntersection() { var set = new HashedSet <int>(); set.Add(1); set.Add(2); var otherSet = new HashedSet <int>(); otherSet.Add(2); otherSet.Add(3); CollectionAssert.AreEqual(new[] { 2 }, set.IntersectsWith(otherSet)); }
public void ShouldReturnCorrectUnion() { var set = new HashedSet <int>(); set.Add(1); set.Add(2); var otherSet = new HashedSet <int>(); otherSet.Add(2); otherSet.Add(3); CollectionAssert.AreEqual(new[] { 1, 2, 3 }, set.Union(otherSet)); }
static void Main(string[] args) { HashedSet <int> testHashSet = new HashedSet <int>(2); Console.WriteLine("Current HashSet count: {0}", testHashSet.Count); testHashSet.Add(1); testHashSet.Add(2); testHashSet.Add(2); testHashSet.Add(2); testHashSet.Add(3); testHashSet.Add(4); testHashSet.Add(5); testHashSet.Add(6); Console.WriteLine(new String('*', 30)); Console.WriteLine("Current HashSet content:"); PrintHashSet(testHashSet); Console.WriteLine(new String('*', 30)); Console.WriteLine("Current HashSet count: {0}", testHashSet.Count); Console.WriteLine(new String('*', 30)); Console.WriteLine("Check if value 1 exist in the HashSet: {0}", testHashSet.Find(1)); Console.WriteLine(new String('*', 30)); Console.WriteLine("Check if value 11 exist in the HashSet: {0}", testHashSet.Find(11)); testHashSet.Remove(5); Console.WriteLine(new String('*', 30)); Console.WriteLine("HashSet content after removing 5:"); PrintHashSet(testHashSet); HashedSet <int> testHashSet2 = new HashedSet <int>(2); testHashSet2.Add(1); testHashSet2.Add(2); testHashSet2.Add(12); HashedSet <int> testHashSetUnion = testHashSet.Union(testHashSet2); Console.WriteLine(new String('*', 30)); Console.WriteLine("HashSet union with HashSet [1, 2, 12]:"); PrintHashSet(testHashSetUnion); HashedSet <int> testHashSetIntersection = testHashSet.Intersection(testHashSet2); Console.WriteLine(new String('*', 30)); Console.WriteLine("HashSet intersection with HashSet [1, 2, 12]:"); PrintHashSet(testHashSetIntersection); }
public void CustomIComparer() { HashedSet <int> set1 = new HashedSet <int>(new ModularComparer(5)); bool b; b = set1.Add(4); Assert.IsTrue(b); b = set1.Add(11); Assert.IsTrue(b); b = set1.Add(9); Assert.IsFalse(b); b = set1.Add(15); Assert.IsTrue(b); Assert.IsTrue(set1.Contains(25)); Assert.IsTrue(set1.Contains(26)); Assert.IsFalse(set1.Contains(27)); }
public void TestUnionMethod() { var hashedSet = new HashedSet<int>(); Assert.IsTrue(hashedSet.Add(1)); Assert.IsTrue(hashedSet.Add(2)); Assert.AreEqual(2, hashedSet.Count); int[] unionArray = { 2, 3, 4, 5 }; hashedSet.UnionWith(unionArray); Assert.AreEqual(5, hashedSet.Count); CollectionAssert.AreEqual(hashedSet.Keys.ToList(), new List<int>() { 1, 2, 3, 4, 5 }); }
public void Add() { HashedSet<string> set1 = new HashedSet<string>( StringComparer.InvariantCultureIgnoreCase); bool b; b = set1.Add("hello"); Assert.IsTrue(b); b = set1.Add("foo"); Assert.IsTrue(b); b = set1.Add(""); Assert.IsTrue(b); b = set1.Add("HELLO"); Assert.IsFalse(b); b = set1.Add("foo"); Assert.IsFalse(b); b = set1.Add("Hello"); Assert.IsFalse(b); b = set1.Add("Eric"); Assert.IsTrue(b); }
public byte[] GetBinaryFileContents(string fileName) { var file = directory.GetFile(fileName); importFilePaths.Add(file.FullPath); using (var buffer = new MemoryStream()) { using (var fileStream = file.OpenRead()) { fileStream.CopyTo(buffer); } return(buffer.ToArray()); } }
static void Main() { HashedSet<int> set = new HashedSet<int>(); set.Add(5); set.Add(5); set.Add(6); set.Add(1); set.Add(3); set.Add(3); set.Add(8); set.Remove(6); Console.WriteLine("First set contains 6 - {0}", set.Contains(6)); Console.WriteLine("First set contains 8 - {0}", set.Contains(8)); Console.WriteLine("First set"); foreach (var item in set) { Console.Write("{0} ", item); } Console.WriteLine(); Console.WriteLine("Second set"); HashedSet<int> set2 = new HashedSet<int>(); set2.Add(13); set2.Add(3); set2.Add(1); foreach (var item in set2) { Console.Write("{0} ", item); } Console.WriteLine(); HashedSet<int> union = set.UnionWith(set2); Console.WriteLine("Union: "); foreach (var item in union) { Console.Write("{0} ", item); } Console.WriteLine(); HashedSet<int> intersection = set.IntersectWith(set2); Console.WriteLine("Intersection: "); foreach (var item in intersection) { Console.Write("{0} ", item); } Console.WriteLine(); }
private static void AddXmlToNHibernateFromAssmebliesAttributes(ISessionFactoryHolder holder, ActiveRecordModelCollection models) { Iesi.Collections.Generic.ISet <Assembly> assembliesGeneratedXmlFor = new HashedSet <Assembly>(); AssemblyXmlGenerator assemblyXmlGenerator = new AssemblyXmlGenerator(); foreach (ActiveRecordModel model in models) { if (assembliesGeneratedXmlFor.Contains(model.Type.Assembly)) { continue; } assembliesGeneratedXmlFor.Add(model.Type.Assembly); Configuration config = holder.GetConfiguration(holder.GetRootType(model.Type)); string[] configurations = assemblyXmlGenerator.CreateXmlConfigurations(model.Type.Assembly); foreach (string xml in configurations) { if (xml != string.Empty) { config.AddXmlString(xml); } } } foreach (Assembly assembly in registeredAssemblies) { if (assembliesGeneratedXmlFor.Contains(assembly)) { continue; } assembliesGeneratedXmlFor.Add(assembly); Configuration config = holder.GetConfiguration(holder.GetRootType(typeof(ActiveRecordBase))); string[] configurations = assemblyXmlGenerator.CreateXmlConfigurations(assembly); foreach (string xml in configurations) { if (xml != string.Empty) { config.AddXmlString(xml); } } } }
public void TestContainsMethod() { var hashedSet = new HashedSet<int>(); Assert.IsTrue(hashedSet.Add(1)); Assert.IsTrue(hashedSet.Add(2)); Assert.IsTrue(hashedSet.Add(3)); Assert.IsTrue(hashedSet.Add(4)); Assert.AreEqual(4, hashedSet.Count); Assert.IsTrue(hashedSet.Contains(3)); Assert.IsTrue(hashedSet.Contains(4)); Assert.IsFalse(hashedSet.Contains(-5)); Assert.IsFalse(hashedSet.Contains(14)); }
/// <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 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)); }
public void TestFindWithInvalidKey() { var table = new HashedSet<string>(); table.Add("Pesho"); var value = table.Find("Peho"); }
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"); }
public IEnumerable Distinct(IEnumerable source) { var s = new HashedSet(); foreach (object item in source) s.Add(item); return s; }
public void TestIntersectMethod() { var hashedSet = new HashedSet<int>(); Assert.IsTrue(hashedSet.Add(1)); Assert.IsTrue(hashedSet.Add(2)); Assert.IsTrue(hashedSet.Add(3)); Assert.IsTrue(hashedSet.Add(4)); Assert.AreEqual(4, hashedSet.Count); int[] intersectArray = { 2, 3 }; hashedSet.IntersectWith(intersectArray); Assert.AreEqual(2, hashedSet.Count); CollectionAssert.AreEqual(hashedSet.Keys.ToList(), new List<int>() { 2, 3 }); }
/// <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 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) { // 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; }