private string ReadFromWriteResult(Domain.Writers.Dtos.MessageWriteResult writeResult) { string resultMessage = null; ushort byteThresholdBitCounter = 0; var bitArray = new System.Collections.BitArray(8); var messageRetrievedFromResultBuffer = new System.Collections.Generic.List <byte>(); for (int byteIndex = 0; byteIndex < writeResult.TotalNumberOfBytesUsed; byteIndex++) { var currentByte = writeResult.Buffer[byteIndex]; for (ushort bitInBytePositionCounter = 0; bitInBytePositionCounter < writeResult.NumberOfBitsUsedInByte; bitInBytePositionCounter++) { var bit = ((currentByte & (1 << bitInBytePositionCounter)) != 0); bitArray.Set(byteThresholdBitCounter, bit); byteThresholdBitCounter++; if (byteThresholdBitCounter == 8) { var byteStorage = new byte[1]; bitArray.CopyTo(byteStorage, 0); messageRetrievedFromResultBuffer.Add(byteStorage[0]); bitArray.SetAll(false); byteThresholdBitCounter = 0; } } } resultMessage = System.Text.Encoding.UTF8.GetString(messageRetrievedFromResultBuffer.ToArray()); return(resultMessage); }
public static void PerformanceTestBitArrays(Int32 length) { long before; System.Collections.BitArray bitArray = new System.Collections.BitArray(length); BetterBitArray betterBitArray = new BetterBitArray((UInt32)length); before = Stopwatch.GetTimestamp(); for (int i = 0; i < 10000; i++) { bitArray.SetAll(false); //bitArray.Set(0, true); } Console.WriteLine((Stopwatch.GetTimestamp() - before).StopwatchTicksAsInt64Milliseconds()); PrintGC("BitArray"); before = Stopwatch.GetTimestamp(); for (int i = 0; i < 10000; i++) { betterBitArray.SetAll(false); //betterBitArray.Assert(0); } Console.WriteLine((Stopwatch.GetTimestamp() - before).StopwatchTicksAsInt64Milliseconds()); PrintGC("BetterBitArray"); }
/// <summary> /// Sets all fields to empty /// </summary> public void ResetFields() { newNickname = string.Empty; newPassword = string.Empty; password = string.Empty; OnPropertyChanged(nameof(NewNickname)); OnPropertyChanged(nameof(NewPassword)); OnPropertyChanged(nameof(Password)); changedField.SetAll(false); }
static void Main(string[] args) { System.Collections.BitArray bits = new System.Collections.BitArray(900); // Setting all bits to 0 bits.SetAll(false); // Here Im setting 21st bit in array bits[21] = true; // etc... int[] nativeBits = new int[29]; // Packing your bits in int array bits.CopyTo(nativeBits, 0); // This prints 2097152. this is 2^21 Console.WriteLine("First element is:" + nativeBits[0].ToString()); }
public cMem() { contents = new T[capacity]; isVacant = new System.Collections.BitArray(capacity); isVacant.SetAll(true); isVacant[0] = false; count = 1; // vacancy management vacantSlots = new int[VACANT_MAX]; vacantTop = 0; isFragmented = false; isTooFragmented = false; }
public void Or_SetAll(int[] bits, bool value) { var size = 12; var array = CreateArray(size); var expected = new System.Collections.BitArray(size); foreach (var bit in bits) { array[bit] = expected[bit] = true; } array.SetAll(value); expected.SetAll(value); CollectionAssert.AreEqual(array, expected); Assert.AreEqual(expected.Count, array.Count); }
/// <summary> /// Check circular reference with ParentNo /// </summary> /// <returns>result</returns> internal bool CheckCircularReferencek() { var bundles = this._assetBundleData.assetbundles; System.Collections.BitArray bitarray = new System.Collections.BitArray(bundles.Count); for (int i = 0; i < bundles.Count; ++i) { bitarray.SetAll(false); int idx = i; while (0 <= bundles[idx].ParentNo) { if (bitarray.Get(idx)) { return(true); // circular... } bitarray.Set(idx, true); idx = bundles[idx].ParentNo; } } return(false); }
public void Clear() { members.SetAll(false); }
public void Reset() { _accelerators.SetAll(false); }
/// <summary> Reinitialisation of the TGraph.</summary> public virtual void clear() { graph.Clear(); graphBitSet.SetAll(false); }
public System.Collections.BitArray CollisionMask(int framenum) { EnsureUndisposed(); if (framenum >= frames.Count) return null; if (!separatemasks) framenum = 0; BoundingBox bb = GetBoundingBox(framenum); if (bb.Left > bb.Right || bb.Top > bb.Bottom) return null; bb.Normalize(); int w = bb.Right - bb.Left + 1; int h = bb.Bottom - bb.Top + 1; System.Collections.BitArray mask = new System.Collections.BitArray(w * h); switch (bbshape) { case BoundingBoxShape.Rectangle: // The mask is a rectangle. mask.SetAll(true); break; case BoundingBoxShape.Diamond: case BoundingBoxShape.Disk: // Use a lambda function for the shape: a disk or a diamond. Func<double, double, bool> ftn = bbshape == BoundingBoxShape.Disk ? (Func<double, double, bool>)((double x, double y) => (x * x + y * y < 1.0)) : (Func<double, double, bool>)((double x, double y) => (Math.Abs(x) + Math.Abs(y) < 1.0)); // Fill in the mask fitting the coordinates into the lambda function for the shape. //GM8 BETA1/2/RC1 incorrect version (off-by-one and excessive rounding): //int scalex = (bb.Right - bb.Left) >> 1; //int scaley = (bb.Bottom - bb.Top) >> 1; //for (int j = 0; j < h; j++) // for (int i = 0; i < w; i++) // mask[j * w + i] = ftn((double)(i - scalex) / (double)scalex, (double)(j - scaley) / (double)scaley); // correct code: double scalex = (double)(bb.Right - bb.Left + 1) * 0.5; double scaley = (double)(bb.Bottom - bb.Top + 1) * 0.5; for (int j = 0; j < h; j++) for (int i = 0; i < w; i++) mask[j * w + i] = ftn((double)(i - scalex) / scalex, (double)(j - scaley) / scaley); break; default: // Generate a mask based on alpha tolerance on each pixel. Bitmap b = frames[framenum]; BitmapData bd = b.LockBits(new Rectangle(bb.Left, bb.Top, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); for (int j = 0; j < h; j++) for (int i = 0; i < w; i++) mask[j * w + i] = (int)((uint)System.Runtime.InteropServices.Marshal.ReadInt32(bd.Scan0, (j + bb.Top) * bd.Stride + (i + bb.Left) * 4) >> 24) > tol; b.UnlockBits(bd); break; } return mask; }
public System.Collections.BitArray CollisionMask(int framenum) { EnsureUndisposed(); if (framenum >= frames.Count) { return(null); } if (!separatemasks) { framenum = 0; } BoundingBox bb = GetBoundingBox(framenum); if (bb.Left > bb.Right || bb.Top > bb.Bottom) { return(null); } bb.Normalize(); int w = bb.Right - bb.Left + 1; int h = bb.Bottom - bb.Top + 1; System.Collections.BitArray mask = new System.Collections.BitArray(w * h); switch (bbshape) { case BoundingBoxShape.Rectangle: // The mask is a rectangle. mask.SetAll(true); break; case BoundingBoxShape.Diamond: case BoundingBoxShape.Disk: // Use a lambda function for the shape: a disk or a diamond. Func <double, double, bool> ftn = bbshape == BoundingBoxShape.Disk ? (Func <double, double, bool>)((double x, double y) => (x * x + y * y < 1.0)) : (Func <double, double, bool>)((double x, double y) => (Math.Abs(x) + Math.Abs(y) < 1.0)); // Fill in the mask fitting the coordinates into the lambda function for the shape. //GM8 BETA1/2/RC1 incorrect version (off-by-one and excessive rounding): //int scalex = (bb.Right - bb.Left) >> 1; //int scaley = (bb.Bottom - bb.Top) >> 1; //for (int j = 0; j < h; j++) // for (int i = 0; i < w; i++) // mask[j * w + i] = ftn((double)(i - scalex) / (double)scalex, (double)(j - scaley) / (double)scaley); // correct code: double scalex = (double)(bb.Right - bb.Left + 1) * 0.5; double scaley = (double)(bb.Bottom - bb.Top + 1) * 0.5; for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { mask[j * w + i] = ftn((double)(i - scalex) / scalex, (double)(j - scaley) / scaley); } } break; default: // Generate a mask based on alpha tolerance on each pixel. Bitmap b = frames[framenum]; BitmapData bd = b.LockBits(new Rectangle(bb.Left, bb.Top, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { mask[j * w + i] = (int)((uint)System.Runtime.InteropServices.Marshal.ReadInt32(bd.Scan0, (j + bb.Top) * bd.Stride + (i + bb.Left) * 4) >> 24) > tol; } } b.UnlockBits(bd); break; } return(mask); }