/// <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; }
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(); }
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)); } } }
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)); } } }
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; }
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; }
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); }
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" }
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" }
public static string ToStringWithFormat(this byte[] bytes) { var sb = new StringBuilder(); var bits = new BitArray(bytes); //var bytes = _bits.ToByteArray(); sb.Append(String.Format("Bit count: {0}, byte count: {1}", bits.Length, bytes.Length)); sb.AppendLine().Append("Byte Frame: "); for (int i = 0; i < bytes.Length; i++) { sb.Append(bytes[i].ToString("X2")); } //sb.AppendLine(); sb.AppendLine().Append("Bits: "); for (int i = 0; i < bits.Length; i++) { sb.Append((bits.Get(i)) ? "1" : "0"); } return sb.ToString(); //return base.ToString(); }
void doPrevSetBit(BitArray a, FixedBitSet b) { int aa = a.Length + rnd.Next(100); int 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); }
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(); }
/// <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; }
/// <summary> /// 获取整数的位状态 /// </summary> /// <param name="data">传送过来的整数</param> /// <param name="bitNo">转换成二进制后,指定的第几位,0表示由右至左的最右边的第一位,范围为0-31</param> /// <returns>返回指定的位状态,true表示为1,false表示为0</returns> public static bool GetBit(int data, int bitNo) { int[] bta = new int[1]; bta[0] = data; System.Collections.BitArray myBA = new System.Collections.BitArray(bta); return(myBA.Get(bitNo)); }
/// <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; }
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; }
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); }
//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); }
/// <summary> /// Returns an array of primes up to upperLimit. /// </summary> /// <remarks>Efficient Sieve of Eratosthenes.</remarks> public static int[] Sieve(int lowerLimit, int upperLimit) { if (lowerLimit > upperLimit) { return new int[0]; } upperLimit = Math.Max(upperLimit, 1); int sieveBound = (int)(upperLimit - 1) / 2; int upperSqrt = ((int)Math.Sqrt(upperLimit) - 1) / 2; BitArray isPrime = new BitArray(sieveBound + 1, true); for (int i = 1, ii = 3, iii = 4; i <= upperSqrt; i++, ii += 2, iii += 4 * i) { if (isPrime.Get(i)) { for (int j = iii; j <= sieveBound; j += ii) { isPrime.Set(j, false); } } } List<int> primes = new List<int>(Math.Max(Math.Min((int)(upperLimit / (Math.Log(upperLimit) - 1.08366)), upperLimit), 10)); if (lowerLimit < 3 && upperLimit >= 2) { primes.Add(2); } if (lowerLimit < 3) { lowerLimit = 3; } for (int i = lowerLimit / 2, ii = 2 * i + 1; i <= sieveBound; i++, ii += 2) { if (isPrime.Get(i)) { primes.Add(ii); } } return primes.ToArray(); }
public long[] SieveOfAtkin() { var primeBits = new BitArray(_limit + 1, false); var upperSqrt = (int)Math.Sqrt(_limit); for (var i = 1; i <= upperSqrt; i++) { for (var j = 1; j <= upperSqrt; j++) { var n = 4 * i * i + j * j; if (n <= _limit && (n % 12 == 1 || n % 12 == 5)) primeBits.Set(n, !primeBits.Get(n)); n = 3 * i * i + j * j; if (n <= _limit && (n % 12 == 7)) primeBits.Set(n, !primeBits.Get(n)); n = 3 * i * i - j * j; if (i > j && n <= _limit && (n % 12 == 11)) primeBits.Set(n, !primeBits.Get(n)); } } for (var i = 5; i <= upperSqrt; i++) { if (primeBits.Get(i)) { for (var j = i * i; j <= _limit; j += i * i) { primeBits.Set(j, false); } } } var numbers = new List<long> {2, 3}; for (var i = 5; i <= _limit; i += 2) { if (primeBits.Get(i)) numbers.Add(i); } return numbers.ToArray(); }
public static void EachBit(this Type.BitArray instance, EachItemAction <bool> action) { int bitCount = instance.Length; for (int index = 0; index < bitCount; index++) { action(instance.Get(index), index); } }
protected override Expression VisitSelect(SelectExpression select) { select = (SelectExpression) base.VisitSelect(select); // look for redundant column declarations List<ColumnDeclaration> cols = select.Columns.OrderBy(c => c.Name).ToList(); BitArray removed = new BitArray(select.Columns.Count); bool anyRemoved = false; for (int i = 0, n = cols.Count; i < n - 1; i++) { ColumnDeclaration ci = cols[i]; ColumnExpression cix = ci.Expression as ColumnExpression; QueryType qt = cix != null ? cix.QueryType : ci.QueryType; ColumnExpression cxi = new ColumnExpression(ci.Expression.Type, qt, select.Alias, ci.Name); for (int j = i + 1; j < n; j++) { if (!removed.Get(j)) { ColumnDeclaration cj = cols[j]; if (SameExpression(ci.Expression, cj.Expression)) { // any reference to 'j' should now just be a reference to 'i' ColumnExpression cxj = new ColumnExpression(cj.Expression.Type, qt, select.Alias, cj.Name); this.map.Add(cxj, cxi); removed.Set(j, true); anyRemoved = true; } } } } if (anyRemoved) { List<ColumnDeclaration> newDecls = new List<ColumnDeclaration>(); for (int i = 0, n = cols.Count; i < n; i++) { if (!removed.Get(i)) { newDecls.Add(cols[i]); } } select = select.SetColumns(newDecls); } return select; }
private static void AddToBitArray(BitArray bitArray, int bitArrayIndex, byte byteData, int byteDataIndex, int length) { var localBitArray = new BitArray(new[] { byteData }); for (var i = byteDataIndex + length - 1; i >= byteDataIndex; i--) { bitArray.Set(bitArrayIndex, localBitArray.Get(i)); bitArrayIndex++; } }
public int[] ASieve(int upperLimit) { BitArray PrimeBits = new BitArray(upperLimit + 1, false); int upperSqrt = (int)Math.Sqrt(upperLimit); for (int i = 1; i <= upperSqrt; i++) { for (int j = 1; j <= upperSqrt; j++) { int n = 4 * i * i + j * j; if (n <= upperLimit && (n % 12 == 1 || n % 12 == 5)) { PrimeBits.Set(n, !PrimeBits.Get(n)); } n = 3 * i * i + j * j; if (n <= upperLimit && (n % 12 == 7)) { PrimeBits.Set(n, !PrimeBits.Get(n)); } n = 3 * i * i - j * j; if (i > j && n <= upperLimit && (n % 12 == 11)) { PrimeBits.Set(n, !PrimeBits.Get(n)); } } } for (int i = 5; i <= upperSqrt; i++) { if (PrimeBits.Get(i)) { for (int j = i * i; j <= upperLimit; j += i * i) { PrimeBits.Set((int)j, false); } } } List<int> numbers = new List<int>(); numbers.Add(2); numbers.Add(3); for (int i = 5; i <= upperLimit; i += 2) { if (PrimeBits.Get(i)) { numbers.Add(i); } } return numbers.ToArray(); }
public PulseOxReading(byte[] data) : this() { if (data.Length != 22) return; BitArray statusMSB = new BitArray(new byte[] { data[14] }); BitArray statusLSB = new BitArray(new byte[] { data[15] }); IsMissingData = statusMSB.Get(0); //no measurement of either HR or O2 IsReliable = statusMSB.Get(1); //reading uses Nonin's smart point algorithm DeviceLowBattery = statusLSB.Get(0); IsRealTime = statusLSB.Get(4); //as opposed to a reading from stored memory Timestamp = PacketUtil.ParseDateTimeAsBCDs(data.Skip(7).Take(6).ToArray<byte>()); SpO2 = data[19]; HeartRate = BitConverter.ToInt16(new byte[] {data[17], data[16]}, 0); }
public static byte[] ToggleBitInKey(byte[] buffer, Random random) { var bitArray = new BitArray(buffer); var bitToToggle = random.Next(buffer.Length*8); var bit = bitArray.Get(bitToToggle); bitArray.Set(bitToToggle, !bit); var result = new byte[buffer.Length]; bitArray.CopyTo(result, 0); return result; }
/// <summary> /// 根据给定的32位整数,返回这32位中每一位的状态值 /// </summary> /// <param name="data">指定32位整数</param> /// <returns>返回表示每一位状态信息的数组</returns> public static bool[] GetBit(int data) { bool[] stau = new bool[32]; int[] bta = new int[1]; bta[0] = data; System.Collections.BitArray myBA = new System.Collections.BitArray(bta); for (int i = 0; i < 32; i++) { stau[i] = myBA.Get(i); } return(stau); }
public int BitArray2Int(BitArray ba) { Int32 ret = 0; for (Int32 i = 0; i < ba.Length; i++) { if (ba.Get(i)) { ret |= (1 << i); } } return ret; }
public void Dump(BitArray bits) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.AppendFormat("FlowChecker ({0})", _scope is FunctionDefinition ? ((FunctionDefinition)_scope).Name : ""); sb.Append('{'); bool comma = false; foreach (var binding in _variables) { if (comma) sb.Append(", "); else comma = true; int index = 2 * binding.Value.Index; sb.AppendFormat("{0}:{1}{2}", binding.Key, bits.Get(index) ? "*" : "-", bits.Get(index + 1) ? "-" : "*"); if (binding.Value.ReadBeforeInitialized) sb.Append("#"); } sb.Append('}'); Debug.WriteLine(sb.ToString()); }
/// <summary> /// Implements Random Projection (RP) /// </summary> /// <performance> /// test 1 : "Hallo mein Name ist Max" -> 4191 /// test 2 : "ABC" -> 4126 /// </performance> /// <param name="n"> /// Not longer than 200 chars, RP performs best at 100-120 chars /// </param> /// <param name="ProjectionVector"> /// Needs to be constant and 160 Bit long /// </param> /// <returns></returns> public static byte[] RandomProjection(string n, BitArray ProjectionVector) { List<byte> input = new List<byte>(Encoding.UTF8.GetBytes(n.Trim(TrimPattern).ToLower())); while (input.Count < 200){ input.AddRange(new List<byte>(input.Take((200 - input.Count) > input.Count ? input.Count : (200 - input.Count)))); } BitArray arr = new BitArray(input.ToArray()); for(int i = 0; i < 160; ++i){ ProjectionVector.Set(i, (arr.Get(i * 10) ^ ProjectionVector.Get(i))); } byte[] output = new byte[20]; ProjectionVector.CopyTo(output, 0); return output; }
public static string GetLemma(string[] tokens, BitArray bits, string delimiter) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < tokens.Length; i++) { if (i != 0 && !bits.Get(i - 1)) { buf.Append(delimiter); } buf.Append(tokens[i]); } return buf.ToString(); }
protected override Expression VisitSelect(SelectExpression select) { select = (SelectExpression)base.VisitSelect(select); var fields = select.Fields.OrderBy(f => f.Name).ToList(); var removed = new BitArray(fields.Count); var anyRemoved = false; for (int i = 0, n = fields.Count; i < n; i++) { var fi = fields[i]; var fxi = new FieldExpression(fi.Expression, select.Alias, fi.Name); for (int j = i + 1; j < n; j++) { if (!removed.Get(i)) { FieldDeclaration fj = fields[j]; if (AreSameExpression(fi.Expression, fj.Expression)) { var fxj = new FieldExpression(fj.Expression, select.Alias, fj.Name); _map.Add(fxj, fxi); removed.Set(j, true); anyRemoved = true; } } } } if (anyRemoved) { var newFields = new List<FieldDeclaration>(); for (int i = 0, n = fields.Count; i < n; i++) { if (!removed.Get(i)) newFields.Add(fields[i]); } select = select.SetFields(newFields); } return select; }
public static bool IsEqual(this BitArray value, BitArray ba) { if (value.Length != ba.Length) return false; for (var i = 0; i < ba.Length; i++) { if (value.Get(i) != ba.Get(i)) return false; } return true; }
// Sieve ref: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes public void GeneratePrimesSieve() { isPrime = new System.Collections.BitArray(n + 1, true); for (int i = 3; i *i <= n; i += 2) { if (isPrime.Get(i)) { for (int j = i * i; j <= n; j += i) { isPrime.Set(j, false); } } } primes = new List <int>(new int[] { 2 }); for (int i = 3; i <= n; i += 2) { if (isPrime.Get(i)) { primes.Add(i); } } }
public object AggregateCount(int[] recordNos) { int count = 0; for (int i = 0; i < recordNos.Length; i++) { if (!_dbNullBits.Get(recordNos[i])) { count++; } } return(count); }
static public int Get(IntPtr l) { try { System.Collections.BitArray self = (System.Collections.BitArray)checkSelf(l); System.Int32 a1; checkType(l, 2, out a1); var ret = self.Get(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
/// <summary> /// /// </summary> /// <returns></returns> internal byte GetFaceType() { bool[] faceBits = new bool[] { Topology, FaceMaterial, FaceUVs, FaceVertexUVs, FaceNormals, VertexNormals, FaceColor, VertexColors }; System.Collections.BitArray bits = new System.Collections.BitArray(faceBits); byte b = 0; if (bits.Get(0)) { b++; } if (bits.Get(1)) { b += 2; } if (bits.Get(2)) { b += 4; } if (bits.Get(3)) { b += 8; } if (bits.Get(4)) { b += 16; } if (bits.Get(5)) { b += 32; } if (bits.Get(6)) { b += 64; } if (bits.Get(7)) { b += 128; } return(b); }