private static IEnumerable <T> DescendantsCore <T, K>(IEnumerable <T> source, Func <T, K> keySelector, Func <T, K> parentKeySelector, Equality <K> equality, K startKey, bool descendantsOnly = false, int?levelsCount = null) where T : class where K : class { PwrList <T> list = new PwrList <T>(); PwrFrameListView <T> view = new PwrFrameListView <T>(list); int priorCount = list.Count; if (descendantsOnly) { list.AddRange(source.Where(t => equality(parentKeySelector(t), startKey))); } else if (startKey != null) { list.AddRange(source.Where(t => equality(keySelector(t), startKey))); } int takeCount = list.Count - priorCount; for (int passCount = 1; (!levelsCount.HasValue || levelsCount.Value > passCount) && takeCount > 0; passCount++) { view.FrameOffset = priorCount; view.FrameSize = takeCount; priorCount = list.Count; list.AddRange(source.Where(t1 => parentKeySelector(t1) != null && view.Any(t2 => equality(keySelector(t2), parentKeySelector(t1))))); takeCount = list.Count - priorCount; } return(list.AsEnumerable()); }
public override int Read(byte[] buffer, int offset, int count) { try { long position = _stream.Position; if (position != _position - (_buffer.Count - _offset)) { _buffer.Clear(); _offset = _buffer.Count; _position = position; } } catch (NotSupportedException) { } int cached = Comparable.Min(count, _buffer.Count - _offset); if (cached > 0) { //buffer.MoveRange(); buffer.Fill(i => _buffer[_offset + i], new Range(offset, cached)); } int read = count - cached; if (read > 0) { read = _stream.Read(buffer, offset, read); if (read > _buffer.Capacity - _buffer.Count) { _buffer.RemoveRange(0, Comparable.Min(read - (_buffer.Capacity - _buffer.Count), _buffer.Count)); } _buffer.AddRange(buffer.Skip(offset + cached + Comparable.Max(0, read - (_buffer.Capacity - _buffer.Count))).Take(Comparable.Min(read, _buffer.Capacity - _buffer.Count))); } return(cached + read); }
public PwrList <T> DequeueRange(int count) { if (count < 0 || count > InnerList.Count) { throw new ArgumentOutOfRangeException("count"); } var list = new PwrList <T>(count); list.AddRange(InnerList.Enumerate(0, count)); list.RemoveRange(0, count); return(list); }
public PwrList <T> PopRange(int count) { if (count < 0 || count > InnerList.Count) { throw new ArgumentOutOfRangeException("count"); } var list = new PwrList <T>(count); var index = InnerList.Count - count; list.AddRange(InnerList.Enumerate(index, count, true)); InnerList.RemoveRange(index, count); return(list); }