public void TestGetBytes() { var vector = new BitVector(7); Assert.AreEqual(1, vector.Bytes.Length); vector = new BitVector(8); Assert.AreEqual(2, vector.Bytes.Length); }
public static void Main(string[] args) { if (args.Length != 2) { Console.Error.WriteLine("Usage: SHS.SCC1 <leader> <store>"); } else { var sw = Stopwatch.StartNew(); var store = new Service(args[0]).OpenStore(Guid.Parse(args[1])); long numUids = store.NumUrls(); var bv = new BitVector(numUids); // All false at creation var stk = new LongStack(1 << 23, "scc"); foreach (long u in store.Uids()) { if (!bv[store.UidToLid(u)]) { Frame frame = new Frame(null, u, store, Dir.Fwd, bv); while (frame != null) { while (frame.linkPos < frame.links.Length) { long v = frame.links[frame.linkPos++]; if (!bv[store.UidToLid(v)]) { frame = new Frame(frame, v, store, Dir.Fwd, bv); } } stk.Push(frame.uid); frame = frame.parent; } } } using (var sccWr = new BinaryWriter(new BufferedStream(new FileStream("scc-main.bin", FileMode.Create, FileAccess.Write)))) { using (var idxWr = new BinaryWriter(new BufferedStream(new FileStream("scc-index.bin", FileMode.Create, FileAccess.Write)))) { long numSCCs = 0; long sccPos = 0; bv.SetAll(false); for (long i = 0; i < numUids; i++) { long u = stk.Pop(); if (!bv[store.UidToLid(u)]) { numSCCs++; long sccSize = 0; Frame frame = new Frame(null, u, store, Dir.Bwd, bv); while (frame != null) { while (frame.linkPos < frame.links.Length) { long v = frame.links[frame.linkPos++]; if (!bv[store.UidToLid(v)]) { frame = new Frame(frame, v, store, Dir.Bwd, bv); } } sccWr.Write(frame.uid); sccSize++; frame = frame.parent; } idxWr.Write(sccSize); idxWr.Write(sccPos); sccPos += sccSize; } } } } store.Close(); Console.WriteLine("Done. Job took {0} seconds.", 0.001 * sw.ElapsedMilliseconds); } }
public void TestEquals() { var expected = new BitVector(new byte[] {0xf0}); var actual = new BitVector(7); actual.Set(0); actual.Set(1); actual.Set(2); Assert.AreEqual(expected, actual); }
private void ReplayReads(ref BitVector reads, SyntaxNode syntax) { // Start at slot 1 (slot 0 just indicates reachability) for (int slot = 1; slot < reads.Capacity; slot++) { if (reads[slot]) { var symbol = variableBySlot[slot].Symbol; CheckAssigned(symbol, syntax, slot); } } }
public void TestIsSet() { var vector = new BitVector(7); Assert.IsFalse(vector.IsSet(1)); vector.Set(1); Assert.IsTrue(vector.IsSet(1)); Assert.IsFalse(vector.IsSet(6)); vector.Set(6); Assert.IsTrue(vector.IsSet(6)); Assert.IsFalse(vector.IsSet(7)); Assert.IsFalse(vector.IsSet(8)); }
public void TestGetTruncatedBytes() { var vector = new BitVector(new byte[] {0x00, 0x00}); Assert.IsTrue(vector.IsOverlong); Assert.AreEqual(new byte[] {0x80}, vector.TruncatedBytes); vector = new BitVector(new byte[] {0x00}); Assert.IsFalse(vector.IsOverlong); Assert.AreEqual(new byte[] {0x80}, vector.TruncatedBytes); vector = new BitVector(new byte[] {0x60, 0x00, 0x04, 0x00}); Assert.IsTrue(vector.IsOverlong); Assert.AreEqual(new byte[] {0x60, 0x00, 0x84}, vector.TruncatedBytes); }
public SynthesizedDelegateSymbol( NamespaceOrTypeSymbol containingSymbol, string name, TypeSymbol objectType, TypeSymbol intPtrType, TypeSymbol voidReturnTypeOpt, int parameterCount, BitVector byRefParameters) : base(name, parameterCount, returnsVoid: (object)voidReturnTypeOpt != null) { _containingSymbol = containingSymbol; _constructor = new DelegateConstructor(this, objectType, intPtrType); _invoke = new InvokeMethod(this, byRefParameters, voidReturnTypeOpt); }
public void BitVector_Set_Test() { BitVector bArray = new BitVector(); bool[] sArray = new bool[32]; Random random = new Random(15); for(int i = 0; i < sArray.Length; i++) { sArray[i] = random.Next(0, 2) == 1; bArray[i] = sArray[i]; } for(int i = 0; i < sArray.Length; i++) { Assert.AreEqual(sArray[i], bArray[i]); } }
public void TestIndexInt32() { using (var validDocsBitmap = new BitVector(Pool)) { validDocsBitmap.EnsureCapacity(4); validDocsBitmap.ChangeAll(true); using (var data = new ColumnData<int>(DbType.Int32, Pool)) { data.EnsureCapacity(4); data.DataArray.GetBlock(0)[0] = 1; data.DataArray.GetBlock(0)[1] = 3; data.DataArray.GetBlock(0)[2] = -1; data.DataArray.GetBlock(0)[3] = 555; data.NotNulls.Set(0); data.NotNulls.Set(1); data.NotNulls.Set(2); data.NotNulls.Clear(3); var index = new SortIndex(); index.Update(data, validDocsBitmap, 4); Assert.AreEqual(4, index.OrderData.Length); // expected resulting order: 3, 2, 0, 1 // item 3 goes on top because it is marked as NULL Assert.AreEqual(3, index.OrderData[0]); Assert.AreEqual(2, index.OrderData[1]); Assert.AreEqual(0, index.OrderData[2]); Assert.AreEqual(1, index.OrderData[3]); } } }
/// <summary> /// Produces name of the synthesized delegate symbol that encodes the parameter byref-ness and return type of the delegate. /// The arity is appended via `N suffix in MetadataName calculation since the delegate is generic. /// </summary> internal static string MakeDynamicCallSiteDelegateName(BitVector byRefs, bool returnsVoid, int generation) { var pooledBuilder = PooledStringBuilder.GetInstance(); var builder = pooledBuilder.Builder; builder.Append(returnsVoid ? "<>A" : "<>F"); if (!byRefs.IsNull) { builder.Append("{"); int i = 0; foreach (int byRefIndex in byRefs.Words()) { if (i > 0) { builder.Append(","); } builder.AppendFormat("{0:x8}", byRefIndex); i++; } builder.Append("}"); Debug.Assert(i > 0); } AppendOptionalGeneration(builder, generation); return pooledBuilder.ToStringAndFree(); }
public BitVector <T> Ite(DD g, BitVector <T> t, BitVector <T> f) { return(this.Manager.Ite(g, t, f)); }
public BitVectorReader(BitVector vector) { this.vector = vector; }
public void WhereGreaterThan(XArray left, XArray right, BitVector vector) { throw new ArgumentException("Operator is not valid for boolean"); }
// Modify the bit vector by XOR'ing with "other" public void xor(BitVector other) { if (sizeInBits != other.size()) { throw new System.ArgumentException("BitVector sizes don't match"); } int sizeInBytes = (sizeInBits + 7) >> 3; for (int i = 0; i < sizeInBytes; ++i) { // The last byte could be incomplete (i.e. not have 8 bits in // it) but there is no problem since 0 XOR 0 == 0. array[i] ^= other.array[i]; } }
internal InvokeMethod(SynthesizedDelegateSymbol containingType, BitVector byRefParameters, TypeSymbol voidReturnTypeOpt) { var typeParams = containingType.TypeParameters; _containingType = containingType; // if we are given Void type the method returns Void, otherwise its return type is the last type parameter of the delegate: _returnType = voidReturnTypeOpt ?? typeParams.Last(); var parameters = new ParameterSymbol[typeParams.Length - ((object)voidReturnTypeOpt != null ? 0 : 1)]; for (int i = 0; i < parameters.Length; i++) { // we don't need to distinguish between out and ref since this is an internal synthesized symbol: var refKind = !byRefParameters.IsNull && byRefParameters[i] ? RefKind.Ref : RefKind.None; parameters[i] = SynthesizedParameterSymbol.Create(this, typeParams[i], i, refKind); } _parameters = parameters.AsImmutableOrNull(); }
private bool RecordCapturedChanges(ref BitVector oldState, ref BitVector newState) { // Build a list of variables that are both captured and assigned var capturedMask = GetCapturedBitmask(ref newState); var capturedAndSet = newState; capturedAndSet.IntersectWith(capturedMask); // Union and check to see if there are any changes return oldState.UnionWith(capturedAndSet); }
private void TestRandomValuesSetter(int size) { var data = CreateRandomBoolArray(size); using (var vector = new BitVector(Pool)) { vector.EnsureCapacity((ulong) size); // check both are false for (var i = 0; i < size; i++) { IsFalse(vector.Get(i)); } var watch = Stopwatch.StartNew(); // assign new values and check state immediately after assignment for (var i = 0; i < data.Length; i++) { //vector.EnsureCapacity((ulong)i + 1); //if (data[i]) vector.Set(i); //else // vector.SafeClear(i); //if (i > 1) // AreEqual(data[i - 2], vector.Get(i - 2)); //if (i > 0) // AreEqual(data[i - 1], vector.Get(i - 1)); //AreEqual(data[i], vector.Get(i)); } // check all are equal after all setters //for (var i = 0; i < data.Length; i++) //{ // AreEqual(data[i], vector.Get(i)); //} watch.Stop(); Console.WriteLine("Elapsed {0} for size {1}", watch.ElapsedMilliseconds, size); } }
public DD GreaterThanOrEqualSigned(BitVector <T> x, BitVector <T> y) { return(this.Manager.GreaterOrEqualSigned(x, y)); }
public void Operations_IsPrefix() { var v1 = BitVector.Parse("1"); var v2 = BitVector.Parse("0"); Assert.False(v1.IsPrefix(v2)); Assert.False(v2.IsPrefix(v1)); v1 = BitVector.Parse("10"); v2 = BitVector.Parse("11"); Assert.False(v1.IsPrefix(v2)); Assert.False(v2.IsPrefix(v1)); Assert.True(v2.IsPrefix(v1, 0)); Assert.True(v2.IsPrefix(v1, 1)); Assert.False(v2.IsPrefix(v1, 2)); v1 = BitVector.Parse("10000000"); v2 = BitVector.Parse("10000000"); Assert.True(v1.IsPrefix(v2)); Assert.True(v2.IsPrefix(v1)); for (int i = 0; i < v1.Count; i++) { Assert.True(v2.IsPrefix(v1, i)); Assert.True(v1.IsPrefix(v2, i)); } v1 = BitVector.Parse("1100000"); v2 = BitVector.Parse("11000001"); Assert.True(v1.IsPrefix(v2)); Assert.False(v2.IsPrefix(v1)); v1 = BitVector.Parse("1100000011"); v2 = BitVector.Parse("11000000111"); Assert.True(v1.IsPrefix(v2)); Assert.False(v2.IsPrefix(v1)); v1 = BitVector.Parse("0100000011"); v2 = BitVector.Parse("01000000110"); Assert.True(v1.IsPrefix(v2)); Assert.False(v2.IsPrefix(v1)); for (int i = 0; i < v1.Count; i++) { Assert.True(v2.IsPrefix(v1, i)); Assert.True(v1.IsPrefix(v2, i)); } Assert.False(v1.IsPrefix(v2, v2.Count)); v1 = BitVector.Parse(""); v2 = BitVector.Parse("01000000111"); Assert.True(v1.IsPrefix(v2)); Assert.False(v2.IsPrefix(v1)); v1 = BitVector.Of(0xFFFFFFFF, 0x00000000, 0x00000000); v2 = BitVector.Of(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000); Assert.True(v1.IsPrefix(v2)); Assert.False(v2.IsPrefix(v1)); v1 = BitVector.Of(0xFFFFFFFF); v2 = BitVector.Of(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000); Assert.True(v1.IsPrefix(v2)); Assert.False(v2.IsPrefix(v1)); }
public DD LessThanOrEqualSigned(BitVector <T> x, BitVector <T> y) { return(this.Manager.LessOrEqualSigned(x, y)); }
public DD Eq(BitVector <T> x, BitVector <T> y) { return(this.Manager.Eq(x, y)); }
public BitVector <T> Multiply(BitVector <T> x, BitVector <T> y) { throw new ZenException("Decision diagram backend does not support multiplication"); }
public BitVector <T> Subtract(BitVector <T> x, BitVector <T> y) { return(this.Manager.Subtract(x, y)); }
public BitVector <T> Add(BitVector <T> x, BitVector <T> y) { return(this.Manager.Add(x, y)); }
static bool hasDefaultArgument(ImmutableArray <BoundExpression> arguments, BitVector defaultArguments) { for (int i = 0; i < arguments.Length; i++) { if (defaultArguments[i]) { return(true); } } return(false); }
/// <summary>Embed "dataBits" using "getMaskPattern".</summary> /// <remarks> /// Embed "dataBits" using "getMaskPattern". On success, the matrix is modified /// For debugging purposes, it skips masking process if "getMaskPattern" is -1. /// See 8.7 of JISX0510:2004 (p.38) for how to embed data bits. /// </remarks> /// <param name="dataBits">data bits to embed in the QR code</param> /// <param name="maskPattern">masking pattern to apply to the data bits</param> /// <param name="matrix">Byte matrix representing the QR code</param> /// <exception cref="WriterException"/> /// <exception cref="iText.Barcodes.Qrcode.WriterException"/> public static void EmbedDataBits(BitVector dataBits, int maskPattern, ByteMatrix matrix) { int bitIndex = 0; int direction = -1; // Start from the right bottom cell. int x = matrix.GetWidth() - 1; int y = matrix.GetHeight() - 1; while (x > 0) { // Skip the vertical timing pattern. if (x == 6) { x -= 1; } while (y >= 0 && y < matrix.GetHeight()) { for (int i = 0; i < 2; ++i) { int xx = x - i; // Skip the cell if it's not empty. if (!IsEmpty(matrix.Get(xx, y))) { continue; } int bit; if (bitIndex < dataBits.Size()) { bit = dataBits.At(bitIndex); ++bitIndex; } else { // Padding bit. If there is no bit left, we'll fill the left cells with 0, as described // in 8.4.9 of JISX0510:2004 (p. 24). bit = 0; } // Skip masking if mask_pattern is -1. if (maskPattern != -1) { if (MaskUtil.GetDataMaskBit(maskPattern, xx, y)) { bit ^= 0x1; } } matrix.Set(xx, y, bit); } y += direction; } direction = -direction; // Reverse the direction. y += direction; x -= 2; } // Move to the left. // All bits should be consumed. if (bitIndex != dataBits.Size()) { throw new WriterException("Not all bits consumed: " + bitIndex + '/' + dataBits.Size()); } }
private void TestRandomValuesSetter2(ulong size, BitVector vector) { var watch = Stopwatch.StartNew(); // assign new values and check state immediately after assignment for (ulong i = 0; i < size; i++) { if (i % 1000 == 0) { vector.EnsureCapacity(i + 2000); } vector.Set(i); //IsFalse(!vector.Get(i)); } watch.Stop(); Console.WriteLine("Elapsed {0} for size {1}", watch.ElapsedMilliseconds, size); }
/// <summary>Make bit vector of type information.</summary> /// <remarks> /// Make bit vector of type information. On success, store the result in "bits". /// Encode error correction level and mask pattern. See 8.9 of JISX0510:2004 (p.45) for details. /// </remarks> /// <param name="ecLevel">error correction level of the QR code</param> /// <param name="maskPattern">masking pattern to use</param> /// <param name="bits">Vactor of bits to contain the result</param> /// <exception cref="WriterException"/> /// <exception cref="iText.Barcodes.Qrcode.WriterException"/> public static void MakeTypeInfoBits(ErrorCorrectionLevel ecLevel, int maskPattern, BitVector bits) { if (!QRCode.IsValidMaskPattern(maskPattern)) { throw new WriterException("Invalid mask pattern"); } int typeInfo = (ecLevel.GetBits() << 3) | maskPattern; bits.AppendBits(typeInfo, 5); int bchCode = CalculateBCHCode(typeInfo, TYPE_INFO_POLY); bits.AppendBits(bchCode, 10); BitVector maskBits = new BitVector(); maskBits.AppendBits(TYPE_INFO_MASK_PATTERN, 15); bits.Xor(maskBits); if (bits.Size() != 15) { // Just in case. throw new WriterException("should not happen but we got: " + bits.Size()); } }
protected ColumnDataBase(ColumnDataBase source, IUnmanagedAllocator allocator) { // may throw due to insufficient memory NotNulls = new BitVector(source.NotNulls, allocator); }
protected override LocalFunctionState CreateLocalFunctionState() => new LocalFunctionState( // The bottom state should assume all variables, even new ones, are assigned new LocalState(BitVector.AllSet(nextVariableSlot), normalizeToBottom: true), UnreachableState());
private static bool CheckMethodConstraints( MethodSymbol method, ConversionsBase conversions, Compilation currentCompilation, ArrayBuilder<TypeParameterDiagnosticInfo> diagnosticsBuilder, ref ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder, BitVector skipParameters = default(BitVector)) { return CheckConstraints( method, conversions, method.TypeSubstitution, ((MethodSymbol)method.OriginalDefinition).TypeParameters, method.TypeArguments, currentCompilation, diagnosticsBuilder, ref useSiteDiagnosticsBuilder, skipParameters); }
public bool CheckStructure() { int num; int num2; if ((this.Coders.Count > 0x20) || (this.BindPairs.Count > 0x20)) { return(false); } BitVector vector = new BitVector(this.BindPairs.Count + this.PackStreams.Count); for (num = 0; num < this.BindPairs.Count; num++) { if (vector.GetAndSet(this.BindPairs[num].InIndex)) { return(false); } } for (num = 0; num < this.PackStreams.Count; num++) { if (vector.GetAndSet(this.PackStreams[num])) { return(false); } } vector = new BitVector(this.UnpackSizes.Count); for (num = 0; num < this.BindPairs.Count; num++) { if (vector.GetAndSet(this.BindPairs[num].OutIndex)) { return(false); } } uint[] numArray = new uint[0x20]; List <int> list = new List <int>(); List <int> list2 = new List <int>(); for (num = 0; num < this.Coders.Count; num++) { CCoderInfo info = this.Coders[num]; num2 = 0; while (num2 < info.NumInStreams) { list.Add(num); num2++; } num2 = 0; while (num2 < info.NumOutStreams) { list2.Add(num); num2++; } } for (num = 0; num < this.BindPairs.Count; num++) { CBindPair pair = this.BindPairs[num]; numArray[list[pair.InIndex]] |= ((uint)1) << list2[pair.OutIndex]; } for (num = 0; num < 0x20; num++) { for (num2 = 0; num2 < 0x20; num2++) { if (((((int)1) << num2) & numArray[num]) != 0) { numArray[num] |= numArray[num2]; } } } for (num = 0; num < 0x20; num++) { if (((((int)1) << num) & numArray[num]) != 0) { return(false); } } return(true); }
public BitVector <T> BitwiseXor(BitVector <T> x, BitVector <T> y) { return(this.Manager.Xor(x, y)); }
internal NamedTypeSymbol GetDelegateType( BoundExpression loweredReceiver, RefKind receiverRefKind, ImmutableArray <BoundExpression> loweredArguments, ImmutableArray <RefKind> refKinds, BoundExpression loweredRight, TypeSymbol resultType) { Debug.Assert(refKinds.IsDefaultOrEmpty || refKinds.Length == loweredArguments.Length); var callSiteType = _factory.WellKnownType(WellKnownType.System_Runtime_CompilerServices_CallSite); if (callSiteType.IsErrorType()) { return(null); } var delegateSignature = MakeCallSiteDelegateSignature(callSiteType, loweredReceiver, loweredArguments, loweredRight, resultType); bool returnsVoid = resultType.SpecialType == SpecialType.System_Void; bool hasByRefs = receiverRefKind != RefKind.None || !refKinds.IsDefaultOrEmpty; if (!hasByRefs) { var wkDelegateType = returnsVoid ? WellKnownTypes.GetWellKnownActionDelegate(invokeArgumentCount: delegateSignature.Length) : WellKnownTypes.GetWellKnownFunctionDelegate(invokeArgumentCount: delegateSignature.Length - 1); if (wkDelegateType != WellKnownType.Unknown) { var delegateType = _factory.Compilation.GetWellKnownType(wkDelegateType); if (!delegateType.HasUseSiteError) { return(delegateType.Construct(delegateSignature)); } } } BitVector byRefs; if (hasByRefs) { byRefs = BitVector.Create(1 + (loweredReceiver != null ? 1 : 0) + loweredArguments.Length + (loweredRight != null ? 1 : 0)); int j = 1; if (loweredReceiver != null) { byRefs[j++] = receiverRefKind != RefKind.None; } if (!refKinds.IsDefault) { for (int i = 0; i < refKinds.Length; i++, j++) { if (refKinds[i] != RefKind.None) { byRefs[j] = true; } } } } else { byRefs = default(BitVector); } int parameterCount = delegateSignature.Length - (returnsVoid ? 0 : 1); int generation = _factory.CompilationState.ModuleBuilderOpt.CurrentGenerationOrdinal; var synthesizedType = _factory.Compilation.AnonymousTypeManager.SynthesizeDelegate(parameterCount, byRefs, returnsVoid, generation); return(synthesizedType.Construct(delegateSignature)); }
public void WhereEqual(XArray left, XArray right, BitVector vector) { bool[] leftArray = (bool[])left.Array; bool[] rightArray = (bool[])right.Array; // Check how the arrays are configured and run the fastest loop possible for the configuration. if (left.Selector.Indices != null || right.Selector.Indices != null) { // Slow Path: Look up indices on both sides. ~55ms for 16M for (int i = 0; i < left.Count; ++i) { if (leftArray[left.Index(i)] == rightArray[right.Index(i)]) { vector.Set(i); } } } else if (!right.Selector.IsSingleValue) { // Faster Path: Compare contiguous arrays. ~20ms for 16M if (s_WhereNative != null) { s_WhereNative(leftArray, left.Selector.StartIndexInclusive, (byte)CompareOperator.Equal, rightArray, right.Selector.StartIndexInclusive, left.Selector.Count, (byte)BooleanOperator.Or, vector.Array, 0); } else { int zeroOffset = left.Selector.StartIndexInclusive; int leftIndexToRightIndex = right.Selector.StartIndexInclusive - left.Selector.StartIndexInclusive; for (int i = left.Selector.StartIndexInclusive; i < left.Selector.EndIndexExclusive; ++i) { if (leftArray[i] == rightArray[i + leftIndexToRightIndex]) { vector.Set(i - zeroOffset); } } } } else if (!left.Selector.IsSingleValue) { // Fastest Path: Contiguous Array to constant. ~15ms for 16M int zeroOffset = left.Selector.StartIndexInclusive; bool rightValue = rightArray[0]; if (s_WhereSingleNative != null) { s_WhereSingleNative(leftArray, left.Selector.StartIndexInclusive, left.Selector.Count, (byte)CompareOperator.Equal, rightValue, (byte)BooleanOperator.Or, vector.Array, 0); } else { for (int i = left.Selector.StartIndexInclusive; i < left.Selector.EndIndexExclusive; ++i) { if (leftArray[i] == rightValue) { vector.Set(i - zeroOffset); } } } } else { // Single Static comparison. ~0.7ms for 16M [called every 10,240 rows] if (leftArray[left.Selector.StartIndexInclusive] == rightArray[right.Selector.StartIndexInclusive]) { vector.All(left.Count); } } // Remove nulls from matches BoolComparer.AndNotNull(left, vector); BoolComparer.AndNotNull(right, vector); }
public bool CheckStructure() { const int kNumCodersMax = 32; // don't change it const int kMaskSize = 32; // it must be >= kNumCodersMax const int kNumBindsMax = 32; if (_coders.Count > kNumCodersMax || _bindPairs.Count > kNumBindsMax) { return(false); } { var v = new BitVector(_bindPairs.Count + _packStreams.Count); for (int i = 0; i < _bindPairs.Count; i++) { if (v.GetAndSet(_bindPairs[i]._inIndex)) { return(false); } } for (int i = 0; i < _packStreams.Count; i++) { if (v.GetAndSet(_packStreams[i])) { return(false); } } } { var v = new BitVector(_unpackSizes.Count); for (int i = 0; i < _bindPairs.Count; i++) { if (v.GetAndSet(_bindPairs[i]._outIndex)) { return(false); } } } uint[] mask = new uint[kMaskSize]; { List <int> inStreamToCoder = new List <int>(); List <int> outStreamToCoder = new List <int>(); for (int i = 0; i < _coders.Count; i++) { CCoderInfo coder = _coders[i]; for (int j = 0; j < coder._numInStreams; j++) { inStreamToCoder.Add(i); } for (int j = 0; j < coder._numOutStreams; j++) { outStreamToCoder.Add(i); } } for (int i = 0; i < _bindPairs.Count; i++) { CBindPair bp = _bindPairs[i]; mask[inStreamToCoder[bp._inIndex]] |= (1u << outStreamToCoder[bp._outIndex]); } } for (int i = 0; i < kMaskSize; i++) { for (int j = 0; j < kMaskSize; j++) { if (((1u << j) & mask[i]) != 0) { mask[i] |= mask[j]; } } } for (int i = 0; i < kMaskSize; i++) { if (((1u << i) & mask[i]) != 0) { return(false); } } return(true); }
public static void Main(string[] args) { if (args.Length != 2) { Console.Error.WriteLine("Usage: SHS.SCC2 <leader> <store>"); } else { var sw = Stopwatch.StartNew(); var shs = new Service(args[0]).OpenStore(Guid.Parse(args[1])); var map = shs.AllocateUidState<int>(); // Mapping from UID to local ID int numVerts = 0; // Number of core vertices var batch = new Batch<long>(500000); foreach (long u in shs.Uids()) { batch.Add(u); if (batch.Full || shs.IsLastUid(u)) { int[] fwdDegs = shs.BatchedGetDegree(batch, Dir.Fwd); int[] bwdDegs = shs.BatchedGetDegree(batch, Dir.Bwd); var mapChunk = new int[batch.Count]; for (int i = 0; i < batch.Count; i++) { mapChunk[i] = fwdDegs[i] == 0 || bwdDegs[i] == 0 ? -1 : numVerts++; } map.SetMany(batch, mapChunk); batch.Reset(); } } uint numEdges = 0; foreach (var up in map.GetAll()) { if (up.val != -1) batch.Add(up.uid); if (batch.Full || shs.IsLastUid(up.uid)) { long[][] nbors = shs.BatchedGetLinks(batch, Dir.Fwd); int[] mappedNbors = map.GetMany(Flatten(nbors)); int q = 0; for (int i = 0; i < nbors.Length; i++) { for (int j = 0; j < nbors[i].Length; j++) { if (mappedNbors[q++] != -1) numEdges++; } } batch.Reset(); } } uint[] pastLast = new uint[numVerts]; // one past last link of that page var links = new int[numEdges]; int p = 0; uint r = 0; foreach (var up in map.GetAll()) { if (up.val != -1) batch.Add(up.uid); if (batch.Full || shs.IsLastUid(up.uid)) { long[][] nbors = shs.BatchedGetLinks(batch, Dir.Fwd); int[] mappedNbors = map.GetMany(Flatten(nbors)); int q = 0; for (int i = 0; i < nbors.Length; i++) { for (int j = 0; j < nbors[i].Length; j++) { int id = mappedNbors[q++]; if (id != -1) links[r++] = id; } pastLast[p++] = r; } batch.Reset(); } } var bv = new BitVector(numVerts); // All false at creation int[] stk = new int[numVerts]; int stkPtr = stk.Length; for (int u = 0; u < numVerts; u++) { if (!bv[u]) { bv[u] = true; Frame frame = new Frame(null, u, pastLast); while (frame != null) { while (frame.ctr < pastLast[frame.id]) { int v = links[frame.ctr++]; if (!bv[v]) { bv[v] = true; frame = new Frame(frame, v, pastLast); } } stk[--stkPtr] = frame.id; frame = frame.parent; } } } p = 0; r = 0; foreach (var up in map.GetAll()) { if (up.val != -1) batch.Add(up.uid); if (batch.Full || shs.IsLastUid(up.uid)) { long[][] nbors = shs.BatchedGetLinks(batch, Dir.Bwd); int[] mappedNbors = map.GetMany(Flatten(nbors)); int q = 0; for (int i = 0; i < nbors.Length; i++) { for (int j = 0; j < nbors[i].Length; j++) { int id = mappedNbors[q++]; if (id != -1) links[r++] = id; } pastLast[p++] = r; } batch.Reset(); } } var pam = new long[numVerts]; p = 0; foreach (var up in map.GetAll()) { if (up.val != -1) pam[p++] = up.uid; } using (var sccWr = new BinaryWriter(new BufferedStream(new FileStream("scc-main.bin", FileMode.Create, FileAccess.Write)))) { using (var idxWr = new BinaryWriter(new BufferedStream(new FileStream("scc-index.bin", FileMode.Create, FileAccess.Write)))) { long sccPos = 0; bv.SetAll(false); for (int i = 0; i < stk.Length; i++) { int u = stk[i]; if (!bv[u]) { long sccSize = 0; bv[u] = true; Frame frame = new Frame(null, u, pastLast); while (frame != null) { while (frame.ctr < pastLast[frame.id]) { int v = links[frame.ctr++]; if (!bv[v]) { bv[v] = true; frame = new Frame(frame, v, pastLast); } } sccWr.Write(pam[frame.id]); sccSize++; frame = frame.parent; } idxWr.Write(sccSize); idxWr.Write(sccPos); sccPos += sccSize; } } foreach (var up in map.GetAll()) { if (up.val == -1) { sccWr.Write(up.uid); idxWr.Write(1L); idxWr.Write(sccPos++); } } } } var dict = new System.Collections.Generic.Dictionary<long, long>(); using (var ib = new BinaryReader(new BufferedStream(new FileStream("scc-index.bin", FileMode.Open, FileAccess.Read)))) { while (true) { try { long size = ib.ReadInt64(); long pos = ib.ReadInt64(); if (!dict.ContainsKey(size)) dict[size] = 0; dict[size]++; } catch (EndOfStreamException) { break; } } } long maxSize = 0; long numSCCs = 0; foreach (var kv in dict) { if (kv.Key > maxSize) maxSize = kv.Key; numSCCs += kv.Value; } Console.WriteLine("Done. Job took {0} seconds.", 0.001 * sw.ElapsedMilliseconds); } }
public void ComputeLastSetBit_IsCorrect(uint data, int lastBit) { var vector = new BitVector(data); Assert.Equal(lastBit, vector.ComputeLastSetBit()); }
private void TestPersistence(ulong count, ExpandableArrayOfKeys keys) { using (var validEntries = new BitVector(_pool)) { validEntries.EnsureCapacity(count); validEntries.ChangeAll(true); using (var stream = new FileStream(@"c:\temp\data.d", FileMode.Create, FileAccess.ReadWrite)) { using (var writer = new BinaryWriter(stream)) { keys.Write(writer, (ulong) count, validEntries); } } using (var keys2 = new ExpandableArrayOfKeys(_pool)) { using (var stream = new FileStream(@"c:\temp\data.d", FileMode.Open, FileAccess.Read)) { using (var reader = new BinaryReader(stream)) { { keys2.Read(reader, (ulong) count, validEntries); } } } } } }
public void Constructor_Succeeds(uint data) { var vector = new BitVector(data); Assert.Equal(data, vector.Data); }
private bool RecordChangedVars(ref LocalState oldWrites, ref LocalState newWrites, ref BitVector oldReads, ref BitVector newReads) { bool anyChanged = IntersectWith(ref oldWrites, ref newWrites); anyChanged |= RecordCapturedChanges(ref oldReads, ref newReads); return anyChanged; }
public void ComputeCount_OnConstruction_IsCorrect(uint data, int numBits) { var vector = new BitVector(data); Assert.Equal(numBits, vector.ComputeCount()); }
internal Frame(Frame parent, long uid, Store shs, Dir dir, BitVector bv) { this.parent = parent; this.uid = uid; this.links = shs.GetLinks(uid, dir); this.linkPos = 0; bv[shs.UidToLid(uid)] = true; }
public void IsEmpty_Succeeds(uint data, bool isEmpty) { var vector = new BitVector(data); Assert.Equal(isEmpty, vector.IsEmpty); }
private bool RecordChangedVars(ref BitVector oldWrites, ref BitVector newWrites, ref BitVector oldReads, ref BitVector newReads) { bool anyChanged = RecordCapturedChanges(ref oldWrites, ref newWrites); anyChanged |= RecordCapturedChanges(ref oldReads, ref newReads); return anyChanged; }
public void CreateWithSize_ValidValues_Succeeds(int size, uint data) { var vector = BitVector.CreateWithSize(size); Assert.Equal(data, vector.Data); }
private BitVector GetCapturedBitmask(ref BitVector state) { BitVector mask = BitVector.Empty; for (int slot = 1; slot < state.Capacity; slot++) { if (IsCapturedInLocalFunction(slot)) { mask[slot] = true; } } return mask; }
public void CreateWithSize_InvalidValues_ThrowsOutOfRange(int size) => Assert.Throws <ArgumentOutOfRangeException>("size", () => BitVector.CreateWithSize(size));
private void TestSetAll() { using (var vector = new BitVector(Pool)) { vector.EnsureCapacity(100000000); for (ulong i = 0; i < vector.Capacity; i++) { if (i % 3 == 0 || i % 7 == 0) { vector.Set(i); } } for (ulong i = 0; i < vector.Capacity; i++) { if (i % 3 == 0 || i % 7 == 0) { IsFalse(!vector.Get(i)); } } vector.ChangeAll(false); for (ulong i = 0; i < vector.Capacity; i++) { IsFalse(vector.Get(i)); } vector.ChangeAll(true); for (ulong i = 0; i < vector.Capacity; i++) { IsFalse(!vector.Get(i)); } } }
public BoundObjectCreationExpression(SyntaxNode syntax, MethodSymbol constructor, ImmutableArray <BoundExpression> arguments, ImmutableArray <string> argumentNamesOpt, ImmutableArray <RefKind> argumentRefKindsOpt, bool expanded, ImmutableArray <int> argsToParamsOpt, BitVector defaultArguments, ConstantValue?constantValueOpt, BoundObjectInitializerExpressionBase?initializerExpressionOpt, Binder?binderOpt, TypeSymbol type, bool hasErrors = false) : this(syntax, constructor, ImmutableArray <MethodSymbol> .Empty, arguments, argumentNamesOpt, argumentRefKindsOpt, expanded, argsToParamsOpt, defaultArguments, constantValueOpt, initializerExpressionOpt, wasTargetTyped : false, binderOpt, type, hasErrors) { }
protected ColumnDataBase(IUnmanagedAllocator allocator) { NotNulls = new BitVector(allocator); }
public BitVector <T> BitwiseAnd(BitVector <T> x, BitVector <T> y) { return(this.Manager.And(x, y)); }
// Append "bits". public void appendBitVector(BitVector bits) { int size = bits.size(); for (int i = 0; i < size; ++i) { appendBit(bits.at(i)); } }
internal NamedTypeSymbol GetCallSiteDelegateType( TypeSymbol loweredReceiver, RefKind receiverRefKind, ImmutableArray <TypeSymbol> loweredArguments, ImmutableArray <RefKind> refKinds, TypeSymbol loweredRight, TypeSymbol resultType) { Debug.Assert(refKinds.IsDefaultOrEmpty || refKinds.Length == loweredArguments.Length); var callSiteType = this.CallSite; if (callSiteType.IsErrorType()) { return(null); } var delegateSignature = MakeCallSiteDelegateSignature(callSiteType, loweredReceiver, loweredArguments, loweredRight, resultType); bool returnsVoid = resultType.SpecialType == SpecialType.System_Void; bool hasByRefs = receiverRefKind != RefKind.None || !refKinds.IsDefaultOrEmpty; if (!hasByRefs) { var wkDelegateType = returnsVoid ? WellKnownTypes.GetWellKnownActionDelegate(invokeArgumentCount: delegateSignature.Length) : WellKnownTypes.GetWellKnownFunctionDelegate(invokeArgumentCount: delegateSignature.Length - 1); if (wkDelegateType != WellKnownType.Unknown) { var delegateType = _compilation.GetWellKnownType(wkDelegateType); if (delegateType != null && !delegateType.IsErrorType()) { return(delegateType.Construct(delegateSignature)); } } } BitVector byRefs; if (hasByRefs) { byRefs = BitVector.Create(1 + (loweredReceiver != null ? 1 : 0) + loweredArguments.Length + (loweredRight != null ? 1 : 0)); int j = 1; if (loweredReceiver != null) { byRefs[j++] = receiverRefKind != RefKind.None; } if (!refKinds.IsDefault) { for (int i = 0; i < refKinds.Length; i++, j++) { if (refKinds[i] != RefKind.None) { byRefs[j] = true; } } } } else { byRefs = default(BitVector); } int parameterCount = delegateSignature.Length - (returnsVoid ? 0 : 1); return(_compilation.AnonymousTypeManager.SynthesizeDelegate(parameterCount, byRefs, returnsVoid).Construct(delegateSignature)); }
public static bool CheckConstraints( this MethodSymbol method, ConversionsBase conversions, SyntaxNode syntaxNode, Compilation currentCompilation, DiagnosticBag diagnostics, BitVector skipParameters = default(BitVector)) { if (!RequiresChecking(method)) { return true; } var diagnosticsBuilder = ArrayBuilder<TypeParameterDiagnosticInfo>.GetInstance(); ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder = null; var result = CheckMethodConstraints(method, conversions, currentCompilation, diagnosticsBuilder, ref useSiteDiagnosticsBuilder, skipParameters); if (useSiteDiagnosticsBuilder != null) { diagnosticsBuilder.AddRange(useSiteDiagnosticsBuilder); } foreach (var pair in diagnosticsBuilder) { var location = new SourceLocation(syntaxNode); diagnostics.Add(new CSDiagnostic(pair.DiagnosticInfo, location)); } diagnosticsBuilder.Free(); return result; }
public SynthesizedDelegateKey(int parameterCount, BitVector byRefs, bool returnsVoid) { _parameterCount = (ushort)parameterCount; _returnsVoid = (byte)(returnsVoid ? 1 : 0); _byRefs = byRefs; }
/// <summary> /// Check type parameter constraints for the containing type or method symbol. /// </summary> /// <param name="containingSymbol">The generic type or method.</param> /// <param name="conversions">Conversions instance.</param> /// <param name="substitution">The map from type parameters to type arguments.</param> /// <param name="typeParameters">Containing symbol type parameters.</param> /// <param name="typeArguments">Containing symbol type arguments.</param> /// <param name="currentCompilation">Improves error message detail.</param> /// <param name="diagnosticsBuilder">Diagnostics.</param> /// <param name="skipParameters">Parameters to skip.</param> /// <param name="useSiteDiagnosticsBuilder"/> /// <param name="ignoreTypeConstraintsDependentOnTypeParametersOpt">If an original form of a type constraint /// depends on a type parameter from this set, do not verify this type constraint.</param> /// <returns>True if the constraints were satisfied, false otherwise.</returns> public static bool CheckConstraints( this Symbol containingSymbol, ConversionsBase conversions, TypeMap substitution, ImmutableArray<TypeParameterSymbol> typeParameters, ImmutableArray<TypeSymbol> typeArguments, Compilation currentCompilation, ArrayBuilder<TypeParameterDiagnosticInfo> diagnosticsBuilder, ref ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder, BitVector skipParameters = default(BitVector), HashSet<TypeParameterSymbol> ignoreTypeConstraintsDependentOnTypeParametersOpt = null) { Debug.Assert(typeParameters.Length == typeArguments.Length); Debug.Assert(typeParameters.Length > 0); int n = typeParameters.Length; bool succeeded = true; for (int i = 0; i < n; i++) { if (skipParameters[i]) { continue; } var typeArgument = typeArguments[i]; var typeParameter = typeParameters[i]; if (!CheckConstraints(containingSymbol, conversions, substitution, typeParameter, typeArgument, currentCompilation, diagnosticsBuilder, ref useSiteDiagnosticsBuilder, ignoreTypeConstraintsDependentOnTypeParametersOpt)) { succeeded = false; } } return succeeded; }
internal NullBitVectorReader(BitVector Param1) : base(Param1) { }
public BoundObjectCreationExpression Update(MethodSymbol constructor, ImmutableArray <MethodSymbol> constructorsGroup, ImmutableArray <BoundExpression> arguments, ImmutableArray <string> argumentNamesOpt, ImmutableArray <RefKind> argumentRefKindsOpt, bool expanded, ImmutableArray <int> argsToParamsOpt, BitVector defaultArguments, ConstantValue?constantValueOpt, BoundObjectInitializerExpressionBase?initializerExpressionOpt, Binder?binderOpt, TypeSymbol type) { return(this.Update(constructor, constructorsGroup, arguments, argumentNamesOpt, argumentRefKindsOpt, expanded, argsToParamsOpt, defaultArguments, constantValueOpt, initializerExpressionOpt, this.WasTargetTyped, binderOpt, type)); }
public BitVector <T> BitwiseNot(BitVector <T> x) { return(this.Manager.Not(x)); }