コード例 #1
0
        void DoTestIntersect(R r1, R r2, int pos, R r1left, R r1right, R common, R r2left, R r2right)
        {
            S r = R.Intersect(r1, r2);

            Assert.AreEqual(pos, r.RelativePosition);
            AssertEqual(r1left, r.Leftover1Left);
            AssertEqual(r1right, r.Leftover1Right);
            AssertEqual(common, r.Common);
            AssertEqual(r2left, r.Leftover2Left);
            AssertEqual(r2right, r.Leftover2Right);
        }
コード例 #2
0
        public bool SetActiveRange(long p1, long p2)
        {
            if (openRange != null)
            {
                throw new InvalidOperationException("Cannot move the active range when there is a subrange being filled");
            }

            CheckIntegrity();

            bool ret = false;

            if (p2 < p1)
            {
                p2 = p1;
            }

            FRange fileRange = new FRange(p1, p2, 1);

            for (LinkedListNode <MessagesRange> r = ranges.First; r != null;)
            {
                LinkedListNode <MessagesRange> next = r.Next;

                FIntersectStruct s = FRange.Intersect(r.Value.DesirableRange, fileRange);
                if (s.RelativePosition < 0)
                {
                    ranges.Remove(r);
                    ret = true;
                }
                else if (s.RelativePosition == 0)
                {
                    r.Value.SetPriority(fileRange.Priority);

                    if (!s.Leftover1Left.IsEmpty)
                    {
                        r.Value.TrimLeft(fileRange.Begin);
                        ret = true;
                    }

                    if (!s.Leftover1Right.IsEmpty)
                    {
                        r.Value.TrimRight(fileRange.End);
                        ret = true;
                    }

                    if (!s.Leftover2Left.IsEmpty)
                    {
                        ranges.AddBefore(r, new MessagesRange(s.Leftover2Left));
                    }

                    fileRange = s.Leftover2Right;
                }
                else if (s.RelativePosition > 0)
                {
                    while (r != null)
                    {
                        next = r.Next;
                        ranges.Remove(r);
                        r = next;
                    }
                    ret = true;
                }

                r = next;
            }

            if (!fileRange.IsEmpty)
            {
                ranges.AddLast(new MessagesRange(fileRange));
                ret = true;
            }

            Merge();

            CheckIntegrity();

            return(ret);
        }