private List <TVal> DoPick(int startIndex, int pickCount) { List <TVal> list = new List <TVal>(); int num = 0; bool flag = false; int num2 = 0; ISegment <TSegmentID, TVal> smallestSegment = null; if (this.pickFromSmallToBig) { smallestSegment = this.GetSmallestSegment(); } else { smallestSegment = this.GetBiggestSegment(); } while (smallestSegment != null) { bool flag2 = false; IList <TVal> content = smallestSegment.GetContent(); int count = content.Count; if ((content != null) && (count > 0)) { if (!flag) { if ((num + count) >= startIndex) { flag = true; flag2 = true; } else { num += count; } } if (flag) { int num4; int num5; if (this.pickFromSmallToBig) { num4 = flag2 ? (startIndex - num) : 0; num5 = num4; while (num5 < count) { list.Add(content[num5]); num2++; if (num2 >= pickCount) { return(list); } num5++; } } else { num4 = flag2 ? ((count - 1) - (startIndex - num)) : (count - 1); for (num5 = num4; num5 >= 0; num5--) { list.Add(content[num5]); num2++; if (num2 >= pickCount) { return(list); } } } } } smallestSegment = this.GetNextSegment(smallestSegment.ID, this.pickFromSmallToBig); } return(list); }
private IList <TVal> DoPick(int startIndex, int pickCount) { IList <TVal> resultList = new List <TVal>(); int accumulateIndex = 0; bool startPointFound = false; int havePickedCount = 0; ISegment <TSegmentID, TVal> curSegment = null; if (this.pickFromSmallToBig) { curSegment = this.segmentContainer.GetSmallestSegment(); } else { curSegment = this.segmentContainer.GetBiggestSegment(); } while (curSegment != null) { bool startPointInCurSegment = false; IList <TVal> curContent = curSegment.GetContent(); #region Process if ((curContent != null) && (curContent.Count > 0)) { if (!startPointFound) { if (accumulateIndex + curContent.Count >= startIndex) { startPointFound = true; startPointInCurSegment = true; } else { accumulateIndex += curContent.Count; } } if (startPointFound) { if (this.pickFromSmallToBig) { int offset = startPointInCurSegment ? startIndex - accumulateIndex : 0; for (int i = offset; i < curContent.Count; i++) { resultList.Add(curContent[i]); ++havePickedCount; if (havePickedCount >= pickCount) { return(resultList); } } } else { int offset = startPointInCurSegment ? (curContent.Count - 1) - (startIndex - accumulateIndex) : curContent.Count - 1; for (int i = offset; i >= 0; i--) { resultList.Add(curContent[i]); ++havePickedCount; if (havePickedCount >= pickCount) { return(resultList); } } } } } #endregion curSegment = this.segmentContainer.GetNextSegment(curSegment.ID, this.pickFromSmallToBig); } return(resultList); }