예제 #1
0
파일: Forest.cs 프로젝트: echofool/Ansj.Net
        public IWoodInterface Add(IWoodInterface branch)
        {
            var temp = chars[branch.GetChar()];
            if (temp == null)
                chars[branch.GetChar()] = branch;
            else
            {
                switch (branch.Status)
                {
                    case 1:
                        if (temp.Status == 3)
                        {
                            temp.Status = 2;
                        }
                        break;
                    case 3:
                        if (temp.Status == 1)
                        {
                            temp.Status = 2;
                        }
                        temp.Param = branch.Param;
                        break;
                }
            }

            return chars[branch.GetChar()];
        }
예제 #2
0
파일: Branch.cs 프로젝트: echofool/Ansj.Net
 public IWoodInterface Add(IWoodInterface branch)
 {
     if (_branches == null)
     {
         _branches = new IWoodInterface[0];
     }
     var bs = AnsjArrays.BinarySearch(_branches, branch.GetChar());
     if (bs >= 0)
     {
         this._branch = _branches[bs];
         switch (branch.Status)
         {
             case 0:
                 _branch.Status = 1;
                 break;
             case 1:
                 if (_branch.Status == 3)
                 {
                     _branch.Status = 2;
                 }
                 break;
             case 3:
                 if (_branch.Status != 3)
                 {
                     _branch.Status = 2;
                 }
                 _branch.Param = branch.Param;
                 break;
         }
         return _branch;
     }
     var newBranches = new IWoodInterface[_branches.Length + 1];
     var insert = -(bs + 1);
     Array.Copy(_branches, 0, newBranches, 0, insert);
     Array.Copy(_branches, insert, newBranches, insert + 1, _branches.Length - insert);
     newBranches[insert] = branch;
     _branches = newBranches;
     return branch;
 }