/// <summary> /// 加入队列 /// </summary> /// <param name="skewPipe"></param> public PipeGroupCollection Push(SkewPipe skewPipe) { var skewPipeId = skewPipe.pipe.Id.IntegerValue; if (LatestSkewPipe == null) { LatestSkewPipe = skewPipe; Branches.Add(new OverlapBranch(skewPipe)); return(null); } //如果和最近一次添加项的间距超出限制,则所有的都超出限制,直接做全部结算 if (!IsValidInterval(LatestSkewPipe, skewPipe)) { var result = Clear(); Push(skewPipe); return(result); } PipeGroupCollection collection = new PipeGroupCollection(); LatestSkewPipe = skewPipe; //对于每一个分支,最近添加项都有可能是不同的,需重新计算间距 bool isExist = false; if (Branches.Count > 100000) { throw new NotImplementedException("超出了十万的分支限制"); } for (int i = Branches.Count() - 1; i >= 0; i--) { var branch = Branches[i]; if (branch.SkewPipes.Count == AnnotationConstaints.PipeCountMax - 1)//如果分组个数超出了规定 则不予生成 { throw new NotImplementedException("管道超出了并排6个的上限"); branch.Push(skewPipe); collection.Add(branch.ToPipeGroup()); Branches.Remove(branch); } else if (!IsValidInterval(branch.LatestSkewPipe, skewPipe))//如果间距超出了限制,则做一波结算 { collection.Add(branch.ToPipeGroup()); Branches.Remove(branch); } else { branch.Push(skewPipe); if (branch.IsOverlapped) { Branches.Add(branch.Clone()); } else { //TODO 如果已有该项的单项 if (!isExist) { foreach (var b in Branches) { if (b.SkewPipes.Count() == 1 && b.SkewPipes[0] == skewPipe) { isExist = true; break; } } if (!isExist) { Branches.Add(new OverlapBranch(skewPipe)); } } } branch.PopLast(); } } //本来想要在这里做消重处理 比如 A-B A-B-D但是后续可能出现A-B-E //目前没有很好的办法检测后续是否会出现E return(collection); }
public static void Main(string[] args) { Console.WriteLine(Branches.Count(1, 3, 1, -1, 3)); }