Example #1
0
        public void Reverse_NegativeParameters(int listLength)
        {
            if (listLength % 2 != 0)
            {
                listLength++;
            }
            SegmentedList <T> list = GenericListFactory(listLength);

            Tuple <int, int>[] InvalidParameters = new Tuple <int, int>[]
            {
                Tuple.Create(-1, -1),
                Tuple.Create(-1, 0),
                Tuple.Create(-1, 1),
                Tuple.Create(-1, 2),
                Tuple.Create(0, -1),
                Tuple.Create(1, -1),
                Tuple.Create(2, -1),
            };

            Assert.All(
                InvalidParameters,
                invalidSet =>
            {
                Assert.Throws <ArgumentOutOfRangeException>(
                    () => list.Reverse(invalidSet.Item1, invalidSet.Item2)
                    );
            }
                );
        }
        public void RemoveRange_InvalidParameters(int listLength)
        {
            if (listLength % 2 != 0)
            {
                listLength++;
            }
            SegmentedList <T> list = GenericListFactory(listLength);

            Tuple <int, int>[] InvalidParameters = new Tuple <int, int>[]
            {
                Tuple.Create(listLength, 1),
                Tuple.Create(listLength + 1, 0),
                Tuple.Create(listLength + 1, 1),
                Tuple.Create(listLength, 2),
                Tuple.Create(listLength / 2, listLength / 2 + 1),
                Tuple.Create(listLength - 1, 2),
                Tuple.Create(listLength - 2, 3),
                Tuple.Create(1, listLength),
                Tuple.Create(0, listLength + 1),
                Tuple.Create(1, listLength + 1),
                Tuple.Create(2, listLength),
                Tuple.Create(listLength / 2 + 1, listLength / 2),
                Tuple.Create(2, listLength - 1),
                Tuple.Create(3, listLength - 2),
            };

            Assert.All(InvalidParameters, invalidSet =>
            {
                if (invalidSet.Item1 >= 0 && invalidSet.Item2 >= 0)
                {
                    Assert.Throws <ArgumentException>(null, () => list.RemoveRange(invalidSet.Item1, invalidSet.Item2));
                }
            });
        }
Example #3
0
            public void TrueForAll_VerifyVanilla(T[] items)
            {
                T?expectedItem         = default(T);
                SegmentedList <T> list = new SegmentedList <T>();
                Predicate <T>     expectedItemDelegate = delegate(T item) { return(expectedItem == null ? item != null : !expectedItem.Equals(item)); };
                bool typeNullable = default(T) == null;

                for (int i = 0; i < items.Length; ++i)
                {
                    list.Add(items[i]);
                }

                //[] Verify TrueForAll looks at every item
                for (int i = 0; i < items.Length; ++i)
                {
                    expectedItem = items[i];
                    Assert.False(list.TrueForAll(expectedItemDelegate)); //"Err_282308ahid Verify TrueForAll looks at every item FAILED\n"
                }

                //[] Verify TrueForAll returns true if the match returns true on every item
                Assert.True(list.TrueForAll(delegate(T item) { return(true); }),
                            "Err_548ahid Verify TrueForAll returns true if the match returns true on every item FAILED\n");

                //[] Verify TrueForAll returns false if the match returns false on every item
                Assert.True((0 == items.Length) == list.TrueForAll(delegate(T item) { return(false); }),
                            "Err_30848ahidi Verify TrueForAll returns " + (0 == items.Length) + " if the match returns false on every item FAILED\n");
            }
Example #4
0
            public void NonGenericIListBasicInsert(T?[] items, T?item, int index, int repeat)
            {
                SegmentedList <T?> list = new SegmentedList <T?>(items);
                IList _ilist            = list;

                for (int i = 0; i < repeat; i++)
                {
                    _ilist.Insert(index, item);
                }

                Assert.True(list.Contains(item));                //"Expected it to be true."
                Assert.Equal(list.Count, items.Length + repeat); //"Expected them to be equal."

                for (int i = 0; i < index; i++)
                {
                    Assert.Equal(list[i], items[i]); //"Expected them to be equal."
                }

                for (int i = index; i < index + repeat; i++)
                {
                    Assert.Equal((object?)list[i], item); //"Expected them to be equal."
                }


                for (int i = index + repeat; i < list.Count; i++)
                {
                    Assert.Equal(list[i], items[i - repeat]); //"Expected them to be equal."
                }
            }
Example #5
0
        public void LastIndexOf_int_OrderIsCorrectWithManyDuplicates(int count)
        {
            SegmentedList <T> list = GenericListFactory(count);
            SegmentedList <T> withoutDuplicates = list.ToSegmentedList();

            list.AddRange(list);
            list.AddRange(list);
            list.AddRange(list);

            Assert.All(
                Enumerable.Range(0, count),
                i =>
            {
                Assert.All(
                    Enumerable.Range(0, 4),
                    j =>
                {
                    int expectedIndex = (j * count) + i;
                    Assert.Equal(
                        expectedIndex,
                        list.LastIndexOf(withoutDuplicates[i], (count * (j + 1)) - 1)
                        );
                    Assert.Equal(
                        expectedIndex,
                        list.LastIndexOf(withoutDuplicates[i], (count * (j + 1)) - 1, count)
                        );
                }
                    );
            }
                );
        }
Example #6
0
            public void BasicInsert(T?[] items, T?item, int index, int repeat)
            {
                SegmentedList <T?> list = new SegmentedList <T?>(items);

                for (int i = 0; i < repeat; i++)
                {
                    list.Insert(index, item);
                }

                Assert.True(list.Contains(item));                //"Expect it to contain the item."
                Assert.Equal(list.Count, items.Length + repeat); //"Expect to be the same."


                for (int i = 0; i < index; i++)
                {
                    Assert.Equal(list[i], items[i]); //"Expect to be the same."
                }

                for (int i = index; i < index + repeat; i++)
                {
                    Assert.Equal(list[i], item); //"Expect to be the same."
                }


                for (int i = index + repeat; i < list.Count; i++)
                {
                    Assert.Equal(list[i], items[i - repeat]); //"Expect to be the same."
                }
            }
        public void FindLast_VerifyDuplicates(int count)
        {
            T?expectedItem               = default(T);
            SegmentedList <T> list       = GenericListFactory(count);
            SegmentedList <T> beforeList = list.ToSegmentedList();
            T?foundItem;
            Predicate <T?> EqualsDelegate = (T? item) => { return(expectedItem == null ? item == null : expectedItem.Equals(item)); };

            if (0 < count)
            {
                list.Add(beforeList[0]);

                //[] Verify first item is duplicated
                expectedItem = beforeList[0];
                foundItem    = list.FindLast(EqualsDelegate);
                Assert.Equal(beforeList[0], foundItem); //"Err_2879072qaiadf  Verify first item is duplicated FAILED\n"
            }

            if (1 < count)
            {
                list.Add(beforeList[1]);

                //[] Verify second item is duplicated
                expectedItem = beforeList[1];
                foundItem    = list.FindLast(EqualsDelegate);
                Assert.Equal(beforeList[1], foundItem); //"Err_4588ajdia Verify second item is duplicated FAILED\n"

                //[] Verify with match that matches more then one item
                foundItem = list.FindLast((T item) => { return(item != null && (item.Equals(beforeList[0]) || item.Equals(beforeList[1]))); });
                Assert.Equal(beforeList[1], foundItem); //"Err_4489ajodoi Verify with match that matches more then one item FAILED\n"
            }
        }
Example #8
0
        public void IndexOf_NonExistingValues(
            IndexOfMethod indexOfMethod,
            int count,
            bool frontToBackOrder
            )
        {
            _ = frontToBackOrder;
            SegmentedList <T> list = GenericListFactory(count);
            IEnumerable <T>   nonexistentValues = CreateEnumerable(
                EnumerableType.List,
                list,
                count: count,
                numberOfMatchingElements: 0,
                numberOfDuplicateElements: 0
                );
            IndexOfDelegate IndexOf = IndexOfDelegateFromType(indexOfMethod);

            Assert.All(
                nonexistentValues,
                nonexistentValue =>
            {
                Assert.Equal(-1, IndexOf(list, nonexistentValue));
            }
                );
        }
Example #9
0
 /// <summary>
 /// Create a IStreamReader (reads binary data) from a given subregion of a byte buffer
 /// </summary>
 public SegmentedMemoryStreamReader(SegmentedList <byte> data, int start, int length)
 {
     bytes = new SegmentedList <byte>(65_536, length);
     bytes.AppendFrom(data, start, length);
     position    = start;
     endPosition = length;
 }
        public void Find_VerifyVanilla(int count)
        {
            SegmentedList <T?> list       = GenericListFactory(count) !;
            SegmentedList <T?> beforeList = list.ToSegmentedList();
            T?expectedItem = default(T);
            T?foundItem;
            Predicate <T?> EqualsDelegate = (T? item) => { return(expectedItem == null ? item == null : expectedItem.Equals(item)); };

            //[] Verify Find returns the correct index
            for (int i = 0; i < count; ++i)
            {
                expectedItem = beforeList[i];
                foundItem    = list.Find(EqualsDelegate);

                Assert.Equal(expectedItem, foundItem); //"Err_282308ahid Verifying value returned from Find FAILED\n"
            }

            //[] Verify Find returns the first item if the match returns true on every item
            foundItem = list.Find(_alwaysTrueDelegate);
            Assert.Equal(0 < count ? beforeList[0] : default(T), foundItem); //"Err_548ahid Verify Find returns the first item if the match returns true on every item FAILED\n"

            //[] Verify Find returns T.Default if the match returns false on every item
            foundItem = list.Find(_alwaysFalseDelegate);
            Assert.Equal(default(T), foundItem); //"Err_30848ahidi Verify Find returns T.Default if the match returns false on every item FAILED\n"

            //[] Verify with default(T)
            list.Add(default(T));
            foundItem = list.Find((T? item) => { return(item == null ? default(T) == null : item.Equals(default(T))); });
            Assert.Equal(default(T), foundItem); //"Err_541848ajodi Verify with default(T) FAILED\n"
            list.RemoveAt(list.Count - 1);
        }
        public void Sort_intintIComparer_NegativeRange_ThrowsArgumentOutOfRangeException(int count)
        {
            SegmentedList <T> list = GenericListFactory(count);

            Tuple <int, int>[] InvalidParameters = new Tuple <int, int>[]
            {
                Tuple.Create(-1, -1),
                Tuple.Create(-1, 0),
                Tuple.Create(-1, 1),
                Tuple.Create(-1, 2),
                Tuple.Create(-2, 0),
                Tuple.Create(int.MinValue, 0),
                Tuple.Create(0, -1),
                Tuple.Create(0, -2),
                Tuple.Create(0, int.MinValue),
                Tuple.Create(1, -1),
                Tuple.Create(2, -1),
            };

            Assert.All(
                InvalidParameters,
                invalidSet =>
            {
                Assert.Throws <ArgumentOutOfRangeException>(
                    () => list.Sort(invalidSet.Item1, invalidSet.Item2, GetIComparer())
                    );
            }
                );
        }
Example #12
0
        /// <summary>
        /// Create a IStreamReader (reads binary data) from a given subregion of a byte buffer
        /// </summary>
        public SegmentedMemoryStreamReader(SegmentedList <byte> data, long start, long length, SerializationConfiguration config = null)
        {
            SerializationConfiguration = config ?? new SerializationConfiguration();

            if (SerializationConfiguration.StreamLabelWidth == StreamLabelWidth.FourBytes)
            {
                readLabel = () =>
                {
                    return((StreamLabel)(uint)ReadInt32());
                };
                sizeOfSerializedStreamLabel = 4;
            }
            else
            {
                readLabel = () =>
                {
                    return((StreamLabel)(ulong)ReadInt64());
                };
                sizeOfSerializedStreamLabel = 8;
            }

            bytes = new SegmentedList <byte>(65_536, length);
            bytes.AppendFrom(data, start, length);
            position    = start;
            endPosition = length;
        }
Example #13
0
        protected override SegmentedList <PointDouble> CreateShape(SegmentedList <PointDouble> tracePoints)
        {
            RectDouble  num5;
            PointDouble a    = tracePoints[0];
            PointDouble b    = tracePoints[tracePoints.Count - 1];
            PointDouble num3 = new PointDouble(b.X - a.X, b.Y - a.Y);
            double      num4 = Math.Sqrt((num3.X * num3.X) + (num3.Y * num3.Y));

            if ((base.ModifierKeys & Keys.Shift) != Keys.None)
            {
                PointDouble center = new PointDouble((a.X + b.X) / 2.0, (a.Y + b.Y) / 2.0);
                double      num7   = num4 / 2.0;
                num5 = RectDouble.FromCenter(center, (double)(num7 * 2.0));
            }
            else
            {
                num5 = RectDoubleUtil.FromPixelPoints(a, b);
            }
            PdnGraphicsPath path = new PdnGraphicsPath();

            path.AddEllipse(num5.ToGdipRectangleF());
            using (Matrix matrix = new Matrix())
            {
                path.Flatten(matrix, 0.1f);
            }
            SegmentedList <PointDouble> list = new SegmentedList <PointDouble>(path.PathPoints.Select <PointF, PointDouble>(pt => pt.ToDoublePoint()), 7);

            path.Dispose();
            return(list);
        }
Example #14
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            SelectionData state = null;
            SegmentedList <HistoryMemento> actions = new SegmentedList <HistoryMemento>();

            if (!historyWorkspace.Selection.IsEmpty)
            {
                state = historyWorkspace.Selection.Save();
                HistoryMemento memento3 = new DeselectFunction().Execute(historyWorkspace);
                actions.Add(memento3);
            }
            ReplaceDocumentHistoryMemento item = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);

            actions.Add(item);
            CompoundHistoryMemento memento2 = new CompoundHistoryMemento(StaticName, PdnResources.GetImageResource("Icons.MenuImageFlattenIcon.png"), actions);
            Document document = RetryManager.RunMemorySensitiveOperation <Document>(() => historyWorkspace.Document.Flatten());

            base.EnterCriticalRegion();
            historyWorkspace.Document = document;
            if (state != null)
            {
                SelectionHistoryMemento newHA = new SelectionHistoryMemento(null, null, historyWorkspace);
                historyWorkspace.Selection.Restore(state);
                memento2.AddMemento(newHA);
            }
            return(memento2);
        }
        public void FindLastIndexInt_VerifyExceptions(int count)
        {
            SegmentedList <T> list       = GenericListFactory(count);
            SegmentedList <T> beforeList = list.ToSegmentedList();
            Predicate <T>     predicate  = _alwaysTrueDelegate;


            //[] Verify Null match
            Assert.Throws <ArgumentNullException>(() => list.FindLastIndex(0, null !)); //"Err_858ahia Expected null match to throw ArgumentNullException"

            /******************************************************************************
            *  index
            ******************************************************************************/
            //[] Verify index=Int32.MinValue
            Assert.Throws <ArgumentOutOfRangeException>(() => list.FindLastIndex(int.MinValue, predicate)); //"Err_948ahid Expected index=Int32.MinValue to throw ArgumentOutOfRangeException"

            if (0 < list.Count)
            {
                //[] Verify index=-1
                Assert.Throws <ArgumentOutOfRangeException>(() => list.FindLastIndex(-1, predicate)); //"Err_328ahuaw Expected index=-1 to throw ArgumentOutOfRangeException"
            }

            //[] Verify index=list.Count + 1
            Assert.Throws <ArgumentOutOfRangeException>(() => list.FindLastIndex(list.Count + 1, predicate)); //"Err_488ajdi Expected index=list.Count + 1 to throw ArgumentOutOfRangeException"

            //[] Verify index=list.Count
            Assert.Throws <ArgumentOutOfRangeException>(() => list.FindLastIndex(list.Count, predicate)); //"Err_9689ajis Expected index=list.Count to throw ArgumentOutOfRangeException"

            //[] Verify index=Int32.MaxValue
            Assert.Throws <ArgumentOutOfRangeException>(() => list.FindLastIndex(int.MaxValue, predicate)); //"Err_238ajwisa Expected index=Int32.MaxValue to throw ArgumentOutOfRangeException"
        }
Example #16
0
        private IHandler[] GetHandlersNoLock(Type service)
        {
            //we have 3 segments
            const int defaults  = 0;
            const int regulars  = 1;
            const int fallbacks = 2;
            var       handlers  = new SegmentedList <IHandler>(3);

            foreach (var handler in name2Handler.Values)
            {
                if (handler.Supports(service) == false)
                {
                    continue;
                }
                if (IsDefault(handler, service))
                {
                    handlers.AddFirst(defaults, handler);
                    continue;
                }
                if (IsFallback(handler, service))
                {
                    handlers.AddLast(fallbacks, handler);
                    continue;
                }
                handlers.AddLast(regulars, handler);
            }
            return(handlers.ToArray());
        }
        public void FindLastIndex_VerifyVanilla(int count)
        {
            T?expectedItem               = default(T);
            SegmentedList <T> list       = GenericListFactory(count);
            SegmentedList <T> beforeList = list.ToSegmentedList();
            int index;
            Predicate <T> EqualsDelegate = delegate(T item) { return(expectedItem == null ? item == null : expectedItem.Equals(item)); };


            //[] Verify FinIndex returns the correct index
            for (int i = 0; i < count; ++i)
            {
                expectedItem = beforeList[i];
                index        = list.FindLastIndex(EqualsDelegate);
                Assert.Equal(i, index); //"Err_282308ahid Expected FindLastIndex to return the same."
            }

            //[] Verify FindLastIndex returns 0 if the match returns true on every item
            int expected = count == 0 ? -1 : count - 1;

            index = list.FindLastIndex(_alwaysTrueDelegate);
            Assert.Equal(expected, index); //"Err_15198ajid Verify FindLastIndex returns 0 if the match returns true on every item"

            //[] Verify FindLastIndex returns -1 if the match returns false on every item
            index = list.FindLastIndex(_alwaysFalseDelegate);
            Assert.Equal(-1, index); //"Err_305981ajodd Verify FindLastIndex returns -1 if the match returns false on every item"
        }
Example #18
0
        public void IndexOf_OrderIsCorrect(
            IndexOfMethod indexOfMethod,
            int count,
            bool frontToBackOrder
            )
        {
            SegmentedList <T> list = GenericListFactory(count);
            SegmentedList <T> withoutDuplicates = list.ToSegmentedList();

            list.AddRange(list);
            IndexOfDelegate IndexOf = IndexOfDelegateFromType(indexOfMethod);

            Assert.All(
                Enumerable.Range(0, count),
                i =>
            {
                if (frontToBackOrder)
                {
                    Assert.Equal(i, IndexOf(list, withoutDuplicates[i]));
                }
                else
                {
                    Assert.Equal(count + i, IndexOf(list, withoutDuplicates[i]));
                }
            }
                );
        }
        public void FindLastIndexIntInt_VerifyDuplicates(int count)
        {
            T?expectedItem               = default(T);
            SegmentedList <T> list       = GenericListFactory(count);
            SegmentedList <T> beforeList = list.ToSegmentedList();
            int           index;
            Predicate <T> EqualsDelegate = (T item) => { return(expectedItem == null ? item == null : expectedItem.Equals(item)); };

            if (0 < count)
            {
                list.Add(beforeList[0]);

                //[] Verify first item is duplicated
                expectedItem = beforeList[0];
                index        = list.FindLastIndex(list.Count - 1, list.Count, EqualsDelegate);
                Assert.Equal(list.Count - 1, index); //"Err_3282iahid Verify first item is duplicated"
            }

            if (1 < count)
            {
                list.Add(beforeList[1]);

                //[] Verify second item is duplicated
                expectedItem = beforeList[1];
                index        = list.FindLastIndex(list.Count - 1, list.Count, EqualsDelegate);
                Assert.Equal(list.Count - 1, index); //"Err_29892adewiu Verify second item is duplicated"
            }
        }
Example #20
0
            private void Exists_VerifyVanilla(T[] items)
            {
                T?expectedItem          = default(T);
                SegmentedList <T?> list = new SegmentedList <T?>();
                Predicate <T?>     expectedItemDelegate = (T? item) => { return(expectedItem == null ? item == null : expectedItem.Equals(item)); };
                bool typeNullable = default(T) == null;

                for (int i = 0; i < items.Length; ++i)
                {
                    list.Add(items[i]);
                }

                //[] Verify Exists returns the correct index
                for (int i = 0; i < items.Length; ++i)
                {
                    expectedItem = items[i];

                    Assert.True(list.Exists(expectedItemDelegate),
                                "Err_282308ahid Verifying Nullable returned FAILED\n");
                }

                //[] Verify Exists returns true if the match returns true on every item
                Assert.True((0 < items.Length) == list.Exists((T? item) => { return(true); }),
                            "Err_548ahid Verify Exists returns 0 if the match returns true on every item FAILED\n");

                //[] Verify Exists returns false if the match returns false on every item
                Assert.True(!list.Exists((T? item) => { return(false); }),
                            "Err_30848ahidi Verify Exists returns -1 if the match returns false on every item FAILED\n");

                //[] Verify with default(T)
                list.Add(default(T));
                Assert.True(list.Exists((T? item) => { return(item == null ? default(T) == null : item.Equals(default(T))); }),
                            "Err_541848ajodi Verify with default(T) FAILED\n");
                list.RemoveAt(list.Count - 1);
            }
        public void FindAll_VerifyDuplicates(int count)
        {
            SegmentedList <T> list = GenericListFactory(count);

            for (int i = 0; i < count / 2; i++)
            {
                list.Add(list[i]);
            }
            SegmentedList <T> beforeList = list.ToSegmentedList();
            T?            expectedItem   = default(T);
            Predicate <T> EqualsDelegate = (value) => expectedItem == null ? value == null : expectedItem.Equals(value);

            //[] Verify FindAll returns the correct List with one item
            for (int i = 0; i < count; ++i)
            {
                expectedItem = beforeList[i];
                SegmentedList <T> results = list.FindAll(EqualsDelegate);
                VerifyList(results, beforeList.Where((value) => EqualsDelegate(value)).ToSegmentedList());
            }

            //[] Verify FindAll returns an List with all of the items if the predicate always returns true
            VerifyList(list.FindAll(_alwaysTrueDelegate), beforeList);

            //[] Verify FindAll returns an empty List if the match returns false on every item
            VerifyList(list.FindAll(_alwaysFalseDelegate), new SegmentedList <T>());
        }
Example #22
0
            public void ClearNonEmptyList(T[] items)
            {
                SegmentedList <T> list = new SegmentedList <T>(items);

                list.Clear();
                Assert.Equal(0, list.Count); //"Should be equal to 0."
            }
Example #23
0
        private Rectangle[] ConsolidateRects(Rectangle[] scans)
        {
            if (scans.Length == 0)
            {
                return(Array.Empty <Rectangle>());
            }

            SegmentedList <Rectangle> cons = new SegmentedList <Rectangle>();
            int current = 0;

            cons.Add(scans[0]);

            for (int i = 1; i < scans.Length; ++i)
            {
                if (scans[i].Left == cons[current].Left &&
                    scans[i].Right == cons[current].Right &&
                    scans[i].Top == cons[current].Bottom)
                {
                    Rectangle cc = cons[current];
                    cc.Height     = scans[i].Bottom - cons[current].Top;
                    cons[current] = cc;
                }
                else
                {
                    cons.Add(scans[i]);
                    current = cons.Count - 1;
                }
            }

            return(cons.ToArrayEx());
        }
Example #24
0
            public void TrueForAll_VerifyExceptions(T[] items)
            {
                var list = new SegmentedList <T>(items);

                Assert.True(list.TrueForAll(item => true));
                Assert.Throws <ArgumentNullException>(() => list.TrueForAll(null !)); //"Err_858ahia Expected null match to throw ArgumentNullException"
            }
        public void CopyTo_ArgumentValidity(int count)
        {
            SegmentedList <T> list = GenericListFactory(count);

            Assert.Throws <ArgumentException>(null, () => list.CopyTo(0, new T[0], 0, count + 1));
            Assert.Throws <ArgumentException>(null, () => list.CopyTo(count, new T[0], 0, 1));
        }
Example #26
0
        public TokenStream(TreeData treeData, SyntaxFormattingOptions options, TextSpan spanToFormat, AbstractTriviaDataFactory factory)
        {
            using (Logger.LogBlock(FunctionId.Formatting_TokenStreamConstruction, CancellationToken.None))
            {
                // initialize basic info
                _factory  = factory;
                _treeData = treeData;
                _options  = options;

                // use some heuristics to get initial size of list rather than blindly start from default size == 4
                var sizeOfList = spanToFormat.Length / MagicTextLengthToTokensRatio;
                _tokens = new SegmentedList <SyntaxToken>(sizeOfList);
                _tokens.AddRange(_treeData.GetApplicableTokens(spanToFormat));

                Debug.Assert(this.TokenCount > 0);

                // initialize trivia related info
                _cachedOriginalTriviaInfo = new SegmentedArray <TriviaData>(this.TokenCount - 1);

                // Func Cache
                _getTriviaData         = this.GetTriviaData;
                _getOriginalTriviaData = this.GetOriginalTriviaData;
            }

            DebugCheckTokenOrder();
        }
        public void Constructor_IEnumerable(
            EnumerableType enumerableType,
            int listLength,
            int enumerableLength,
            int numberOfMatchingElements,
            int numberOfDuplicateElements
            )
        {
            _ = listLength;
            _ = numberOfMatchingElements;
            IEnumerable <T> enumerable = CreateEnumerable(
                enumerableType,
                null,
                enumerableLength,
                0,
                numberOfDuplicateElements
                );
            SegmentedList <T> list     = new SegmentedList <T>(enumerable);
            SegmentedList <T> expected = enumerable.ToSegmentedList();

            Assert.Equal(enumerableLength, list.Count); //"Number of items in list do not match the number of items given."

            for (int i = 0; i < enumerableLength; i++)
            {
                Assert.Equal(expected[i], list[i]);     //"Expected object in item array to be the same as in the list"
            }
            Assert.False(((IList <T>)list).IsReadOnly); //"List should not be readonly"
        }
Example #28
0
        public void Reverse_RepeatedValues(int listLength, int index, int count)
        {
            SegmentedList <T> list = GenericListFactory(1);

            for (int i = 1; i < listLength; i++)
            {
                list.Add(list[0]);
            }
            SegmentedList <T> listBefore = list.ToSegmentedList();

            list.Reverse(index, count);

            for (int i = 0; i < index; i++)
            {
                Assert.Equal(list[i], listBefore[i]); //"Expect them to be the same."
            }

            int j = 0;

            for (int i = index; i < index + count; i++)
            {
                Assert.Equal(list[i], listBefore[index + count - (j + 1)]); //"Expect them to be the same."
                j++;
            }

            for (int i = index + count; i < listBefore.Count; i++)
            {
                Assert.Equal(list[i], listBefore[i]); //"Expect them to be the same."
            }
        }
Example #29
0
 internal Enumerator(SegmentedList <T> list)
 {
     _list    = list;
     _index   = 0;
     _version = list._version;
     _current = default;
 }
Example #30
0
        private Rectangle[] ConsolidateRects(Rectangle[] scans)
        {
            if (scans.Length == 0)
            {
                return(Array.Empty <Rectangle>());
            }
            SegmentedList <Rectangle> items = new SegmentedList <Rectangle>();
            int num = 0;

            items.Add(scans[0]);
            for (int i = 1; i < scans.Length; i++)
            {
                Rectangle rectangle = items[num];
                if (scans[i].Left == rectangle.Left)
                {
                    rectangle = items[num];
                    if (scans[i].Right == rectangle.Right)
                    {
                        rectangle = items[num];
                        if (scans[i].Top == rectangle.Bottom)
                        {
                            Rectangle rectangle2 = items[num];
                            rectangle         = items[num];
                            rectangle2.Height = scans[i].Bottom - rectangle.Top;
                            items[num]        = rectangle2;
                            continue;
                        }
                    }
                }
                items.Add(scans[i]);
                num = items.Count - 1;
            }
            return(items.ToArrayEx <Rectangle>());
        }
		private IHandler[] GetHandlersNoLock(Type service)
		{
			//we have 3 segments
			const int defaults = 0;
			const int regulars = 1;
			const int fallbacks = 2;
			var handlers = new SegmentedList<IHandler>(3);
			foreach (var handler in name2Handler.Values)
			{
				if (handler.Supports(service) == false)
				{
					continue;
				}
				if (IsDefault(handler, service))
				{
					handlers.AddFirst(defaults, handler);
					continue;
				}
				if (IsFallback(handler, service))
				{
					handlers.AddLast(fallbacks, handler);
					continue;
				}
				handlers.AddLast(regulars, handler);
			}
			return handlers.ToArray();
		}