コード例 #1
0
        public static SickTree <TItem, TDecision> ToSickTree <TSource, TItem, TDecision>(this IEnumerable <TSource> en, Func <TSource, TItem> itemSelector, Func <TSource, TDecision[]> pathSelector)
        {
            var result = new SickTree <TItem, TDecision>();

            using (var enu = en.GetEnumerator())
            {
                while (enu.MoveNext())
                {
                    result.AddPath(itemSelector(enu.Current), pathSelector(enu.Current));
                }
            }

            return(result);
        }
コード例 #2
0
        private static void B()
        {
            SickTree <int, int> tree = new SickTree <int, int>();

            tree.AddPath(1, new int[] { 1, 4 });
            tree.AddPath(2, new int[] { 1, 4, 2 });
            tree.AddPath(3, new int[] { 1, 4, 8 });
            tree.AddPath(4, new int[] { 1 }, true);
            tree.AddPath(5, new int[0]);

            Tuple <string, int[]>[] convTest = new Tuple <string, int[]>[]
            {
                Tuple.Create("eins", new int[] { 1, 4, 5 }),
                Tuple.Create("zwei", new int[] { 1, 4, 10 }),
                Tuple.Create("drei", new int[] { 1, 2 })
            };

            tree.ToList().ForEach(Console.WriteLine);
            var tree2 = convTest.ToSickTree(
                t => t.Item1,
                t => t.Item2
                );
        }