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


C# BitArray.Get方法代码示例

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


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

示例1: ESieve

        public static int[] ESieve(int upperLimit)
        {
            int sieveBound = (int)(upperLimit - 1) / 2;
            int upperSqrt = ((int)Math.Sqrt(upperLimit) - 1) / 2;

            BitArray PrimeBits = new BitArray(sieveBound + 1, true);

            for (int i = 1; i <= upperSqrt; i++)
            {
                if (PrimeBits.Get(i))
                {
                    for (int j = i * 2 * (i + 1); j <= sieveBound; j += 2 * i + 1)
                    {
                        PrimeBits.Set(j, false);
                    }
                }
            }

            List<int> numbers = new List<int>((int)(upperLimit / (Math.Log(upperLimit) - 1.08366)));
            numbers.Add(2);

            for (int i = 1; i <= sieveBound; i++)
            {
                if (PrimeBits.Get(i))
                {
                    numbers.Add(2 * i + 1);
                }
            }

            return numbers.ToArray();
        }
开发者ID:dstites,项目名称:Project-Euler,代码行数:31,代码来源:Utilities.cs

示例2: CreateFrom

        /// <summary>
        /// Creates a RLEBitset from a BitArray.
        /// </summary>
        /// <param name="bits">a BitArray</param>
        /// <returns>an RLEBitset</returns>
        public static IBitset CreateFrom(BitArray bits)
        {
            RLEBitset rtnVal = new RLEBitset();
            rtnVal._Length = bits.Length;
            Run currRun = new Run();
            for (int i = 0; i < bits.Count; i++)
            {
                if (bits.Get(i) == true)
                {
                    currRun.StartIndex = i;
                    currRun.EndIndex = i;
                    for (int j = i + 1; j < bits.Count; j++)
                    {
                        if (bits.Get(j))
                        {
                            currRun.EndIndex = j;
                        }
                        else
                        {
                            break;
                        }
                    }
                    i = currRun.EndIndex; //move the counter to the end of the run we just found
                    rtnVal._RunArray.Add(currRun);
                    currRun = new Run();
                }

            }
            return rtnVal;
        }
开发者ID:scintillating7,项目名称:BitSetsNet,代码行数:35,代码来源:RLEBitset.cs

示例3: doGet

		void doGet(BitArray a, FixedBitSet b)
		{
			int max = b.Length();
			for (int i = 0; i < max; i++)
			{
				if (a.Get(i) != b.Get(i))
				{
					Assert.Fail("mismatch: BitSet=[" + i + "]=" + a.Get(i));
				}
			}
		}
开发者ID:synhershko,项目名称:lucene.net,代码行数:11,代码来源:TestFixedBitSet.cs

示例4: DoGet

 internal virtual void DoGet(BitArray a, LongBitSet b)
 {
     long max = b.Length();
     for (int i = 0; i < max; i++)
     {
         if (a.Get(i) != b.Get(i))
         {
             Assert.Fail("mismatch: BitSet=[" + i + "]=" + a.Get(i));
         }
     }
 }
开发者ID:paulirwin,项目名称:lucene.net,代码行数:11,代码来源:TestLongBitSet.cs

示例5: VisitSelect

		protected override Expression VisitSelect(SqlSelectExpression select)
		{
			var columnRemoved = false; 
			
			select = (SqlSelectExpression)base.VisitSelect(select);
			
			var columnsOrderedByName = select.Columns.OrderBy(c => c.Name).ToList();

			var removedColumns = new BitArray(select.Columns.Count);
			
			for (int i = 0, n = columnsOrderedByName.Count; i < n - 1; i++)
			{
				var icolumn = columnsOrderedByName[i];
				var iNewColumnExpression = new SqlColumnExpression(icolumn.Expression.Type, select.Alias, icolumn.Name);
				
				for (var j = i + 1; j < n; j++)
				{
					if (!removedColumns.Get(j))
					{
						var jcolumn = columnsOrderedByName[j];

						if (IsSameExpression(icolumn.Expression, jcolumn.Expression))
						{
							// 'j' references should now be a reference to 'i'

							var jNewColumnExpression = new SqlColumnExpression(jcolumn.Expression.Type, select.Alias, jcolumn.Name);
							this.visitedColumns.Add(jNewColumnExpression, iNewColumnExpression);

							removedColumns.Set(j, true);
							columnRemoved = true;
						}
					}
				}
			}

			if (columnRemoved)
			{
				var newColumnDeclarations = new List<SqlColumnDeclaration>();

				for (int i = 0, n = columnsOrderedByName.Count; i < n; i++)
				{
					if (!removedColumns.Get(i))
					{
						newColumnDeclarations.Add(columnsOrderedByName[i]);
					}
				}

				select = select.ChangeColumns(newColumnDeclarations);
			}

			return select;
		}
开发者ID:crazle,项目名称:Shaolinq,代码行数:52,代码来源:SqlRedundantColumnRemover.cs

示例6: BitArray2Byte

        public static byte[] BitArray2Byte(BitArray ba)
        {
            int len = (((ba.Count + 62) >> 6) << 6);
            byte[] b = new byte[len >> 3];

            for (int i = 1; i < ba.Length - 8; i += 8) {

                if (ba.Get(i)) b[i / 8] |= 0x80;
                if (ba.Get(i + 1)) b[i / 8] |= 0x40;
                if (ba.Get(i + 2)) b[i / 8] |= 0x20;
                if (ba.Get(i + 3)) b[i / 8] |= 0x10;
                if (ba.Get(i + 4)) b[i / 8] |= 0x8;
                if (ba.Get(i + 5)) b[i / 8] |= 0x4;
                if (ba.Get(i + 6)) b[i / 8] |= 0x2;
                if (ba.Get(i + 7)) b[i / 8] |= 0x1;

            }

            if (len > 64)
                    b[0] |= 0x80;
            if (len > 128)
                b[8] |= 0x80;

            return b;
        }
开发者ID:phucvinh,项目名称:iso4net,代码行数:25,代码来源:Utils.cs

示例7: ReduceVertices

        public void ReduceVertices(BitArray usedVerts)
        {
            if ((NumVertices() >= 4) && (!usedVerts.Get(3)))
                RemoveVertex(3);

            if ((NumVertices() >= 3) && (!usedVerts.Get(2)))
                RemoveVertex(2);

            if ((NumVertices() >= 2) && (!usedVerts.Get(1)))
                RemoveVertex(1);

            if ((NumVertices() >= 1) && (!usedVerts.Get(0)))
                RemoveVertex(0);
        }
开发者ID:bsamuels453,项目名称:BulletXNA,代码行数:14,代码来源:VoronoiSimplexSolver.cs

示例8: BitArray_SetAllTest

            public static void BitArray_SetAllTest()
            {
                BitArray ba2 = new BitArray(6, false);

                Assert.False(ba2.Get(0)); //"Err_10! Expected ba4.Get(0) to be false"
                Assert.False(ba2.Get(5)); //"Err_11! Expected ba4.Get(1) to be false"

                // false to true
                ba2.SetAll(true);

                Assert.True(ba2.Get(0)); //"Err_12! Expected ba4.Get(0) to be true"
                Assert.True(ba2.Get(5)); //"Err_13! Expected ba4.Get(1) to be true"


                // false to false
                ba2.SetAll(false);

                Assert.False(ba2.Get(0)); //"Err_14! Expected ba4.Get(0) to be false"
                Assert.False(ba2.Get(5)); //"Err_15! Expected ba4.Get(1) to be false"

                ba2 = new BitArray(6, true);

                Assert.True(ba2.Get(0)); //"Err_16! Expected ba4.Get(0) to be true"
                Assert.True(ba2.Get(5)); //"Err_17! Expected ba4.Get(1) to be true"

                // true to true
                ba2.SetAll(true);

                Assert.True(ba2.Get(0)); //"Err_18! Expected ba4.Get(0) to be true"
                Assert.True(ba2.Get(5)); //"Err_19! Expected ba4.Get(1) to be true"

                // true to false
                ba2.SetAll(false);

                Assert.False(ba2.Get(0)); //"Err_20! Expected ba4.Get(0) to be false"
                Assert.False(ba2.Get(5)); //"Err_21! Expected ba4.Get(1) to be false"

                // []  Size stress.
                int size = 0x1000F;
                ba2 = new BitArray(size, true);

                Assert.True(ba2.Get(0)); //"Err_22! Expected ba4.Get(0) to be true"
                Assert.True(ba2.Get(size - 1)); //"Err_23! Expected ba4.Get(size-1) to be true"

                ba2.SetAll(false);

                Assert.False(ba2.Get(0)); //"Err_24! Expected ba4.Get(0) to be false"
                Assert.False(ba2.Get(size - 1)); //"Err_25! Expected ba4.Get(size-1) to be false"
            }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:49,代码来源:BitArray_GetSetTests.cs

示例9: BitArray_SetTest

            public static void BitArray_SetTest()
            {
                // []  Set true to true, true to false
                // []  Set false to false and false to true is covered in BitArray_GetTest() above
                BitArray ba2 = new BitArray(6, true);

                ba2.Set(0, true);
                ba2.Set(1, false);
                ba2.Set(2, true);
                ba2.Set(5, true);

                Assert.True(ba2.Get(0)); //"Err_7! Expected ba4.Get(0) to be true"
                Assert.False(ba2.Get(1)); //"Err_8! Expected ba4.Get(1) to be false"
                Assert.True(ba2.Get(2)); //"Err_9! Expected ba4.Get(2) to be true"
            }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:15,代码来源:BitArray_GetSetTests.cs

示例10: Run

        //Runs the algoritm for number of iterations
        public override void Run(Configuration config)
        {
            log = new RandomLogSpecification(data.DataFileName, config.RandomSeed, config.NumberOfRuns, config.PenaltyCoefficient);
            solution = new SolutionSpecification();

            BitArray routerswitches = new BitArray((int)data.RouterCount);
            double highestfitness = 0.0;
            BitArray best = new BitArray((int)data.RouterCount);
            for(int i = 0; i < config.NumberOfRuns; i++)
            {
                routerswitches = new BitArray((int)data.RouterCount);
                int numbertoswitch = randomgenerator.Next((int)data.RouterCount);
                for(int j = 0; j < numbertoswitch; j++)
                {
                    int switching;
                    while(routerswitches.Get(switching = randomgenerator.Next((int)data.RouterCount)) == true);
                    routerswitches.Set(switching, true);
                }

                double fitness = FitnessEvaluation(data.NetworkPaths, routerswitches, numbertoswitch, config.PenaltyCoefficient);

                if(fitness > highestfitness)
                {
                    ((RandomLogSpecification)log).AddEvaluation(i, fitness);
                    highestfitness = fitness;
                    best = (BitArray)routerswitches.Clone();
                }
            }

            solution.RoutersTurnedOff = ExtensionMethods.ConvertBitArrayToOffRouterNumbers(best, data.HostCount);
        }
开发者ID:addiem7c5,项目名称:CS348,代码行数:32,代码来源:RandomSearch.cs

示例11: DoPrevSetBit

 internal virtual void DoPrevSetBit(BitArray a, LongBitSet b)
 {
     int aa = a.Count + Random().Next(100);
     long bb = aa;
     do
     {
         aa = a.PrevSetBit(aa-1);
         aa--;
         while ((aa >= 0) && (!a.Get(aa)))
         {
             aa--;
         }
         if (b.Length() == 0)
         {
             bb = -1;
         }
         else if (bb > b.Length() - 1)
         {
             bb = b.PrevSetBit(b.Length() - 1);
         }
         else if (bb < 1)
         {
             bb = -1;
         }
         else
         {
             bb = bb >= 1 ? b.PrevSetBit(bb - 1) : -1;
         }
         Assert.AreEqual(aa, bb);
     } while (aa >= 0);
 }
开发者ID:joyanta,项目名称:lucene.net,代码行数:31,代码来源:TestLongBitSet.cs

示例12: getUserData

        public String getUserData()
        {
            ReportService rs = new ReportService();
            String table = "";
            foreach (flight f in flight_list)
            {
                table += "<div class=\"hr hr-18 dotted hr-double\"></div><div class=\"flight\"><h1>" + f.flight_name ;
                table +="<small><i class=\"ace-icon fa fa-angle-double-right\"></i>乘客列表</small></h1>"
                    + "<div class=\"row\"><div class=\"col-xs-12\"><table id=\"simple-table\" class=\"table table-striped table-bordered table-hover\">"
                    +"<thead><tr><th>乘客姓名</th><th>机票等级</th><th class=\"hidden-480\">座位号</th><th>PNR</th>"
                    +"<th class=\"hidden-480\">特殊要求</th></tr></thead>";
                table += "<tbody>";
                List<order> orderList = rs.getOrderByFlightId(f.flight_id);

                foreach(order o in orderList)
                {
                    table += "<tr>";
                    table += "<td>" + o.user.user_name + "</td>";
                    table += "<td>" + o.type + "</td>";

                    BitArray seat = new BitArray(o.seat);
                    int seatNum = 0;
                    for (int i= 0; seatNum < seat.Length; i++ )
                    {
                        if (seat.Get(i) == true) seatNum = i;
                    }
                    table += "<td class=\"hidden-480\">"+ seatNum +"</td>";
                    table += "<td>" + o.PNR+ "</td>";
                    table += "<td class=\"hidden-480\">" + o.SSR + "</td></tr>";
                }
                table += "</tbody></table></div></div></div>";
            }
            return table;
        }
开发者ID:lao605,项目名称:FYXFlightSystem,代码行数:34,代码来源:tomorrow-flight.aspx.cs

示例13: SieveOfEratosthenes

        public long[] SieveOfEratosthenes()
        {
            var sieveBound = (_limit - 1) / 2;
            var upperSqrt = ((int)Math.Sqrt(_limit) - 1) / 2;

            var primeBits = new BitArray(sieveBound + 1, true);

            for (var i = 1; i <= upperSqrt; i++)
            {
                if (primeBits.Get(i))
                {
                    for (var j = i * 2 * (i + 1); j <= sieveBound; j += 2 * i + 1)
                    {
                        primeBits.Set(j, false);
                    }
                }
            }

            var capacity = (int)(_limit / (Math.Log(_limit) - 1.08366));
            var numbers = new List<long>(capacity) { 2 };
            for (var i = 1; i <= sieveBound; i++)
            {
                if (primeBits.Get(i))
                    numbers.Add(2 * i + 1);
            }

            return numbers.ToArray();
        }
开发者ID:wrparra,项目名称:ProjectEuler,代码行数:28,代码来源:PrimeNumbers.cs

示例14: GroupByGrid

        /// <summary>
        /// Extract Features from a depth mask using a grid based pool method.
        /// 
        /// The regions which have a pixel count greater than or equal to the threshold 
        ///     have a feature value of 1. All others are 0.
        /// </summary>
        /// <param name="depthMask">
        ///     The mask of the hand, where 1 represents a pixel which is part of the hand
        /// </param>
        /// <param name="sqrtRegions">
        ///     The square root of the number of regions to split into. This forces the grid to be a square.
        /// </param>
        /// <param name="regionWidth">The width (in pixels) of each region</param>
        /// <param name="regionThreshold">The threshold for whether a region is considered to be 1 or a 0 val</param>
        /// <returns>A feature array where each bit represents a specific region</returns>
        public static double[] GroupByGrid(BitArray depthMask, int sqrtRegions, int regionWidth, int regionThreshold)
        {
            // the number of features = number of regions
            int regions = sqrtRegions*sqrtRegions;
            int width = sqrtRegions*regionWidth;
            var feats = new double[regions];

            for (int i = 0; i < sqrtRegions; i++)
            {
                for (int j = 0; j < sqrtRegions; j++)
                {
                    int iStart = i * regionWidth;
                    int jStart = j * regionWidth;
                    int regionIndex = i * sqrtRegions + j;

                    // sum the number of hand pixels over the region
                    int sum = 0;
                    for (int x = 0; x < regionWidth; x++)
                        for (int y = 0; y < regionWidth; y++)
                            if (depthMask.Get((y + jStart) * width + (x + iStart)))
                                sum++;

                    // this feature is 1 iff number of hand pixels exceeds the threshold
                    feats[regionIndex] = sum < regionThreshold ? 0 : 1;
                }
            }

            return feats;
        }
开发者ID:smanoharan,项目名称:314Kinect,代码行数:44,代码来源:GridHandFeatureExtractor.cs

示例15: GetBits

        /// <summary>
        /// Get the bits from a Base32 encoded string.
        /// </summary>
        /// <param name="base32text">A Base32 encoded string to decode into a byte array.</param>
        /// <returns>An array of bits from the resulting byte array.</returns>
        public static BitArray GetBits(string base32text)
        {
            char[] input = base32text.ToLower().ToCharArray();

            /*
             * Base32 = 5 bits in a character
             * Length = number of characters * 5 bits per character
             */

            int bitsIn32 = 5;
            int resultsLength = input.Length * bitsIn32;

            // Use the length to create the resulting bits array
            BitArray results = new BitArray(resultsLength, false);

            int index = 0;

            for (int i = 0; i < input.Length; i++)
            {
                char c = input[i];
                int value = Array.IndexOf(encodingTable, c);
                if (value == -1) throw new ApplicationException("The Base32 encoded string contains invalid characters.");

                BitArray bits = new BitArray(new byte[] { Convert.ToByte(value) });

                for (int x = 0; x < bitsIn32; x++)
                {
                    results.Set(index, bits.Get(x));
                    index++;
                }
            }

            return results;
        }
开发者ID:SimWitty,项目名称:SimWitty,代码行数:39,代码来源:Base32.cs


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