コード例 #1
0
ファイル: Set.cs プロジェクト: gtryf/MIXWare
 // union
 public static Set <TEnum> operator |(Set <TEnum> left, Set <TEnum> right)
 {
     System.Collections.BitArray result = new System.Collections.BitArray(new bool[left.members.Count]);
     result.Or(left.members);
     if (right != null)
     {
         result.Or(right.members);
     }
     return(new Set <TEnum>(result));
 }
コード例 #2
0
ファイル: Set.cs プロジェクト: gtryf/MIXWare
 public Set <TEnum> Add(Set <TEnum> otherSet)
 {
     if (otherSet != null)
     {
         members.Or(otherSet.members);
     }
     return(this);
 }
コード例 #3
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Determine if this set is an (improper) subset of another.
        /// </summary>
        /// <param name="other">the set we are testing against.
        ///
        /// </param>
        public virtual bool is_subset_of(terminal_set other)
        {
            not_null(other);

            /* make a copy of the other set */
            System.Collections.BitArray copy_other = (System.Collections.BitArray)other._elements.Clone();

            /* and or in */
            copy_other = copy_other.Or(_elements);

            /* if it hasn't changed, we were a subset */
            return(BitArraysEqual(copy_other, other._elements));
            /// copy_other.Equals(other._elements);
        }
コード例 #4
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Add (union) in a complete set.
        /// </summary>
        /// <param name="other">the set being added.
        /// </param>
        /// <returns>true if this changes the set.
        ///
        /// </returns>
        public virtual bool add(terminal_set other)
        {
            not_null(other);

            /* make a copy */
            System.Collections.BitArray copy = (System.Collections.BitArray)_elements.Clone();

            /* or in the other set */
            //UPGRADE_NOTE: In .NET BitArrays must be of the same size to allow the 'System.Collections.BitArray.Or' operation. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1083"'
            _elements = _elements.Or(other._elements);

            /* changed if we are not the same as the copy */
            //UPGRADE_TODO: method 'java.util.BitSet.equals' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilBitSetequals_javalangObject"'
            return(!BitArraysEqual(_elements, copy));
            // _elements.Equals(copy);
        }
コード例 #5
0
        public void Or_Test(int[] bits1, int[] bits2)
        {
            var size      = 12;
            var array1    = CreateArray(size);
            var array2    = CreateArray(size);
            var expected1 = new System.Collections.BitArray(size);
            var expected2 = new System.Collections.BitArray(size);

            foreach (var bit in bits1)
            {
                array1[bit] = expected1[bit] = true;
            }
            foreach (var bit in bits2)
            {
                array2[bit] = expected2[bit] = true;
            }

            var array    = array1.Or(array2);
            var expected = expected1.Or(expected2);

            CollectionAssert.AreEqual(array, expected);
            Assert.AreEqual(expected.Count, array.Count);
        }
コード例 #6
0
 public SafeBitArray(SafeBitArray bitset, int len)
     : this(len)
 {
     _bits.Or(bitset._bits);
     mPointer = len - 1;
 }
コード例 #7
0
ファイル: RGraph.cs プロジェクト: carlhuth/GenXSource
        /// <summary>  Parsing of the RGraph. This is the recursive method
        /// to perform a query. The method will recursively
        /// parse the RGraph thru connected nodes and visiting the
        /// RGraph using allowed adjacency relationship.
        ///
        /// </summary>
        /// <param name="traversed"> node already parsed
        /// </param>
        /// <param name="extension"> possible extension node (allowed neighbours)
        /// </param>
        /// <param name="forbiden">  node forbiden (set of node incompatible with the current solution)
        /// </param>
        private void parseRec(System.Collections.BitArray traversed, System.Collections.BitArray extension, System.Collections.BitArray forbidden)
        {
            System.Collections.BitArray newTraversed  = null;
            System.Collections.BitArray newExtension  = null;
            System.Collections.BitArray newForbidden  = null;
            System.Collections.BitArray potentialNode = null;

            // if there is no more extension possible we
            // have reached a potential new solution
            if (isEmpty(extension))
            {
                solution(traversed);
            }
            // carry on with each possible extension
            else
            {
                // calculates the set of nodes that may still
                // be reached at this stage (not forbiden)
                potentialNode = ((System.Collections.BitArray)graphBitSet.Clone());
                potentialNode.And(forbidden.Not());
                //UPGRADE_NOTE: In .NET BitArrays must be of the same size to allow the 'System.Collections.BitArray.Or' operation. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1083'"
                potentialNode.Or(traversed);

                // checks if we must continue the search
                // according to the potential node set
                if (mustContinue(potentialNode))
                {
                    // carry on research and update iteration count
                    nbIteration++;

                    // for each node in the set of possible extension (neighbours of
                    // the current partial solution, include the node to the solution
                    // and perse recursively the RGraph with the new context.
                    for (int x = nextSetBit(extension, 0); x >= 0 && !stop; x = nextSetBit(extension, x + 1))
                    {
                        // evaluates the new set of forbidden nodes
                        // by including the nodes not compatible with the
                        // newly accepted node.
                        newForbidden = (System.Collections.BitArray)forbidden.Clone();
                        //UPGRADE_NOTE: In .NET BitArrays must be of the same size to allow the 'System.Collections.BitArray.Or' operation. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1083'"
                        newForbidden.Or(((RNode)graph[x]).forbidden);

                        // if it is the first time we are here then
                        // traversed is empty and we initialize the set of
                        // possible extensions to the extension of the first
                        // accepted node in the solution.
                        if (isEmpty(traversed))
                        {
                            newExtension = (System.Collections.BitArray)(((RNode)graph[x]).extension.Clone());
                        }
                        // else we simply update the set of solution by
                        // including the neighbours of the newly accepted node
                        else
                        {
                            newExtension = (System.Collections.BitArray)extension.Clone();
                            //UPGRADE_NOTE: In .NET BitArrays must be of the same size to allow the 'System.Collections.BitArray.Or' operation. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1083'"
                            newExtension.Or(((RNode)graph[x]).extension);
                        }

                        // extension my not contain forbidden nodes
                        newExtension.And(newForbidden.Not());

                        // create the new set of traversed node
                        // (update current partial solution)
                        // and add x to the set of forbidden node
                        // (a node may only appear once in a solution)
                        newTraversed = (System.Collections.BitArray)traversed.Clone();
                        SupportClass.BitArraySupport.Set(newTraversed, x);
                        SupportClass.BitArraySupport.Set(forbidden, x);

                        // parse recursively the RGraph
                        parseRec(newTraversed, newExtension, newForbidden);
                    }
                }
            }
        }
コード例 #8
0
        static void Main(string[] args)
        {
            #region https://youtu.be/_UtKEYYhi24
            Coleccion show = new Coleccion();
            System.Collections.BitArray bitArray =
                new System.Collections.BitArray(
                    new byte[] { 1, 2, 4, 8, 16 });// Convertiendo byte a bit

            CountElement.Count(bitArray);
            Coleccion.Show(bitArray, 2);

            //// Obtenemos un bit en particular
            System.Console.WriteLine(bitArray.Get(3));

            //// ponemos un bit en particular
            bitArray.Set(3, true);
            System.Console.WriteLine(bitArray.Get(3));
            Coleccion.Show(bitArray, 2);


            //https://youtu.be/pGS78ttnqfY

            // Clonacion del BitArray
            System.Collections.BitArray bitArray2 =
                (System.Collections.BitArray)bitArray.Clone();

            //// Invertir el Array, NOT
            bitArray2.Not();
            Coleccion.Show(bitArray2, 2);

            // Creando otro Array
            System.Collections.BitArray bitArray3 =
                new System.Collections.BitArray(new byte[] { 5, 7, 9, 13, 15 });
            Coleccion.Show(bitArray3, 2, "3°Array");

            //// Hacemos Or entre Arreglos
            bitArray3.Or(bitArray); // El resultado se guarda en el Array que llevo
                                    //acabo la invocacion.
            Coleccion.Show(bitArray, pNombre: "1°Array");
            Coleccion.Show(bitArray3, 3, pNombre: "Result");
            System.Console.WriteLine("=|||||||||=");

            //// Hacemos AND entre Array
            Coleccion.Show(bitArray, pNombre: "1°Array");
            Coleccion.Show(bitArray3, pNombre: "3°Array");

            // Hacemos el AND, BitArray 3 se modifica con el resultado
            bitArray3.And(bitArray);
            Coleccion.Show(bitArray3, 3, "Result");
            System.Console.WriteLine("=&&&&&&&&&&&=");

            //// Hamos XOR entre Array
            bitArray3 =
                new System.Collections.BitArray(new byte[] { 5, 7, 9, 13, 21 });
            Coleccion.Show(bitArray, pNombre: "1°Array");
            Coleccion.Show(bitArray3, pNombre: "3°Array");

            // Hacemos el XOR, Array 3 se modifica con el resultado
            bitArray3.Xor(bitArray);
            Coleccion.Show(bitArray3, pNombre: "Result");

            System.Console.ReadKey();
            #endregion
        }