Esempio n. 1
0
 public bool IsSubset(PowerSet <T> set2)
 {
     if (Size() >= set2.Size())
     {
         if (set2.Size() == 0)
         {
             return(true);
         }
         for (int i = 0; i < size; i++)
         {
             if (set2.slots[i] != null && !set2.slots[i].Equals(default(T)))
             {
                 if (!Get(set2.slots[i]))
                 {
                     break;
                 }
             }
             if (i == size - 1)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 2
0
 public bool IsSubset(PowerSet <T> set2) // возвращает true, если set2 есть подмножество текущего множества, иначе false
 {
     if (Size() >= set2.Size())
     {
         if (set2.Size() == 0)
         {
             return(true);
         }
         for (int i = 0; i < size; i++)
         {
             if (set2.slots[i] != null && !set2.slots[i].Equals(default(T)))
             {
                 if (!Get(set2.slots[i]))
                 {
                     break;
                 }
             }
             if (i == size - 1)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 3
0
        static void TestFunc(PowerSet <int> set1, PowerSet <int> set2, Func <PowerSet <int>, PowerSet <int>, PowerSet <int> > testFunc)
        {
            if (set1.Size() == 0)
            {
                Console.Write("set1 is empty");
            }
            else
            {
                Console.WriteLine("set1");
                for (int i = 0; i < set1._values.Length; i++)
                {
                    if (set1._slotsStatus[i] == PowerSet <int> .SlotStatus.Fill)
                    {
                        Console.Write(set1._values[i] + " ");
                    }
                }
            }

            Console.WriteLine();

            if (set2.Size() == 0)
            {
                Console.Write("set2 is empty");
            }
            else
            {
                Console.WriteLine("set2");
                for (int i = 0; i < set2._values.Length; i++)
                {
                    if (set2._slotsStatus[i] == PowerSet <int> .SlotStatus.Fill)
                    {
                        Console.Write(set2._values[i] + " ");
                    }
                }
            }

            Console.WriteLine();

            PowerSet <int> resultSet = testFunc(set1, set2);

            if (resultSet.Size() == 0)
            {
                Console.Write("result set is empty");
            }
            else
            {
                Console.WriteLine("result set");
                for (int i = 0; i < resultSet._values.Length; i++)
                {
                    if (resultSet._slotsStatus[i] == PowerSet <int> .SlotStatus.Fill)
                    {
                        Console.Write(resultSet._values[i] + " ");
                    }
                }
            }

            Console.WriteLine();

            Console.WriteLine(new string('=', 50));
        }
Esempio n. 4
0
        static void TestIsSubset(PowerSet <int> set1, PowerSet <int> set2)
        {
            if (set1.Size() == 0)
            {
                Console.Write("set1 is empty");
            }
            else
            {
                Console.WriteLine("set1");
                for (int i = 0; i < set1._values.Length; i++)
                {
                    if (set1._slotsStatus[i] == PowerSet <int> .SlotStatus.Fill)
                    {
                        Console.Write(set1._values[i] + " ");
                    }
                }
            }

            Console.WriteLine();

            if (set2.Size() == 0)
            {
                Console.Write("set2 is empty");
            }
            else
            {
                Console.WriteLine("set2");
                for (int i = 0; i < set2._values.Length; i++)
                {
                    if (set2._slotsStatus[i] == PowerSet <int> .SlotStatus.Fill)
                    {
                        Console.Write(set2._values[i] + " ");
                    }
                }
            }

            Console.WriteLine();

            bool result = set1.IsSubset(set2);

            Console.WriteLine("result is subset = " + result);

            Console.WriteLine(new string('=', 50));
        }
Esempio n. 5
0
        static void TestPowerSet()
        {
            Console.WriteLine("test power set");
            PowerSet <int> powerSet = new PowerSet <int>();

            for (int i = 0; i <= 10; i++)
            {
                powerSet.Put(i);
            }

            for (int i = 0; i < powerSet._values.Length; i++)
            {
                Console.Write(powerSet._values[i] + " ");
            }

            Console.WriteLine();
            Console.WriteLine("test put 11");
            Console.WriteLine("power set size before  = " + powerSet.Size());
            powerSet.Put(11);
            Console.WriteLine("power set size after = " + powerSet.Size());

            for (int i = 0; i < powerSet._values.Length; i++)
            {
                Console.Write(powerSet._values[i] + " ");
            }

            Console.WriteLine();

            Console.WriteLine("test put 10");
            Console.WriteLine("power set size before  = " + powerSet.Size());
            powerSet.Put(10);
            Console.WriteLine("power set size after = " + powerSet.Size());

            for (int i = 0; i < powerSet._values.Length; i++)
            {
                Console.Write(powerSet._values[i] + " ");
            }

            Console.WriteLine();
            Console.WriteLine("test remove 4");
            Console.WriteLine("power set size before  = " + powerSet.Size());
            bool result = powerSet.Remove(4);

            Console.WriteLine("power set size after = " + powerSet.Size());
            Console.WriteLine("remove result = " + result);
            for (int i = 0; i < powerSet._values.Length; i++)
            {
                Console.Write(powerSet._values[i] + " ");
            }

            Console.WriteLine();
            Console.WriteLine("test remove 4");
            Console.WriteLine("power set size before  = " + powerSet.Size());
            result = powerSet.Remove(4);
            Console.WriteLine("power set size after = " + powerSet.Size());
            Console.WriteLine("remove result = " + result);
            for (int i = 0; i < powerSet._values.Length; i++)
            {
                Console.Write(powerSet._values[i] + " ");
            }

            Console.WriteLine();
            Console.WriteLine("test remove 20");
            Console.WriteLine("power set size before  = " + powerSet.Size());
            result = powerSet.Remove(20);
            Console.WriteLine("power set size after = " + powerSet.Size());
            Console.WriteLine("remove result = " + result);
            for (int i = 0; i < powerSet._values.Length; i++)
            {
                Console.Write(powerSet._values[i] + " ");
            }

            Console.WriteLine("test get");

            for (int i = 0; i < powerSet._values.Length; i++)
            {
                Console.WriteLine(i + " get result = " + powerSet.Get(i));
            }

            Console.WriteLine();
            Console.WriteLine(new string('=', 50));
        }