コード例 #1
0
        public WorldState Clone()
        {
            WorldState copy = new WorldState(_bits.Count);

            copy._bits = (BitArray)_bits.Clone();
            return(copy);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Anil1111/Education
        static void Main(string[] args)
        {
            var bits1 = new BitArray(3)
            {
                [0] = true,
                [1] = true,
                [2] = true
            };

            var bits2 = new BitArray(3);

            bits2[0] = true;
            bits2[1] = false;
            bits2[2] = true;

            //Пришлось влепить так потому, что при выполнении операции, значение bits1 и bits2 меняется(ссылочный тип)

            var resultBits = (bits1.Clone() as BitArray)?.And(bits2.Clone() as BitArray);

            var resultBits2 = (bits1.Clone() as BitArray)?.Or(bits2.Clone() as BitArray);

            var resultBits3 = (bits1.Clone() as BitArray)?.Xor(bits2.Clone() as BitArray);

            var resultBits4 = (bits1.Clone() as BitArray).Not();

            foreach (var bit in resultBits)
            {
                Console.WriteLine(bit);
            }

            //Delay
            Console.ReadKey();
        }
コード例 #3
0
        private Tuple <List <BitArray>, List <BitArray>, BitArray> MergeGroup(List <BitArray> groupsByColor, List <BitArray> libertiesByColor, BitArray group, BitArray liberty)
        {
            var newGroups = new List <BitArray>();

            newGroups.Add((BitArray)group.Clone());
            var newLiberties = new List <BitArray>();

            newLiberties.Add((BitArray)liberty.Clone());
            var newStones = (BitArray)group.Clone();

            for (int i = 0; i < groupsByColor.Count; i++)
            {
                if (((BitArray)group.Clone()).And(libertiesByColor[i]).HasTrue())
                {
                    newGroups[0].Or(groupsByColor[i]);
                    newLiberties[0].Or(libertiesByColor[i]);
                }
                else
                {
                    newGroups.Add((BitArray)groupsByColor[i].Clone());
                    newLiberties.Add((BitArray)libertiesByColor[i].Clone());
                }
                newStones.Or(groupsByColor[i]);
            }
            newLiberties[0].XorTrue(newStones);
            return(new Tuple <List <BitArray>, List <BitArray>, BitArray>(newGroups, newLiberties, newStones));
        }
コード例 #4
0
        public static string ConvertToSecureTextString(string password)
        {
            var data          = System.Text.ASCIIEncoding.Default.GetBytes(password);
            var converted     = ConvertToBytes((aditionalEntropy.Clone() as BitArray).Xor(nr2));
            var protecteddata = ProtectedData.Protect(data, converted, DataProtectionScope.CurrentUser);

            return(System.Text.Encoding.Default.GetString(protecteddata));
        }
コード例 #5
0
        public WAHBitArray And(BitArray op)
        {
            CheckBitArray(op);

            BitArray b = (BitArray)_ba.Clone();

            return(new WAHBitArray(b.And(op)));
        }
コード例 #6
0
        // logical 'AND' or two bit sets (orginals are not modified)
        static BitArray And(BitArray a, BitArray b)
        {
            BitArray c = (BitArray)a.Clone();

            c.And(b);
            return(c);
        }
コード例 #7
0
        static void Main(string[] args)
        {
            //QUE SEAN MODIFICAR UN BIT A LA VEZ
            byte[] vectorAingresar = new byte[] { 1, 2, 4, 8, 16 };

            BitArray array = new BitArray(vectorAingresar);

            //los bytes se estan conviertiendo en bits
            Console.WriteLine(array.Count);
            Muestra(array);
            Console.WriteLine(array.Get(0));
            Console.WriteLine(array.Get(3));
            array.Set(3, true);  /*indice y el segundo es el valor a colocar*/
            array.Set(4, false); /*indice y el segundo es el valor a colocar*/
            Muestra(array);


            BitArray clon = (BitArray)array.Clone();

            Muestra(clon);
            clon.Not();
            Muestra(clon);

            array.Or(clon);
            Muestra(array);

            clon.And(array);
            Muestra(clon);

            array.Xor(clon);
            Muestra(array);
            Console.ReadKey();
        }
コード例 #8
0
ファイル: Node.cs プロジェクト: jeongmincha/Decision-Tree
 public Node(BitArray parentAvailAttrs)
 {
     attrCount      = Globals.attrCount;
     availableAttrs = (BitArray)parentAvailAttrs.Clone();                // !!
     tuples         = new List <Tuple>();
     childNodes     = new List <Node>();
 }
コード例 #9
0
        BitArray DerivationsOf(BitArray s0)
        {
            BitArray s    = (BitArray)s0.Clone();
            bool     done = false;

            while (!done)
            {
                done = true;
                foreach (Symbol sym in tab.terminals)
                {
                    if (s[sym.n])
                    {
                        foreach (Symbol baseSym in tab.terminals)
                        {
                            if (baseSym.inherits == sym && !s[baseSym.n])
                            {
                                s[baseSym.n] = true;
                                done         = false;
                            }
                        }
                    }
                }
            }
            return(s);
        }
コード例 #10
0
ファイル: UseSetCollector.cs プロジェクト: liyistc/symdiff
        public void Propagate()
        {
            this.callGraph = CallGraphHelper.ComputeCallGraph(program);
            Queue <Procedure> workQueue = new Queue <Procedure>(this.ProcedureToUseSet.Keys.Where(key => this.callGraph.Nodes.Contains(key)));

            while (workQueue.Count > 0)
            {
                Procedure current = workQueue.Dequeue();
                BitArray  useSet  = this.ProcedureToUseSet[current];
                BitArray  copy    = useSet.Clone() as BitArray;
                Debug.Assert(copy != null);
                bool changed = false;
                foreach (var suc in this.callGraph.Successors(current))
                {
                    useSet.Or(this.ProcedureToUseSet[suc]);
                }
                if (!this.BitArrayEquals(copy, useSet))
                {
                    changed = true;
                }

                if (changed)
                {
                    foreach (var pred in this.callGraph.Predecessors(current))
                    {
                        if (!workQueue.Contains(pred) && !pred.Equals(current))
                        {
                            workQueue.Enqueue(pred);
                        }
                    }
                }
            }
        }
コード例 #11
0
ファイル: BitMatrix.cs プロジェクト: roddickchen/NCDK
        /// <summary>
        /// Utility method xors the vectors <paramref name="u"/> and <paramref name="v"/>. Neither
        /// input is modified.
        /// </summary>
        /// <param name="u">a bit set</param>
        /// <param name="v">a bit set</param>
        /// <returns>the 'xor' of <paramref name="u"/> and <paramref name="v"/></returns>
        internal static BitArray Xor(BitArray u, BitArray v)
        {
            BitArray w = (BitArray)u.Clone();

            w.Xor(v);
            return(w);
        }
コード例 #12
0
        private double Part1(int[][] bitsArray)
        {
            int[] sumColumns = new int[bitsArray[0].Length];
            foreach (var bitWord in bitsArray)
            {
                for (int i = 0; i < bitWord.Length; i++)
                {
                    sumColumns[i] += bitWord[i] == 1 ? 1 : -1;
                }
            }

            bool[] bits = new bool[bitsArray[0].Length];

            for (int i = 0; i < bits.Length; i++)
            {
                bits[i] = sumColumns[i] > 0 ? true : false;
            }

            var bitArray         = new BitArray(bits);
            var firstValue       = ConvertBitToInt(bitArray);
            var invertedBitArray = (BitArray)bitArray.Clone();

            invertedBitArray.Not();
            var secondValue = ConvertBitToInt(invertedBitArray);

            return(firstValue * secondValue);
        }
コード例 #13
0
        /// <summary>
        /// This lists all bits set in bs2 and not in bs2 (other way round not considered) in a list and to logger.
        /// See. <see cref="Differences(BitArray, BitArray)"/> for a method to list all differences,
        /// including those missing present in bs2 but not bs1.
        /// </summary>
        /// <param name="bs1">First bitset</param>
        /// <param name="bs2">Second bitset</param>
        /// <returns>An arrayList of Integers</returns>
        /// <seealso cref="Differences(BitArray, BitArray)"/>
        public static IReadOnlyList <int> ListDifferences(BitArray bs1, BitArray bs2)
        {
            var u   = (BitArray)bs1.Clone();
            var v   = (BitArray)bs2.Clone();
            var len = Math.Max(u.Length, v.Length);

            if (u.Length < len)
            {
                u.Length = len;
            }
            if (v.Length < len)
            {
                v.Length = len;
            }

            var l = new List <int>();

            Debug.WriteLine("Listing bit positions set in bs2 but not in bs1");
            for (int f = 0; f < v.Count; f++)
            {
                if (v[f] && !u[f])
                {
                    l.Add(f);
                    Debug.WriteLine("Bit " + f + " not set in bs1");
                }
            }
            return(l);
        }
コード例 #14
0
ファイル: BitPlane.cs プロジェクト: momoewang/igoenchi
        public BitPlane Copy()
        {
            var bitPlaneCopy = new BitPlane(Width, Height);

            bitPlaneCopy.bitArray = bitArray.Clone() as BitArray;
            return(bitPlaneCopy);
        }
コード例 #15
0
        /// <summary>
        /// Inverts the bloomfilter.
        /// </summary>
        /// <returns></returns>
        public SimpleBloomFilter <Number160> Not()
        {
            var copy = (BitArray)BitArray.Clone();

            copy.Flip(0, copy.Length);
            return(new SimpleBloomFilter <Number160>(_byteArraySize, ExpectedElements, copy));
        }
コード例 #16
0
        /// <summary>and <paramref name="s"/> and <paramref name="t"/> without modifying <paramref name="s"/></summary>
        private static BitArray And(BitArray s, BitArray t)
        {
            BitArray u = (BitArray)s.Clone();

            u.And(t);
            return(u);
        }
コード例 #17
0
        public static void Clone_LongLength_Works()
        {
            BitArray bitArray = new BitArray(int.MaxValue - 30);
            BitArray clone    = (BitArray)bitArray.Clone();

            Assert.Equal(bitArray.Length, clone.Length);
        }
コード例 #18
0
        /// <summary>
        /// tests equivalence by XORing and checking for 1s.  XOR returns true if 2 bits differ
        /// </summary>
        /// <param name="ba1"></param>
        /// <param name="ba2"></param>
        /// <returns></returns>
        public static bool AreEquivalent_XORCompare(this BitArray ba1, BitArray ba2)
        {
            //null check
            if (ba1 == null)
            {
                if (ba2 == null)
                {
                    return(true);
                }

                return(false);
            }
            if (ba2 == null)
            {
                return(false);
            }

            //do an XOR.  if any 1s appear we have a mismatch
            BitArray clone = ba1.Clone() as BitArray;//we have to clone because the BitArray.Xor() implementation changes instance state of the BitArray
            BitArray check = clone.Xor(ba2);

            foreach (bool each in check)
            {
                if (each)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #19
0
        public static bool AreEquivalent_ANDCompare(this BitArray ba1, BitArray ba2)
        {
            //null check
            if (ba1 == null)
            {
                if (ba2 == null)
                {
                    return(true);
                }

                return(false);
            }
            if (ba2 == null)
            {
                return(false);
            }

            //do an AND.  if not same as AND arg, not the same
            BitArray clone = ba1.Clone() as BitArray;//we have to clone because the BitArray.And() implementation changes instance state of the BitArray
            BitArray check = clone.And(ba2);

            for (int i = 0; i < check.Length; i++)
            {
                if (!check[i].Equals(ba2[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #20
0
        private void RecalculateLiberty(BitArray capturedStones)
        {
            var captureLiberty = new BitArray(Size2);

            for (int j = 0; j < capturedStones.Length; j++)
            {
                if (capturedStones[j])
                {
                    captureLiberty.Or(GetLiberty(j));
                }
            }
            for (int c = 0; c < 2; c++)
            {
                for (int i = 0; i < groups[c].Count; i++)
                {
                    if (((BitArray)groups[c][i].Clone()).And(captureLiberty).HasTrue())
                    {
                        var newLiberty = new BitArray(Size2);
                        for (int j = 0; j < groups[c][i].Length; j++)
                        {
                            if (groups[c][i][j])
                            {
                                newLiberty.Or(GetLiberty(j));
                            }
                        }
                        newLiberty.XorTrue(stones[1 - c]);
                        newLiberty.XorTrue(stones[c]);
                        liberties[c][i] = (BitArray)newLiberty.Clone();
                    }
                }
            }
        }
コード例 #21
0
        /// <summary>
        /// List all differences between the two bit vectors. Unlike
        /// <see cref="ListDifferences(BitArray, BitArray)"/> which only list
        /// those which are set in <paramref name="s"/> but not in <paramref name="t"/>.
        /// </summary>
        /// <param name="s">a bit vector</param>
        /// <param name="t">another bit vector</param>
        /// <returns>all differences between <paramref name="s"/> and <paramref name="t"/></returns>
        public static IReadOnlyCollection <int> Differences(BitArray s, BitArray t)
        {
            var u   = (BitArray)s.Clone();
            var v   = (BitArray)t.Clone();
            var len = Math.Max(u.Length, v.Length);

            if (u.Length < len)
            {
                u.Length = len;
            }
            if (v.Length < len)
            {
                v.Length = len;
            }
            u.Xor(v);

            var differences = new SortedSet <int>();

            for (int i = BitArrays.NextSetBit(u, 0); i >= 0; i = BitArrays.NextSetBit(u, i + 1))
            {
                differences.Add(i);
            }

            return(differences);
        }
コード例 #22
0
ファイル: BitArrays.cs プロジェクト: roddickchen/NCDK
        public static void AndNot(BitArray a, BitArray set)
        {
            var b = (BitArray)set.Clone();

            b.Length = a.Length;
            a.And(b.Not());
        }
コード例 #23
0
ファイル: KeyState.cs プロジェクト: 7Bpencil/sharpPhysics
 public void Update(Vector2 newMousePosition)
 {
     previousKeys          = (BitArray)currentKeys.Clone();
     previousMouseButtons  = (BitArray)currentMouseButtons.Clone();
     previousMousePosition = currentMousePosition;
     currentMousePosition  = newMousePosition;
 }
コード例 #24
0
        public int AgreeOn(TinyFingerprintSchema other)
        {
            BitArray copy   = (BitArray)bitArray.Clone();
            var      result = copy.And(other.bitArray);

            return(TrueCounts(result));
        }
コード例 #25
0
        public void testClone()
        {
            BitArray array = new BitArray(32);
            var      clone = (BitArray)array.Clone();

            clone[0] = true;
            Assert.IsFalse(array[0]);
        }
コード例 #26
0
        public static BitArray XNOR(BitArray arr1, BitArray arr2)
        {
            //AND operation
            var arr1Clone = (BitArray)arr1.Clone();
            var arr2Clone = (BitArray)arr2.Clone();

            var arr3 = (BitArray)arr1.Clone();

            arr3.And(arr2);

            //NOR operation
            arr1Clone = arr1Clone.Not().And(arr2Clone.Not());

            //XNOR output
            arr1Clone.Or(arr3);
            return(arr1Clone);
        }
コード例 #27
0
            static BitArray Union(BitArray s, BitArray t, int x)
            {
                BitArray u = (BitArray)s.Clone();

                u.Or(t);
                u.Set(x, true);
                return(u);
            }
コード例 #28
0
	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strLoc = "Loc_000oo";
		BitArray bitArr1;
		BitArray bitArr2;
		Boolean[] bolArr1;
		Int32 iNumOfElements;
		Random rnd1;
		try {
			do
			{
				iNumOfElements = 10;
				rnd1 = new Random();
				strLoc = "Loc_742dsf!";
				iCountTestcases++;
				bolArr1 = new Boolean[iNumOfElements];
				for(int i=0; i<iNumOfElements; i++){
					if(rnd1.Next(10)>5)
						bolArr1[i] = true;
					else
						bolArr1[i] = false;
				}
				bitArr1 = new BitArray(bolArr1);
				bitArr2 = (BitArray)bitArr1.Clone();
				for(int i=0; i<iNumOfElements; i++){
					if(bitArr1[i] != bitArr2[i]){
						iCountErrors++;
						Console.WriteLine("Err_36tdfg_" + i + "! Wrong value returned, ");
					}
				}
				iCountTestcases++;
				for(int i=0; i<iNumOfElements; i++)
					bitArr1[i] = !bitArr1[i];
				for(int i=0; i<iNumOfElements; i++){
					if(bitArr1[i] != !bitArr2[i]){
						iCountErrors++;
						Console.WriteLine("Err_394t7sg_" + i + "! Wrong value returned, ");
					}
				}
			} while (false);
			} catch (Exception exc_general ) {
			++iCountErrors;
			Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
		}
		if ( iCountErrors == 0 )
		{
			Console.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
			return true;
		}
		else
		{
			Console.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
			return false;
		}
	}
コード例 #29
0
        public List <IPRange> GetSmallerRanges(int prefix)
        {
            if (prefix < Prefix)
            {
                throw new ArgumentException("Prefix should be bigger then original IPRange prefix");
            }

            if (prefix == Prefix)
            {
                return(new List <IPRange>()
                {
                    new IPRange()
                    {
                        Prefix = this.Prefix, Bits = (BitArray)this.Bits.Clone()
                    }
                });
            }

            List <IPRange> ipRangeList = new List <IPRange>();
            int            Count       = 1;

            Count <<= (prefix - Prefix); // 25 - 24

            BitArray BitsClone = new BitArray(32);

            BitsClone = (BitArray)Bits.Clone();

            for (int i = 0; i <= 31 - Prefix; i++)
            {
                BitsClone.Set(i, false);
            }

            for (int i = 0; i < Count; i++)
            {
                IPRange ipRange = new IPRange();
                ipRange.Prefix = prefix;
                ipRange.Bits   = (BitArray)BitsClone.Clone();

                byte[] ipBytes = new byte[4];
                BitsClone.CopyTo(ipBytes, 0);
                var ipAddress = new IPAddress(ipBytes.Reverse().ToArray());

                ipRange.BaseAddress = ipAddress.ToString();

                ipRangeList.Add(ipRange);

                for (int idx = 31 - prefix + 1; idx < 31 - Prefix + 1; idx++)
                {
                    BitsClone[idx] ^= true;
                    if (BitsClone[idx])
                    {
                        break;
                    }
                }
            }

            return(ipRangeList);
        }
コード例 #30
0
        protected void ComputeLocalLiveSets()
        {
            var liveSetTrace = CreateTraceLog("ComputeLocalLiveSets");

            foreach (var block in ExtendedBlocks)
            {
                var liveGen  = new BitArray(IndexCount, false);
                var liveKill = new BitArray(IndexCount, false);

                if (BasicBlocks.HeadBlocks.Contains(block.BasicBlock))
                {
                    for (int s = 0; s < IndexCount; s++)
                    {
                        liveKill.Set(s, true);
                    }
                }

                for (var node = block.BasicBlock.First; !node.IsBlockEndInstruction; node = node.Next)
                {
                    if (node.IsEmpty)
                    {
                        continue;
                    }

                    foreach (var index in Environment.GetInputs(node))
                    {
                        if (!liveKill.Get(index))
                        {
                            liveGen.Set(index, true);
                        }
                    }

                    foreach (var index in Environment.GetKills(node))
                    {
                        liveKill.Set(index, true);
                    }

                    foreach (var index in Environment.GetOutputs(node))
                    {
                        liveKill.Set(index, true);
                    }
                }

                block.LiveGen     = liveGen;
                block.LiveKill    = liveKill;
                block.LiveKillNot = ((BitArray)liveKill.Clone()).Not();

                if (liveSetTrace.Active)
                {
                    liveSetTrace.Log("Block #  " + block.BasicBlock.Sequence.ToString());
                    liveSetTrace.Log("GEN:     " + block.LiveGen.ToString2());
                    liveSetTrace.Log("KILL:    " + block.LiveKill.ToString2());
                    liveSetTrace.Log("KILLNOT: " + block.LiveKillNot.ToString2());
                    liveSetTrace.Log(string.Empty);
                }
            }
        }
コード例 #31
0
        public static void Ctor_Simple_Method_Tests()
        {
            int      length   = 0;
            BitArray bitArray = new BitArray(length);

            Assert.NotNull(bitArray.SyncRoot);
            Assert.False(bitArray.IsSynchronized);
            Assert.False(bitArray.IsReadOnly);
            Assert.Equal(bitArray, bitArray.Clone());
        }
コード例 #32
0
        public static void Ctor_Simple_Method_Tests()
        {
            int length = 0;
            BitArray bitArray = new BitArray(length);

            Assert.NotNull(bitArray.SyncRoot);
            Assert.False(bitArray.IsSynchronized);
            Assert.False(bitArray.IsReadOnly);
            Assert.Equal(bitArray, bitArray.Clone());
        }