public static SimpleSet operator *(SimpleSet op1, SimpleSet op2) { (SimpleSet biggest, SimpleSet smallest) = op1.MaxElem > op2.MaxElem ? (op1, op2) : (op2, op1); SimpleSet resultSimpleSet = new SimpleSet(biggest.MaxElem); for (int i = 0; i <= smallest.MaxElem; i++) { resultSimpleSet._data[i] = biggest._data[i] && smallest._data[i]; } return(resultSimpleSet); }
public static SimpleSet operator *(SimpleSet lhs, SimpleSet rhs) { var length = Math.Min(lhs.Max, rhs.Max); var result = new SimpleSet(length); for (var i = 0; i < length; i++) { result._arr[i] = lhs._arr[i] && rhs._arr[i]; } return(result); }
public static void SimpleSetTest1() { SimpleSet mySet1 = new SimpleSet(2); SimpleSet mySet2 = new SimpleSet(3); mySet1.FillSet(new int[] { 0, 1, 2 }); mySet1.Print(Console.WriteLine); mySet2.FillSet("0 3"); mySet2.Print(Console.WriteLine); Console.WriteLine(); (mySet1 + mySet2).Print(Console.WriteLine); (mySet1 * mySet2).Print(Console.WriteLine); Console.WriteLine(); }
public static SimpleSet operator +(SimpleSet lhs, SimpleSet rhs) { var minLength = Math.Min(lhs.Max, rhs.Max); var length = Math.Max(lhs.Max, rhs.Max); var result = new SimpleSet(length); for (var i = 0; i < minLength; i++) { result._arr[i] = lhs._arr[i] || rhs._arr[i]; } var biggest = lhs.Max > rhs.Max ? lhs : rhs; for (var i = minLength; i < length; i++) { result._arr[i] = biggest._arr[i]; } return(result); }
static void Main(string[] args) { var s = new SimpleSet(100); s.Append(new[] { 1, 2, 3, 4, 10, 11, 100 }); s.Remove(10); Console.WriteLine(s); var s2 = new BitSet(20); s2.Append("1 2 3 4 20 19 20 18"); s2.Remove(18); Console.WriteLine(s2); var s3 = new MultiSet(10); s3.Append(new[] { 1, 1, 2, 2, 10, 9, 9 }); s3.Remove(1); s3.Remove(9); Console.WriteLine(s3); s.Add(101); }
public void TestUnionAndIntersection(object args) { int tmpTypeOfSet = typeOfSet; Set set1; Set set2; SetTypeOfSet(null); switch (typeOfSet) { case 1: { set1 = new SimpleSet(max); set2 = new SimpleSet(max); break; } case 2: { set1 = new BitSet(max); set2 = new BitSet(max); break; } case 3: { set1 = new MultiSet(max); set2 = new MultiSet(max); break; } default: { set1 = new SimpleSet(max); set2 = new SimpleSet(max); break; } } typeOfSet = tmpTypeOfSet; Settings.Default.TypeSet = typeOfSet; Settings.Default.Save(); string s1, s2; Console.WriteLine("Введите первую строку, с которой будет заполнено множество один"); s1 = GetCommandString(); try { set1.FillSet(s1); } catch (ElemOutOfSetExeption e) { Console.WriteLine(e.Message); } Console.WriteLine("Введите вторую строку, с которой будет заполнено множество два"); s2 = GetCommandString(); try { set2.FillSet(s2); } catch (ElemOutOfSetExeption e) { Console.WriteLine(e.Message); } Console.WriteLine("Объединение множеств:"); if (set1 is SimpleSet) { Console.WriteLine(((SimpleSet)set1 + (SimpleSet)set2)); } else if (set1 is BitSet) { Console.WriteLine(((BitSet)set1 + (BitSet)set2)); } else if (set1 is MultiSet) { Console.WriteLine(((MultiSet)set1 + (MultiSet)set2)); } Console.WriteLine("Пересечение множеств:"); if (set1 is SimpleSet) { Console.WriteLine(((SimpleSet)set1 * (SimpleSet)set2)); } else if (set1 is BitSet) { Console.WriteLine(((BitSet)set1 * (BitSet)set2)); } else if (set1 is MultiSet) { Console.WriteLine(((MultiSet)set1 * (MultiSet)set2)); } }