/// <summary>
 /// Initializes a new instance of the <see cref="SnapshotElementComparer" /> class.
 /// </summary>
 /// <param name="region">The parent region that contains this element.</param>
 /// <param name="pointerIncrementMode">The method by which to increment element pointers.</param>
 /// <param name="constraints">The constraints to use for the element comparisons.</param>
 public unsafe SnapshotElementComparer(
     SnapshotRegion region,
     PointerIncrementMode pointerIncrementMode,
     ConstraintNode constraints) : this(region, pointerIncrementMode)
 {
     this.ElementCompare = this.BuildCompareActions(constraints);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SnapshotElementIndexer" /> class.
 /// </summary>
 /// <param name="region">The parent region that contains this element.</param>
 /// <param name="elementIndex">The index of the element to begin pointing to.</param>
 public unsafe SnapshotElementIndexer(
     SnapshotRegion region,
     Int32 elementIndex = 0)
 {
     this.Region       = region;
     this.ElementIndex = elementIndex;
 }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SnapshotElementVectorComparer" /> class.
        /// </summary>
        /// <param name="region">The parent region that contains this element.</param>
        public SnapshotElementVectorComparer(SnapshotRegion region)
        {
            this.Region          = region;
            this.VectorSize      = Vectors.VectorSize;
            this.VectorReadBase  = this.Region.ReadGroupOffset - this.Region.ReadGroupOffset % this.VectorSize;
            this.VectorReadIndex = 0;
            this.DataTypeSize    = Conversions.SizeOf(this.Region.ReadGroup.ElementDataType);
            this.ResultRegions   = new List <SnapshotRegion>();

            this.SetConstraintFunctions();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SnapshotElementComparer" /> class.
        /// </summary>
        /// <param name="region">The parent region that contains this element.</param>
        /// <param name="pointerIncrementMode">The method by which to increment element pointers.</param>
        /// <param name="constraints">The constraints to use for the element comparisons.</param>
        public unsafe SnapshotElementComparer(SnapshotRegion region, PointerIncrementMode pointerIncrementMode, DataTypeBase dataType)
        {
            this.Region          = region;
            this.CurrentTypeCode = Type.GetTypeCode(dataType);

            // The garbage collector can relocate variables at runtime. Since we use unsafe pointers, we need to keep these pinned
            this.CurrentValuesHandle  = GCHandle.Alloc(this.Region.ReadGroup.CurrentValues, GCHandleType.Pinned);
            this.PreviousValuesHandle = GCHandle.Alloc(this.Region.ReadGroup.PreviousValues, GCHandleType.Pinned);

            this.InitializePointers();
            this.SetConstraintFunctions();
            this.SetPointerFunction(pointerIncrementMode);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SnapshotElementVectorComparer" /> class.
        /// </summary>
        /// <param name="region">The parent region that contains this element.</param>
        /// <param name="constraints">The set of constraints to use for the element comparisons.</param>
        public SnapshotElementVectorComparer(SnapshotRegion region, ScanConstraints constraints)
        {
            this.Region          = region;
            this.VectorSize      = Vectors.VectorSize;
            this.VectorReadBase  = this.Region.ReadGroupOffset - this.Region.ReadGroupOffset % this.VectorSize;
            this.VectorReadIndex = 0;
            this.DataType        = constraints.ElementType;
            this.DataTypeSize    = constraints.ElementType.Size;
            this.ResultRegions   = new List <SnapshotRegion>();

            this.SetConstraintFunctions();
            this.VectorCompare = this.BuildCompareActions(constraints?.RootConstraint);
        }
Example #6
0
        /// <summary>
        /// Indexer to allow the retrieval of the element at the specified index. Notes: This does NOT index into a region.
        /// </summary>
        /// <param name="elementIndex">The index of the snapshot element.</param>
        /// <returns>Returns the snapshot element at the specified index.</returns>
        public SnapshotElementIndexer this[UInt64 elementIndex]
        {
            get
            {
                SnapshotRegion region = this.BinaryRegionSearch(elementIndex);

                if (region == null)
                {
                    return(null);
                }

                return(region[(elementIndex - region.BaseElementIndex).ToInt32()]);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SnapshotElementComparer" /> class.
 /// </summary>
 /// <param name="region">The parent region that contains this element.</param>
 /// <param name="pointerIncrementMode">The method by which to increment element pointers.</param>
 /// <param name="constraints">The constraints to use for the element comparisons.</param>
 public unsafe SnapshotElementComparer(SnapshotRegion region, PointerIncrementMode pointerIncrementMode, Constraint constraints, DataTypeBase dataType) : this(region, pointerIncrementMode, dataType)
 {
     this.ElementCompare = this.BuildCompareActions(constraints);
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SnapshotElementVectorComparer" /> class.
 /// </summary>
 /// <param name="region">The parent region that contains this element.</param>
 /// <param name="constraints">The set of constraints to use for the element comparisons.</param>
 public SnapshotElementVectorComparer(SnapshotRegion region, ConstraintNode constraints) : this(region)
 {
     this.VectorCompare = this.BuildCompareActions(constraints);
 }
Example #9
0
        /// <summary>
        /// Finalizes any leftover snapshot regions and returns them.
        /// </summary>
        public IList <SnapshotRegion> GatherCollectedRegions()
        {
            // Create the final region if we are still encoding
            if (this.Encoding)
            {
                this.ResultRegions.Add(new SnapshotRegion(this.Region.ReadGroup, this.VectorReadBase + this.VectorReadIndex - this.RunLength, this.RunLength));
                this.RunLength = 0;
                this.Encoding  = false;
            }

            // Remove vector misaligned leading regions
            SnapshotRegion firstRegion   = this.ResultRegions.FirstOrDefault();
            Int32          adjustedIndex = 0;

            while (firstRegion != null)
            {
                // Exit if not misaligned
                if (firstRegion.ReadGroupOffset >= this.Region.ReadGroupOffset)
                {
                    break;
                }

                Int32 misalignment = this.Region.ReadGroupOffset - firstRegion.ReadGroupOffset;

                if (firstRegion.RegionSize <= misalignment)
                {
                    // The region is totally eclipsed -- remove it
                    this.ResultRegions.Remove(firstRegion);
                }
                else
                {
                    // The region is partially eclipsed -- adjust the size
                    firstRegion.ReadGroupOffset += misalignment;
                    firstRegion.RegionSize      -= misalignment;
                    adjustedIndex++;
                }

                firstRegion = this.ResultRegions.Skip(adjustedIndex).FirstOrDefault();
            }

            // Remove vector overreading trailing regions
            SnapshotRegion lastRegion = this.ResultRegions.LastOrDefault();

            adjustedIndex = 0;

            while (lastRegion != null)
            {
                // Exit if not overreading
                if (lastRegion.EndAddress <= this.Region.EndAddress)
                {
                    break;
                }

                Int32 overread = (lastRegion.EndAddress - this.Region.EndAddress).ToInt32();

                if (lastRegion.RegionSize <= overread)
                {
                    // The region is totally eclipsed -- remove it
                    this.ResultRegions.Remove(lastRegion);
                }
                else
                {
                    lastRegion.RegionSize -= overread;
                    adjustedIndex++;
                }

                lastRegion = this.ResultRegions.Reverse().Skip(adjustedIndex).FirstOrDefault();
            }

            return(this.ResultRegions);
        }