Ejemplo n.º 1
0
        public void Load(string key, string name)
        {
            Keys.Add(key);
            var ch   = name[0];
            var node = Nodes.FirstOrDefault(q => q.Char == ch);

            if (node == null)
            {
                node      = new NameTree();
                node.Char = ch;
                //node.IsNum = "0123456789".Contains(ch);
                node.Name = this.Name + ch;
                this.Nodes.Add(node);
            }
            if (name.Length == 1)
            {
                node.CurKeys.Add(key);
            }
            else
            {
                var next = name.Substring(1);
                node.NextKeys.Add(key);
                node.Load(key, next);
            }
        }
Ejemplo n.º 2
0
        private List <string> getMinName(Dictionary <string, string> dict, List <string> names)
        {
            NameTree root = new NameTree();

            foreach (var item in dict)
            {
                root.Load(item.Key, item.Value);
            }
            root.OrderBy();

            List <string> list = new List <string>();

            foreach (var item in names)
            {
                var name = root.GetName(item);
                if (list.Contains(name) == false)
                {
                    list.Add(name);
                    continue;
                }
                name = getSimpleName(item);
                if (list.Contains(name) == false)
                {
                    list.Add(name);
                    continue;
                }
                for (int i = 2; i < 10; i++)
                {
                    var n = name + i;
                    if (list.Contains(n) == false)
                    {
                        list.Add(n);
                        break;
                    }
                }
            }
            return(list);
        }