/* * 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)); }