コード例 #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;
 }