当前位置: 首页>>代码示例>>C#>>正文


C# BitArray.And方法代码示例

本文整理汇总了C#中System.Collections.BitArray.And方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.And方法的具体用法?C# BitArray.And怎么用?C# BitArray.And使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.BitArray的用法示例。


在下文中一共展示了BitArray.And方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BitArray_AndTest

            public static void BitArray_AndTest()
            {
                BitArray_Helper(Operator.And);

                // [] Test to make sure that 0 sized bit arrays can be And-ed

                BitArray b1 = new BitArray(0);
                BitArray b2 = new BitArray(0);

                b1.And(b2);
            }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:11,代码来源:BitArray_OperatorsTests.cs

示例2: BitArrayDemo

        static void BitArrayDemo()
        {
            var bits1 = new BitArray(8);
            bits1.SetAll(true);
            bits1.Set(1, false);
            bits1[5] = false;
            bits1[7] = false;
            Console.Write("initialized: ");
            DisplayBits(bits1);
            Console.WriteLine();

            DisplayBits(bits1);
            bits1.Not();
            Console.Write(" not ");
            DisplayBits(bits1);
            Console.WriteLine();

            var bits2 = new BitArray(bits1);
            bits2[0] = true;
            bits2[1] = false;
            bits2[4] = true;
            DisplayBits(bits1);
            Console.Write(" or ");
            DisplayBits(bits2);
            Console.Write(" : ");
            bits1.Or(bits2);
            DisplayBits(bits1);
            Console.WriteLine();

            DisplayBits(bits2);
            Console.Write(" and ");
            DisplayBits(bits1);
            Console.Write(" : ");
            bits2.And(bits1);
            DisplayBits(bits2);
            Console.WriteLine();

            DisplayBits(bits1);
            Console.Write(" xor ");
            DisplayBits(bits2);
            bits1.Xor(bits2);
            Console.Write(" : ");
            DisplayBits(bits1);
            Console.WriteLine();
        }
开发者ID:CSharpDev,项目名称:Csharp,代码行数:45,代码来源:Program.cs

示例3: Walk

        // WhileStmt
        public override bool Walk(WhileStatement node) {
            // Walk the expression
            node.Test.Walk(this);

            BitArray opte = node.ElseStatement != null ? new BitArray(_bits) : null;
            BitArray exit = new BitArray(_bits.Length, true);

            PushLoop(exit);
            node.Body.Walk(this);
            PopLoop();

            _bits.And(exit);

            if (node.ElseStatement != null) {
                // Flow the else
                BitArray save = _bits;
                _bits = opte;
                node.ElseStatement.Walk(this);
                // Restore the bits
                _bits = save;

                // Intersect
                _bits.And(opte);
            }

            return false;
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:28,代码来源:FlowChecker.cs

示例4: RunDataColumn

		void RunDataColumn(Report rpt, WorkClass wc, MatrixEntry rm, MatrixEntry cm, MatrixCellEntry[,] matrix, Rows _Data, int iRow, ref int iColumn, int level, int rowcell)
		{
			BitArray andData;
			MatrixRow mr = this.MatrixRows.Items[rowcell] as MatrixRow;
			float height = mr.Height == null? 0: mr.Height.Points;

			foreach (MatrixEntry ame in cm.GetSortedData(rpt))
			{
				if (ame.ColumnGroup != LastCg)
				{
					RunDataColumn(rpt, wc, rm, ame, matrix, _Data, iRow, ref iColumn, level+1, rowcell);
					continue;
				}
				andData = new BitArray(ame.Rows);	// copy the data
				andData.And(rm.Rows);				//  because And is destructive
				matrix[iRow, iColumn] = RunGetMatrixCell(rpt, ame, iRow, _Data, andData, 
						Math.Max(rm.FirstRow, ame.FirstRow),
						Math.Min(rm.LastRow, ame.LastRow));
				matrix[iRow, iColumn].Height = height;
				matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]);
				matrix[iRow, iColumn].ColumnME = ame;
				matrix[iRow, iColumn].RowME = rm;
				
				iColumn++;
			}
			// do we need to subtotal this?
			ColumnGrouping cg = (ColumnGrouping) (_ColumnGroupings.Items[level]);
			if (cg.DynamicColumns != null &&
				cg.DynamicColumns.Subtotal != null)
			{
				andData = new BitArray(cm.Rows);	// copy the data
				andData.And(rm.Rows);				//  because And is destructive
				for (int i=0; i < this.CountMatrixCells; i++)
				{
					matrix[iRow, iColumn] = RunGetMatrixCell(rpt, cm, rowcell, i, _Data, andData, 
						Math.Max(rm.FirstRow, cm.FirstRow),
						Math.Min(rm.LastRow, cm.LastRow));
					matrix[iRow, iColumn].Height = height;
					matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]);
					matrix[iRow, iColumn].ColumnME = cm;
					matrix[iRow, iColumn].RowME = rm;
					iColumn++;
				}
			}
		}
开发者ID:Elboodo,项目名称:My-FyiReporting,代码行数:45,代码来源:Matrix.cs

示例5: AndNot

 public static BitArray AndNot(BitArray b1, BitArray b2)
 {
     if (b1.Length > b2.Length)
     {
         b2.Length = b1.Length;
     }
     else if (b2.Length > b1.Length)
     {
         b1.Length = b2.Length;
     }
     b1.And(b2.Not());
     return b1;
 }
开发者ID:DONGChuan,项目名称:LGame,代码行数:13,代码来源:CollectionUtils.cs

示例6: MakeChild

        public Genome MakeChild(Genome other, BitArray mask)
        {
            BitArray leftCopy = new BitArray(this.genome);
            BitArray rightCopy = new BitArray(other.genome);
            BitArray maskCopy = new BitArray(mask);

            leftCopy.And(maskCopy);
            rightCopy.And(maskCopy.Not());

            //BitArray temp2 = new BitArray(right.And(mask.Not()));
            return new Genome(leftCopy.Or(rightCopy));
        }
开发者ID:KalerPorter,项目名称:genetic,代码行数:12,代码来源:Genetic.cs

示例7: MakeContabLeafList

        private ContingencyTableNode MakeContabLeafList(Varset variables, BitArray records)
        {
            Varset variablesCp = new Varset(variables);
            if (variablesCp.Equals(zero))
            {
                int count = 0;
                for (int i = 0; i < records.Count; i++)
                {
                    if (records[i])
                    {
                        count += 1;
                    }
                }
                return new ContingencyTableNode(count, 0, 1);
            }

            int firstIndex = variables.FindFirst();
            int cardinality = network.GetCardinality(firstIndex);
            ContingencyTableNode ct = new ContingencyTableNode(0, cardinality, 0);
            variablesCp.Set(firstIndex, false);
            Varset remainingVariables = new Varset(variablesCp);
            for (int k = 0; k < cardinality; k++)
            {
                BitArray r = new BitArray(recordCount);
                r = r.Or(records);
                r = r.And(consistentRecords[firstIndex][k]);

                int count = 0;
                for (int i = 0; i < r.Count; i++)
                {
                    if (r[i])
                    {
                        count += 1;
                    }
                }
                if (count > 0)
                {
                    ContingencyTableNode child = MakeContabLeafList(remainingVariables, r);
                    ct.SetChild(k, child);
                    ct.LeafCount += child.LeafCount;
                }
            }
            return ct;
        }
开发者ID:shskwmt,项目名称:UrlearningCS,代码行数:44,代码来源:AdTree.cs

示例8: AddClause

 internal virtual BitArray AddClause(BooleanQuery bq, BitArray result)
 {
     BitArray rnd = Sets[Random().Next(Sets.Length)];
     Query q = new ConstantScoreQuery(new FilterAnonymousInnerClassHelper(this, rnd));
     bq.Add(q, BooleanClause.Occur.MUST);
     if (Validate)
     {
         if (result == null)
         {
             result = (BitArray)rnd.Clone();
         }
         else
         {
             result = result.And(rnd);
         }
     }
     return result;
 }
开发者ID:paulirwin,项目名称:lucene.net,代码行数:18,代码来源:TestScorerPerf.cs

示例9: FinishAnalysis

 private Tuple<Type, Dictionary<string, int>> FinishAnalysis(bool scriptCmdlet = false)
 {
     List<Block> list = Block.GenerateReverseDepthFirstOrder(this._entryBlock);
     BitArray assignedBitArray = new BitArray(this._variables.Count);
     list[0]._visitData = assignedBitArray;
     this.AnalyzeBlock(assignedBitArray, list[0]);
     for (int i = 1; i < list.Count; i++)
     {
         Block block = list[i];
         assignedBitArray = new BitArray(this._variables.Count);
         assignedBitArray.SetAll(true);
         block._visitData = assignedBitArray;
         int num2 = 0;
         foreach (Block block2 in block._predecessors)
         {
             if (block2._visitData != null)
             {
                 num2++;
                 assignedBitArray.And((BitArray) block2._visitData);
             }
         }
         this.AnalyzeBlock(assignedBitArray, block);
     }
     var v = this._variables.Values.Where(x => x.LocalTupleIndex == -2).SelectMany(x => x.AssociatedAsts);
     foreach (Ast ast in v)
     {
         FixTupleIndex(ast, -2);
     }
     VariableAnalysisDetails[] detailsArray = (from details in this._variables.Values
         where details.LocalTupleIndex >= 0
         orderby details.LocalTupleIndex
         select details).ToArray<VariableAnalysisDetails>();
     Dictionary<string, int> dictionary = new Dictionary<string, int>(0, StringComparer.OrdinalIgnoreCase);
     for (int j = 0; j < detailsArray.Length; j++)
     {
         VariableAnalysisDetails details = detailsArray[j];
         string name = details.Name;
         dictionary.Add(name, j);
         if (details.LocalTupleIndex != j)
         {
             foreach (Ast ast2 in details.AssociatedAsts)
             {
                 FixTupleIndex(ast2, j);
             }
         }
     }
     return Tuple.Create<Type, Dictionary<string, int>>(MutableTuple.MakeTupleType((from l in detailsArray select l.Type).ToArray<Type>()), dictionary);
 }
开发者ID:nickchal,项目名称:pash,代码行数:48,代码来源:VariableAnalysis.cs

示例10: Walk

        // SwitchStatement
        protected internal override bool Walk(SwitchStatement node)
        {
            // The expression is evaluated always.
            // Then each case clause expression is evaluated until match is found.
            // Therefore, the effects of the case clause expressions accumulate.
            // Default clause is evaluated last (so all case clause expressions must
            // accumulate first)
            WalkNode(node.TestValue);

            // Flow all the cases, they all start with the same initial state
            int count;
            IList<SwitchCase> cases = node.Cases;
            if (cases != null && (count = cases.Count) > 0) {
                SwitchCase @default = null;
                // Save the initial state
                BitArray entry = _bits;
                // The state to progressively accumualte effects of the case clause expressions
                BitArray values = new BitArray(entry);
                // State to flow the case clause bodies.
                BitArray caseFlow = new BitArray(_bits.Length);
                // The state to accumulate results into
                BitArray result = new BitArray(_bits.Length, true);

                PushStatement(result);

                for (int i = 0; i < count; i++) {
                    if (cases[i].IsDefault) {
                        Debug.Assert(@default == null);

                        // postpone the default case
                        @default = cases[i];
                        continue;
                    }

                    // Set the state for the walking of the body
                    caseFlow.SetAll(false);
                    caseFlow.Or(values);

                    // Walk the body
                    _bits = caseFlow;
                    WalkNode(cases[i].Body);

                    // Accumulate the result into the overall case statement result.
                    result.And(caseFlow);
                }

                // Walk the default at the end.
                if (@default != null) {
                    // Initialize
                    caseFlow.SetAll(false);
                    caseFlow.Or(values);

                    // Walk the default body
                    _bits = caseFlow;
                    WalkNode(@default.Body);

                    // Accumulate.
                    result.And(caseFlow);

                    // If there's a default clause, exactly one case got executed.
                    // The final state is 'and' across all cases, stored in 'result'
                    entry.SetAll(false);
                    entry.Or(result);
                } else {
                    // In the absence of default clause, we may have executed case,
                    // but didn't have to, so the result is an 'and' between the cases
                    // and the initial state.
                    entry.And(result);
                }

                PopStatement();

                // Restore the original state.
                _bits = entry;
            }

            return false;
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:79,代码来源:FlowChecker.cs

示例11: FinishAnalysis

        private Tuple<Type, Dictionary<string, int>> FinishAnalysis(bool scriptCmdlet = false)
        {
            var blocks = Block.GenerateReverseDepthFirstOrder(_entryBlock);

            // The first block has no predecessors, so analyze outside the loop to "prime" the bitarray.
            var bitArray = new BitArray(_variables.Count);
            blocks[0]._visitData = bitArray;
            AnalyzeBlock(bitArray, blocks[0]);

            for (int index = 1; index < blocks.Count; index++)
            {
                var block = blocks[index];

                bitArray = new BitArray(_variables.Count);
                bitArray.SetAll(true);
                block._visitData = bitArray;

                int predCount = 0;
                foreach (var pred in block._predecessors)
                {
                    // VisitData can be null when the pred occurs because of a continue statement.
                    if (pred._visitData != null)
                    {
                        predCount += 1;
                        bitArray.And((BitArray)pred._visitData);
                    }
                }
                Diagnostics.Assert(predCount != 0, "If we didn't and anything, there is a flaw in the logic and incorrect code may be generated.");

                AnalyzeBlock(bitArray, block);
            }

            Diagnostics.Assert(_exitBlock._predecessors.All(p => p._unreachable || p._visitData is BitArray), "VisitData wasn't set on a reachable block");

            foreach (var details in _variables.Values)
            {
                if (details.LocalTupleIndex == ForceDynamic)
                {
                    foreach (var ast in details.AssociatedAsts)
                    {
                        FixTupleIndex(ast, ForceDynamic);
                        FixAssigned(ast, details);
                    }
                }
            }

            var orderedLocals = (from details in _variables.Values
                                 where (details.LocalTupleIndex >= 0 || (details.LocalTupleIndex == ForceDynamic && details.Automatic))
                                 orderby details.LocalTupleIndex
                                 select details).ToArray();

            Diagnostics.Assert(!_disableOptimizations
                || orderedLocals.Length == (int)AutomaticVariable.NumberOfAutomaticVariables +
                        (scriptCmdlet ? SpecialVariables.PreferenceVariables.Length : 0),
                "analysis is incorrectly allocating number of locals when optimizations are disabled.");

            var nameToIndexMap = new Dictionary<string, int>(0, StringComparer.OrdinalIgnoreCase);
            for (int i = 0; i < orderedLocals.Length; ++i)
            {
                var details = orderedLocals[i];
                var name = details.Name;
                nameToIndexMap.Add(name, i);

                if (details.LocalTupleIndex != i)
                {
                    foreach (var ast in details.AssociatedAsts)
                    {
                        FixTupleIndex(ast, i);
                    }
                }
                // Automatic variables assign the type directly, not relying on any analysis.  For
                // all other variables, we don't determine the type of the local until we're done
                // with the analysis.
                Diagnostics.Assert(details.Type != null, "Type should be resolved already");
            }

            var tupleType = MutableTuple.MakeTupleType((from l in orderedLocals select l.Type).ToArray());
            return Tuple.Create(tupleType, nameToIndexMap);
        }
开发者ID:40a,项目名称:PowerShell,代码行数:79,代码来源:VariableAnalysis.cs

示例12: UpdateEntrySet

		private bool UpdateEntrySet(BitArray entrySet, BitArray exitSet, BitArray useBeforeDef, BitArray notDef)
		{
			int card = entrySet.Cardinality();
			entrySet.Or(exitSet);
			entrySet.And(notDef);
			entrySet.Or(useBeforeDef);
			return entrySet.Cardinality() != card;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:8,代码来源:Block.cs

示例13: Discriminate

        /// <summary>
        /// Given discriminator values (ordinally aligned with DiscriminatorColumns), determines 
        /// the entity type to return. Throws a CommandExecutionException if the type is ambiguous.
        /// </summary>
        internal EntityType Discriminate(object[] discriminatorValues, int resultSetIndex)
        {
            FunctionImportStructuralTypeMappingKB resultMapping = this.GetResultMapping(resultSetIndex);
            Debug.Assert (resultMapping != null);

            // initialize matching types bit map
            BitArray typeCandidates = new BitArray(resultMapping.MappedEntityTypes.Count, true);

            foreach (var typeMapping in resultMapping.NormalizedEntityTypeMappings)
            {
                // check if this type mapping is matched
                bool matches = true;
                var columnConditions = typeMapping.ColumnConditions;
                for (int i = 0; i < columnConditions.Count; i++)
                {
                    if (null != columnConditions[i] && // this discriminator doesn't matter for the given condition
                        !columnConditions[i].ColumnValueMatchesCondition(discriminatorValues[i]))
                    {
                        matches = false;
                        break;
                    }
                }

                if (matches)
                {
                    // if the type condition is met, narrow the set of type candidates
                    typeCandidates = typeCandidates.And(typeMapping.ImpliedEntityTypes);
                }
                else
                {
                    // if the type condition fails, all implied types are eliminated
                    // (the type mapping fragment is a co-implication, so a type is no longer
                    // a candidate if any condition referring to it is false)
                    typeCandidates = typeCandidates.And(typeMapping.ComplementImpliedEntityTypes);
                }
            }

            // find matching type condition
            EntityType entityType = null;
            for (int i = 0; i < typeCandidates.Length; i++)
            {
                if (typeCandidates[i])
                {
                    if (null != entityType)
                    {
                        throw EntityUtil.CommandExecution(System.Data.Entity.Strings.ADP_InvalidDataReaderUnableToDetermineType);
                    }
                    entityType = resultMapping.MappedEntityTypes[i];
                }
            }

            // if there is no match, raise an exception
            if (null == entityType)
            {
                throw EntityUtil.CommandExecution(System.Data.Entity.Strings.ADP_InvalidDataReaderUnableToDetermineType);
            }

            return entityType;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:63,代码来源:FunctionImportMappingNonComposable.cs

示例14: Subtract

	public static void Subtract(BitArray a, BitArray b) { // a = a - b
		BitArray c = (BitArray) b.Clone();
		a.And(c.Not());
	}
开发者ID:ggrov,项目名称:tacny,代码行数:4,代码来源:Tab.cs

示例15: BitArray_Helper

            public static void BitArray_Helper(Operator op)
            {
                BitArray ba2 = null;
                BitArray ba3 = null;
                BitArray ba4 = null;

                // []  Standard cases (1,1) (1,0) (0,0).
                ba2 = new BitArray(6, false);
                ba3 = new BitArray(6, false);

                ba2.Set(0, true);
                ba2.Set(1, true);

                ba3.Set(1, true);
                ba3.Set(2, true);

                switch (op)
                {
                    case Operator.Xor:
                        ba4 = ba2.Xor(ba3);
                        Assert.True(ba4.Get(0)); //"Err_8! Expected ba4.Get(0) to be true"
                        Assert.False(ba4.Get(1)); //"Err_9! Expected ba4.Get(1) to be false"
                        Assert.True(ba4.Get(2)); //"Err_10! Expected ba4.Get(2) to be true"
                        Assert.False(ba4.Get(4)); //"Err_11! Expected ba4.Get(4) to be false"
                        break;

                    case Operator.And:
                        ba4 = ba2.And(ba3);
                        Assert.False(ba4.Get(0)); //"Err_12! Expected ba4.Get(0) to be false"
                        Assert.True(ba4.Get(1)); //"Err_13! Expected ba4.Get(1) to be true"
                        Assert.False(ba4.Get(2)); //"Err_14! Expected ba4.Get(2) to be false"
                        Assert.False(ba4.Get(4)); //"Err_15! Expected ba4.Get(4) to be false"
                        break;

                    case Operator.Or:
                        ba4 = ba2.Or(ba3);
                        Assert.True(ba4.Get(0)); //"Err_16! Expected ba4.Get(0) to be true"
                        Assert.True(ba4.Get(1)); //"Err_17! Expected ba4.Get(1) to be true"
                        Assert.True(ba4.Get(2)); //"Err_18! Expected ba4.Get(2) to be true"
                        Assert.False(ba4.Get(4)); //"Err_19! Expected ba4.Get(4) to be false"
                        break;
                }


                // []  Size stress cases.
                ba2 = new BitArray(0x1000F, false);
                ba3 = new BitArray(0x1000F, false);

                ba2.Set(0x10000, true); // The bit for 1 (2^0).
                ba2.Set(0x10001, true); // The bit for 2 (2^1).

                ba3.Set(0x10001, true); // The bit for 2 (2^1).

                switch (op)
                {
                    case Operator.Xor:
                        ba4 = ba2.Xor(ba3);
                        Assert.True(ba4.Get(0x10000)); //"Err_20! Expected ba4.Get(0x10000) to be true"
                        Assert.False(ba4.Get(0x10001)); //"Err_21! Expected ba4.Get(0x10001) to be false"
                        Assert.False(ba4.Get(0x10002)); //"Err_22! Expected ba4.Get(0x10002) to be false"
                        Assert.False(ba4.Get(0x10004)); //"Err_23! Expected ba4.Get(0x10004) to be false"
                        break;

                    case Operator.And:
                        ba4 = ba2.And(ba3);
                        Assert.False(ba4.Get(0x10000)); //"Err_24! Expected ba4.Get(0x10000) to be false"
                        Assert.True(ba4.Get(0x10001)); //"Err_25! Expected ba4.Get(0x10001) to be true"
                        Assert.False(ba4.Get(0x10002)); //"Err_26! Expected ba4.Get(0x10002) to be false"
                        Assert.False(ba4.Get(0x10004)); //"Err_27! Expected ba4.Get(0x10004) to be false"
                        break;

                    case Operator.Or:
                        ba4 = ba2.Or(ba3);
                        Assert.True(ba4.Get(0x10000)); //"Err_28! Expected ba4.Get(0x10000) to be true"
                        Assert.True(ba4.Get(0x10001)); //"Err_29! Expected ba4.Get(0x10001) to be true"
                        Assert.False(ba4.Get(0x10002)); //"Err_30! Expected ba4.Get(0x10002) to be false"
                        Assert.False(ba4.Get(0x10004)); //"Err_31! Expected ba4.Get(0x10004) to be false"
                        break;
                }
            }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:80,代码来源:BitArray_OperatorsTests.cs


注:本文中的System.Collections.BitArray.And方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。