Esempio n. 1
0
        private bool _CollectDupSegments(
            int inDupCount,
            CSegmentPool inSegmentPool,
            int inMaxAllowedDup)
        {
            bool wasSuccessful = true;

            if (inDupCount > 0)
            {
                if (inDupCount <= inMaxAllowedDup)
                {
                    int theMinimalDistance = inSegmentPool.GetMinDist();
                    for (int i = 0, j = 0; i < _mArray.Length - 1 || j < inDupCount; i++)
                    {
                        var theDistance = Math.Abs(_mArray[i + 1]) - Math.Abs(_mArray[i]);
                        if (theDistance == theMinimalDistance && inSegmentPool.GetSegment(0).StartingPoint.Index != i
                            ) // Be careful about the same segment
                        {
                            int      theStartIndex = i, theEndIndex = i + 1;
                            CSegment theSegment = CSegment.Create(_mArray, theStartIndex, ref theEndIndex);
                            inSegmentPool.Add(theSegment);
                            j++;
                        }
                    }
                }
                else
                {
                    wasSuccessful = false;
                }
            }

            return(wasSuccessful);
        }
Esempio n. 2
0
        public bool FinalizeRecruit()
        {
            // First create one segment for the minimal residency
            CSegment theSegment = CSegment.Create(_mArray, _minimalResidency.Start, ref _minimalResidency.End);

            _minialSegmentPool.Add(theSegment);

            // Then handle the dups of minimal
            var wasSuccessful = _CollectDupSegments(_minimalResidency.DupCount, _minialSegmentPool, 5);

            // Now look at the subMinimal and if there was a valid segment, create and put it into the
            //  subminimal segment array
            if (_subMinimalResidency.End > _subMinimalResidency.Start)
            {
                theSegment = CSegment.Create(_mArray, _subMinimalResidency.Start, ref _subMinimalResidency.End);
                _subMinimalSegmentPool.Add(theSegment);
            }


            if (wasSuccessful)
            {
                wasSuccessful = _CollectDupSegments(_subMinimalResidency.DupCount, _subMinimalSegmentPool, 3);
            }

            return(wasSuccessful);
        }
Esempio n. 3
0
        public static CSegment Create(
            int[] inArray,
            int inStartIndex,
            ref int inEndIndex)
        {
            CSegment theSegment = null;

            // Handling of zero-distance segments
            //  Move forward until a non-zero-distance found
            if (inArray[inStartIndex] == inArray[inEndIndex])
            {
                while (inEndIndex < inArray.Length - 1)
                {
                    inEndIndex++;
                    if (inArray[inStartIndex] != inArray[inEndIndex])
                    {
                        theSegment = new CSegment(inStartIndex, inEndIndex);
                        break;
                    }
                }
            }
            else
            {
                theSegment = new CSegment(inStartIndex, inEndIndex);
            }

            return(theSegment);
        }
Esempio n. 4
0
        public void Add(
            CSegment inSegment)
        {
            if (_size > 6)
            {
                throw new Exception("Segment Pool is full!");
            }

            _segments[_size++] = inSegment;
            if (inSegment.Distance() < _minDist)
            {
                _minDist = inSegment.Distance();
            }
        }
Esempio n. 5
0
 public int Compare(
     CSegment inSegment)
 {
     return((EndingPoint.Value - StartingPoint.Value) -
            (inSegment.EndingPoint.Value - inSegment.StartingPoint.Value));
 }