예제 #1
0
        /*
         *  this whole thing is meant for fully qualified type names
         *  since c# has inner types, both A and A.B could be a valid target for a completion with payload
         *  -> an optional payload on inner nodes must be supported
         *  -> leafs must be non-empty
         */
        public bool Add(SCG.IEnumerable <string> edges, Pay payload)
        {
            // TODO: exception on null payload, want null to be used internally and get away with not doing the maybe<T> dance
            if (!edges.Any())
            {
                throw new InterfaceE();
            }
            if (edges.Any(e => string.IsNullOrEmpty(e) /*|| string.IsNullOrWhiteSpace(e)*/))
            {
                throw new InterfaceE();                                                                                  // <- empty strings as keys destroy pretty much all assumptions
            }
            //                               TODO !!!                    ^._____ not available in Unity
            string first = edges.First();
            var    Rest  = edges.Skip(1);

            if (!Rest.Any())
            {
                return(AddLeaf(first, payload));
            }

            if (!D.Contains(first))
            {
                D[first] = new SuggestionTree <Pay>();
            }
            // D[first] is guaranteed to exist at this point, but it might be a leaf -> convert to inner node
            // TODO this is prob. still not enough, depending on how this is supposed to behave upon input in which a path is duplicate
            //      for example when simulating "using directives", overrriding paths and even replacing whole subtrees must be supported
            // ( das braucht wahrscheinlich einen Join( SuggTree1 , SuggTree2 ) siehe lustig bunte A4 blaetter )
            if (D[first] is SuggestionLeaf <Pay> )
            {
                var nu_tree = new SuggestionTree <Pay>(); nu_tree.payload = D[first].payload; D[first] = nu_tree;
            }
            return(D[first].Add(Rest, payload));
        }
예제 #2
0
        public static SCG.IEnumerable <T> SkipRange <T>(this SCG.IEnumerable <T> enumerable, int startIndex, int count)
        {
            #region Code Contracts

            // Argument is non-null
            Requires(enumerable != null, ArgumentMustBeNonNull);

            #endregion

            // ReSharper disable PossibleMultipleEnumeration
            return(enumerable.Take(startIndex).Concat(enumerable.Skip(startIndex + count)));
            // ReSharper enable PossibleMultipleEnumeration
        }
예제 #3
0
파일: TestHelper.cs 프로젝트: flyer87/C6
 public static T[] InsertItems <T>(this SCG.IEnumerable <T> enumerable, int index, SCG.IEnumerable <T> items) => enumerable.Take(index).Concat(items).Concat(enumerable.Skip(index)).ToArray();
예제 #4
0
파일: TestHelper.cs 프로젝트: flyer87/C6
 public static T[] InsertItem <T>(this SCG.IEnumerable <T> enumerable, int index, T item) => enumerable.Take(index).Append(item).Concat(enumerable.Skip(index)).ToArray();