示例#1
0
        // --- Other view patterns --------------------------------------

        // Replace the first occurrence of each x from xs by y in list:

        public static void ReplaceXsByY <T>(HashedLinkedList <T> list, T[] xs, T y)
        {
            foreach (T x in xs)
            {
                using (IList <T> view = list.ViewOf(x)) {
                    if (view != null)
                    {
                        view.Remove();
                        view.Add(y);
                    }
                }
            }
        }
示例#2
0
文件: ViewExample.cs 项目: flyer87/C6
        public void Main()
        {
            var list = new HashedLinkedList <int> {
                2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59
            };

            // View of item
            list.ViewOf(2);

            // Last view of item
            list.LastViewOf(11);

            // View in range
            var view = list.View(0, 3);

            // Slide with offset
            view.Slide(3);

            // Slide with offset and set lenght
            view.Slide(-3, 3);

            // Try slide with offset and set lenght
            var hasSucceed = view.TrySlide(-10, 3);

            // Try slide with offset and set lenght
            view.TrySlide(3, -3);

            var view2 = list.View(0, 3);
            var view3 = list.View(1, 3);

            // Check if views overlap
            Overlap(view2, view3);

            // Check if views contained in each other
            ContainsView(view2, view3);

            // Span views
            var spannedView = view2.Span(view3);

            // Invalidate all views by shuffle
            list.Shuffle();

            // Check if view is valid
            Console.WriteLine($"View is valid? {view.IsValid}");
        }