protected void Split(int k, out ISegmentContainer sc1, out ISegmentContainer sc2, bool keep) { //Contract.Requires(k < Count); //Contract.Ensures(sc1 != null); //Contract.Ensures(sc2 != null); int sc1Count = k + (keep ? 1 : 0); int sc2Count = Count - k - 1; sc1 = new SegmentContainer(sc1Count); sc2 = new SegmentContainer(sc2Count); for (int i = 0; i < sc1Count; i++) { sc1.Append(this[i]); } for (int i = k + 1; i < Count; i++) { sc2.Append(this[i]); } }
/// <summary> /// Splits this container at position <paramref name="k"/>. The first <paramref name="k"/> /// elements of the container are stored in <paramref name="container1"/> and the remainder /// in <paramref name="container2"/>. /// </summary> /// <param name="k">The index where the container should be split.</param> /// <param name="container1">The container which contains the elements before <paramref name="k"/>.</param> /// <param name="container2">The container which contains the elements after <paramref name="k"/>.</param> /// <param name="keep">Indicates if <paramref name="k"/>th item should be kept in <paramref name="container1"/> or not.</param> protected void Split( int k, [NotNull] out ISegmentContainer container1, [NotNull] out ISegmentContainer container2, bool keep) { Debug.Assert(k < Count); int container1Count = k + (keep ? 1 : 0); int container2Count = Count - k - 1; container1 = new SegmentContainer(container1Count); container2 = new SegmentContainer(container2Count); for (int i = 0; i < container1Count; ++i) { container1.Append(this[i]); } for (int i = k + 1; i < Count; ++i) { container2.Append(this[i]); } }