Exemplo n.º 1
0
        static public void Test()
        {
            BitVector S1 = 0b0011_0010;
            BitVector S2 = 0b0100_0011;

            Debug.Assert(SetOp.Union(S1, S2) == 0b0111_0011);
            Debug.Assert(SetOp.Union(S1, S2) == SetOp.Union(S2, S1));
            Debug.Assert(SetOp.Intersect(S1, S2) == 0b0000_0010);
            Debug.Assert(SetOp.Intersect(S1, S2) == SetOp.Intersect(S2, S1));
            Debug.Assert(SetOp.Substract(S1, S2) == 0b0011_0000);
            Debug.Assert(SetOp.Substract(S2, S1) == 0b0100_0001);

            Debug.Assert(SetOp.CountSetBits(S1) == 3);
            Debug.Assert(SetOp.MinTableIndex(S1) == 1);
            Debug.Assert(SetOp.MinTableIndex(S2) == 0);
            Debug.Assert(SetOp.OrderBeforeSet(3) == 15);

            var l = SetOp.TablesAscending(S2).ToList();

            Debug.Assert(l.SequenceEqual(new List <int>()
            {
                0, 1, 6
            }));
            l = SetOp.TablesDescending(S2).ToList();
            Debug.Assert(l.SequenceEqual(new List <int>()
            {
                6, 1, 0
            }));
        }
Exemplo n.º 2
0
        // There are two ways of enumeration:
        //  1. full set is not included
        //  2. full set is included
        //
        internal IEnumerable <BitVector> Next(bool fullsetIncluded = false)
        {
            BitVector S1, S2, S;
            int       counter = 0;

            S  = S_;
            S1 = 0;
            do
            {
                S1 = S & (S1 - S);
                if (S1 != S || fullsetIncluded)
                {
                    counter++;
                    S2 = SetOp.CoveredSubstract(S, S1);
                    //Console.WriteLine(Convert.ToString(S1, 2).PadLeft(8,'0') + ":" + Convert.ToString(S2, 2).PadLeft(8, '0'));
                    yield return(S1);
                }
            } while (S1 != S);

            // result includes all combinations except emtpy and full set (optional)
            Debug.Assert(counter - (fullsetIncluded ? 1 : 0)
                         == (1 << SetOp.CountSetBits(S)) - 2);
        }